diff --git a/Scripts/Editor/SoftMaskEditor.cs b/Scripts/Editor/SoftMaskEditor.cs index 3b1eb24..f81cb45 100644 --- a/Scripts/Editor/SoftMaskEditor.cs +++ b/Scripts/Editor/SoftMaskEditor.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEditor; +using System.Linq; namespace Coffee.UIExtensions.Editors @@ -14,6 +15,37 @@ namespace Coffee.UIExtensions.Editors [CanEditMultipleObjects] public class SoftMaskEditor : Editor { + static readonly List s_Graphics = new List (); + + public override void OnInspectorGUI () + { + base.OnInspectorGUI (); + + var current = target as SoftMask; + current.GetComponentsInChildren (true, s_Graphics); + var fixTargets = s_Graphics.Where (x => x.gameObject != current.gameObject && !x.GetComponent () && (!x.GetComponent () || x.GetComponent ().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 (); + } + } + 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)