diff --git a/Editor/UIParticleEditor.cs b/Editor/UIParticleEditor.cs index 120d7a9..1ea7dcf 100644 --- a/Editor/UIParticleEditor.cs +++ b/Editor/UIParticleEditor.cs @@ -1,6 +1,8 @@ using UnityEditor; using UnityEditor.UI; using UnityEngine; +using System.Collections.Generic; +using System.Linq; namespace Coffee.UIExtensions { @@ -13,7 +15,8 @@ namespace Coffee.UIExtensions //################################ static readonly GUIContent contentParticleMaterial = new GUIContent ("Particle Material", "The material for rendering particles"); static readonly GUIContent contentTrailMaterial = new GUIContent ("Trail Material", "The material for rendering particle trails"); - + static readonly List s_UIParticles = new List (); + static readonly List s_ParticleSystems = new List (); //################################ // Public/Protected Members. @@ -26,6 +29,8 @@ namespace Coffee.UIExtensions base.OnEnable (); _spParticleSystem = serializedObject.FindProperty ("m_ParticleSystem"); _spTrailParticle = serializedObject.FindProperty ("m_TrailParticle"); + _spScale = serializedObject.FindProperty ("m_Scale"); + _spIgnoreParent = serializedObject.FindProperty ("m_IgnoreParent"); } /// @@ -58,11 +63,31 @@ namespace Coffee.UIExtensions EditorGUILayout.PropertyField (_spTrailParticle); EditorGUI.EndDisabledGroup (); - if ((target as UIParticle).GetComponentsInParent (false).Length == 1) + var current = target as UIParticle; + + EditorGUILayout.PropertyField (_spIgnoreParent); + + EditorGUI.BeginDisabledGroup (!current.isRoot); + EditorGUILayout.PropertyField (_spScale); + EditorGUI.EndDisabledGroup (); + + current.GetComponentsInChildren (true, s_ParticleSystems); + if (s_ParticleSystems.Any (x => x.GetComponent () == null)) { - EditorGUILayout.PropertyField (serializedObject.FindProperty ("m_Scale")); + GUILayout.BeginHorizontal (); + EditorGUILayout.HelpBox ("There are child ParticleSystems that does not have a UIParticle component.\nAdd UIParticle component to them.", MessageType.Warning); + GUILayout.BeginVertical (); + if (GUILayout.Button ("Fix")) + { + foreach (var p in s_ParticleSystems.Where (x => !x.GetComponent ())) + { + p.gameObject.AddComponent (); + } + } + GUILayout.EndVertical (); + GUILayout.EndHorizontal (); } - EditorGUILayout.PropertyField (serializedObject.FindProperty ("m_IgnoreParent")); + s_ParticleSystems.Clear (); serializedObject.ApplyModifiedProperties (); } @@ -72,5 +97,7 @@ namespace Coffee.UIExtensions //################################ SerializedProperty _spParticleSystem; SerializedProperty _spTrailParticle; + SerializedProperty _spScale; + SerializedProperty _spIgnoreParent; } } \ No newline at end of file diff --git a/UIParticle.cs b/UIParticle.cs index 14fbed8..3447362 100644 --- a/UIParticle.cs +++ b/UIParticle.cs @@ -94,6 +94,11 @@ namespace Coffee.UIExtensions } } + public bool isRoot + { + get { return !_parent; } + } + public override Material GetModifiedMaterial (Material baseMaterial) { return base.GetModifiedMaterial (_renderer ? _renderer.sharedMaterial : baseMaterial);