close #11; Easy setup in editor

pull/77/head
mob-sakai 2018-11-28 19:55:56 +09:00
parent dfc173ad91
commit 820432b0db
2 changed files with 36 additions and 4 deletions

View File

@ -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<UIParticle> s_UIParticles = new List<UIParticle> ();
static readonly List<ParticleSystem> s_ParticleSystems = new List<ParticleSystem> ();
//################################
// 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");
}
/// <summary>
@ -58,11 +63,31 @@ namespace Coffee.UIExtensions
EditorGUILayout.PropertyField (_spTrailParticle);
EditorGUI.EndDisabledGroup ();
if ((target as UIParticle).GetComponentsInParent<UIParticle> (false).Length == 1)
var current = target as UIParticle;
EditorGUILayout.PropertyField (_spIgnoreParent);
EditorGUI.BeginDisabledGroup (!current.isRoot);
EditorGUILayout.PropertyField (_spScale);
EditorGUI.EndDisabledGroup ();
current.GetComponentsInChildren<ParticleSystem> (true, s_ParticleSystems);
if (s_ParticleSystems.Any (x => x.GetComponent<UIParticle> () == 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<UIParticle> ()))
{
p.gameObject.AddComponent<UIParticle> ();
}
}
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;
}
}

View File

@ -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);