From 96a868b60a3f36d761d58b5082aa9d37666e63a3 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Fri, 28 Aug 2020 16:48:56 +0900 Subject: [PATCH] feat: automatically update --- Packages/UIParticle/Scripts/UIParticle.cs | 46 ++++++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/Packages/UIParticle/Scripts/UIParticle.cs b/Packages/UIParticle/Scripts/UIParticle.cs index c06c61a..7fc2fe3 100755 --- a/Packages/UIParticle/Scripts/UIParticle.cs +++ b/Packages/UIParticle/Scripts/UIParticle.cs @@ -15,7 +15,7 @@ namespace Coffee.UIExtensions [ExecuteInEditMode] [RequireComponent(typeof(RectTransform))] [RequireComponent(typeof(CanvasRenderer))] - public class UIParticle : MaskableGraphic + public class UIParticle : MaskableGraphic, ISerializationCallbackReceiver { [HideInInspector] [SerializeField] bool m_IsTrail = false; @@ -114,6 +114,13 @@ public void RefreshParticles() { GetComponentsInChildren(particles); + foreach (var ps in particles) + { + var tsa = ps.textureSheetAnimation; + if (tsa.mode == ParticleSystemAnimationMode.Sprites && tsa.uvChannelMask == (UVChannelFlags) 0) + tsa.uvChannelMask = UVChannelFlags.UV0; + } + particles.Exec(p => p.GetComponent().enabled = !enabled); particles.SortForRendering(transform); @@ -258,12 +265,11 @@ protected override void OnDidApplyAnimationProperties() private void InitializeIfNeeded() { - if (0 < particles.Count) return; + if (!this || 0 < particles.Count) return; - if (m_IsTrail - || transform.parent && transform.parent.GetComponentInParent()) + if (m_IsTrail) { - gameObject.SetActive(false); + UnityEngine.Debug.LogWarningFormat("[UIParticle] Remove this UIParticle: {0}\nReason: UIParticle for trails is no longer needed.", name); if (Application.isPlaying) Destroy(gameObject); else @@ -271,13 +277,41 @@ private void InitializeIfNeeded() return; } + if (transform.parent && transform.parent.GetComponentInParent()) + { + UnityEngine.Debug.LogWarningFormat("[UIParticle] Remove this UIParticle: {0}\nReason: The parent UIParticle exists.", name); + if (Application.isPlaying) + Destroy(this); + else + DestroyImmediate(this); + return; + } + // refresh. #if UNITY_EDITOR if (!Application.isPlaying) - UnityEditor.EditorApplication.delayCall += RefreshParticles; + UnityEditor.EditorApplication.delayCall += () => + { + if (this) RefreshParticles(); + }; else #endif RefreshParticles(); } + +#if UNITY_EDITOR + void ISerializationCallbackReceiver.OnBeforeSerialize() + { + InitializeIfNeeded(); + } + + void ISerializationCallbackReceiver.OnAfterDeserialize() + { + UnityEditor.EditorApplication.delayCall += () => + { + if (this) InitializeIfNeeded(); + }; + } +#endif } }