Skip to content

Commit

Permalink
close #12; Add a SoftMaskable component to the child UI elements of S…
Browse files Browse the repository at this point in the history
…oftMask From the inspector
  • Loading branch information
mob-sakai committed Dec 17, 2018
1 parent 9d6bf05 commit f9caefe
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Scripts/Editor/SoftMaskEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEditor;
using System.Linq;


namespace Coffee.UIExtensions.Editors
Expand All @@ -14,6 +15,37 @@ namespace Coffee.UIExtensions.Editors
[CanEditMultipleObjects]
public class SoftMaskEditor : Editor
{
static readonly List<Graphic> s_Graphics = new List<Graphic> ();

public override void OnInspectorGUI ()
{
base.OnInspectorGUI ();

var current = target as SoftMask;
current.GetComponentsInChildren<Graphic> (true, s_Graphics);
var fixTargets = s_Graphics.Where (x => x.gameObject != current.gameObject && !x.GetComponent<SoftMaskable> () && (!x.GetComponent<Mask> () || x.GetComponent<Mask> ().showMaskGraphic)).ToList ();
if (0 < fixTargets.Count)
{
GUILayout.BeginHorizontal ();
EditorGUILayout.HelpBox ("There are child Graphicss that does not have a SoftMaskable component.\nAdd SoftMaskable component to them.", MessageType.Warning);
GUILayout.BeginVertical ();
if (GUILayout.Button ("Fix"))
{
foreach (var p in fixTargets)
{
p.gameObject.AddComponent<SoftMaskable> ();
}
}
if (GUILayout.Button ("Ping"))
{
EditorGUIUtility.PingObject (fixTargets[0]);
}
GUILayout.EndVertical ();
GUILayout.EndHorizontal ();
}
}


//%%%% Context menu for editor %%%%
[MenuItem("CONTEXT/Mask/Convert To SoftMask", true)]
static bool _ConvertToSoftMask(MenuCommand command)
Expand Down

0 comments on commit f9caefe

Please sign in to comment.