A game about forced loneliness, made by TACStudios
at master 38 lines 1.5 kB view raw
1using UnityEngine; 2using UnityEngine.UI; 3 4namespace UnityEditor.UI 5{ 6 /// <summary> 7 /// Base class for custom editors that are for components that implement the SelfControllerEditor interface. 8 /// </summary> 9 public class SelfControllerEditor : Editor 10 { 11 static string s_Warning = "Parent has a type of layout group component. A child of a layout group should not have a {0} component, since it should be driven by the layout group."; 12 13 public override void OnInspectorGUI() 14 { 15 bool anyHaveLayoutParent = false; 16 for (int i = 0; i < targets.Length; i++) 17 { 18 Component comp = (targets[i] as Component); 19 ILayoutIgnorer ignorer = comp.GetComponent(typeof(ILayoutIgnorer)) as ILayoutIgnorer; 20 if (ignorer != null && ignorer.ignoreLayout) 21 continue; 22 23 RectTransform parent = comp.transform.parent as RectTransform; 24 if (parent != null) 25 { 26 Behaviour layoutGroup = parent.GetComponent(typeof(ILayoutGroup)) as Behaviour; 27 if (layoutGroup != null && layoutGroup.enabled) 28 { 29 anyHaveLayoutParent = true; 30 break; 31 } 32 } 33 } 34 if (anyHaveLayoutParent) 35 EditorGUILayout.HelpBox(string.Format(s_Warning, ObjectNames.NicifyVariableName(target.GetType().Name)), MessageType.Warning); 36 } 37 } 38}