Skip to content

Commit

Permalink
close #11; Easy setup in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Nov 28, 2018
1 parent 279a470 commit a8a3bae
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
35 changes: 31 additions & 4 deletions Assets/Coffee/UIExtensions/UIParticle/Editor/UIParticleEditor.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using UnityEditor;
using UnityEditor.UI;
using UnityEngine;
using System.Collections.Generic;
using System.Linq;

namespace Coffee.UIExtensions
{
Expand All @@ -13,7 +15,8 @@ public class UIParticleEditor : GraphicEditor
//################################
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.
Expand All @@ -26,6 +29,8 @@ protected override void OnEnable ()
base.OnEnable ();
_spParticleSystem = serializedObject.FindProperty ("m_ParticleSystem");
_spTrailParticle = serializedObject.FindProperty ("m_TrailParticle");
_spScale = serializedObject.FindProperty ("m_Scale");
_spIgnoreParent = serializedObject.FindProperty ("m_IgnoreParent");
}

/// <summary>
Expand Down Expand Up @@ -58,11 +63,31 @@ public override void OnInspectorGUI ()
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 ();
}
Expand All @@ -72,5 +97,7 @@ public override void OnInspectorGUI ()
//################################
SerializedProperty _spParticleSystem;
SerializedProperty _spTrailParticle;
SerializedProperty _spScale;
SerializedProperty _spIgnoreParent;
}
}
5 changes: 5 additions & 0 deletions Assets/Coffee/UIExtensions/UIParticle/UIParticle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public bool ignoreParent
}
}

public bool isRoot
{
get { return !_parent; }
}

public override Material GetModifiedMaterial (Material baseMaterial)
{
return base.GetModifiedMaterial (_renderer ? _renderer.sharedMaterial : baseMaterial);
Expand Down

0 comments on commit a8a3bae

Please sign in to comment.