diff --git a/Scripts/Editor/UIParticleEditor.cs b/Scripts/Editor/UIParticleEditor.cs index 2d423aa..ec73f11 100644 --- a/Scripts/Editor/UIParticleEditor.cs +++ b/Scripts/Editor/UIParticleEditor.cs @@ -68,6 +68,7 @@ namespace Coffee.UIExtensions static private bool _xyzMode; private bool _showMax; + private static readonly HashSet s_Shaders = new HashSet(); private static readonly List s_MaskablePropertyNames = new List { "_Stencil", @@ -192,6 +193,15 @@ namespace Coffee.UIExtensions t.RefreshParticles(t.particles); } }; + + // On select UIParticle, refresh particles. + if (!Application.isPlaying) + { + foreach (UIParticle t in targets) + { + t.RefreshParticles(t.particles); + } + } } private static void MaterialField(Rect rect, GUIContent label, SerializedProperty sp, int index) @@ -260,6 +270,8 @@ namespace Coffee.UIExtensions { if (!mat || !mat.shader) continue; var shader = mat.shader; + if (s_Shaders.Contains(shader)) continue; + s_Shaders.Add(shader); foreach (var propName in s_MaskablePropertyNames) { if (mat.HasProperty(propName)) continue; @@ -269,6 +281,7 @@ namespace Coffee.UIExtensions } } } + s_Shaders.Clear(); // UIParticle for trail should be removed. if (FixButton(current.m_IsTrail, "This UIParticle component should be removed. The UIParticle for trails is no longer needed.")) @@ -286,7 +299,7 @@ namespace Coffee.UIExtensions if (0 < allPsRenderers.Length) { var so = new SerializedObject(allPsRenderers); - var sp = so.FindProperty("m_ApplyActiveColorSpace");//.boolValue = false; + var sp = so.FindProperty("m_ApplyActiveColorSpace"); if (FixButton(sp.boolValue || sp.hasMultipleDifferentValues, "When using linear color space, the particle colors are not output correctly.\nTo fix, set 'Apply Active Color Space' in renderer module to false.")) { sp.boolValue = false; diff --git a/Scripts/UIParticle.cs b/Scripts/UIParticle.cs index daa5aae..d5a7442 100644 --- a/Scripts/UIParticle.cs +++ b/Scripts/UIParticle.cs @@ -272,11 +272,6 @@ namespace Coffee.UIExtensions { GetComponentsInChildren(m_Renderers); - for (var i = 0; i < m_Renderers.Count; i++) - { - GetRenderer(i).Clear(i); - } - var j = 0; for (var i = 0; i < particles.Count; i++) { @@ -286,6 +281,11 @@ namespace Coffee.UIExtensions GetRenderer(j++).Set(this, particles[i], true); } } + + for (; j < m_Renderers.Count; j++) + { + GetRenderer(j).Clear(j); + } } internal void UpdateTransformScale() diff --git a/Scripts/UIParticleRenderer.cs b/Scripts/UIParticleRenderer.cs index 4ccfd7d..af47562 100644 --- a/Scripts/UIParticleRenderer.cs +++ b/Scripts/UIParticleRenderer.cs @@ -135,6 +135,9 @@ namespace Coffee.UIExtensions gameObject.layer = parent.gameObject.layer; _particleSystem = particleSystem; +#if UNITY_EDITOR + if (Application.isPlaying) +#endif if (_particleSystem.isPlaying) { _particleSystem.Clear();