summaryrefslogtreecommitdiff
path: root/Assets/uGUI-2017.1/Editor/UI/SelfControllerEditor.cs
blob: 4510d44eb3e706ea876563fdba6c5221d4db32ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using UnityEngine;
using UnityEngine.UI;

namespace UnityEditor.UI
{
    public class SelfControllerEditor : Editor
    {
        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.";

        public override void OnInspectorGUI()
        {
            bool anyHaveLayoutParent = false;
            for (int i = 0; i < targets.Length; i++)
            {
                Component comp = (targets[i] as Component);
                ILayoutIgnorer ignorer = comp.GetComponent(typeof(ILayoutIgnorer)) as ILayoutIgnorer;
                if (ignorer != null && ignorer.ignoreLayout)
                    continue;

                RectTransform parent = comp.transform.parent as RectTransform;
                if (parent != null)
                {
                    Behaviour layoutGroup = parent.GetComponent(typeof(ILayoutGroup)) as Behaviour;
                    if (layoutGroup != null && layoutGroup.enabled)
                    {
                        anyHaveLayoutParent = true;
                        break;
                    }
                }
            }
            if (anyHaveLayoutParent)
                EditorGUILayout.HelpBox(string.Format(s_Warning, ObjectNames.NicifyVariableName(target.GetType().Name)), MessageType.Warning);
        }
    }
}