Beispiel #1
0
        public override void OnHeaderGUI()
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.BeginVertical();
            bool changed = false;

            changed |= EditorGUILayoutEx.Toggle("Apply On Selection", ref applyOnSelection);
            if (!applyOnSelection)
            {
                changed |= EditorGUILayoutEx.ObjectField <Transform>("Root", ref root, true);
            }
            changed |= typeSelector.DrawSelector();
            Type type = typeSelector.type;

            if (typeSelector.GetType() != null)
            {
                if (fieldInspector.DrawFieldPopup(type, ref field))
                {
                    changed  = true;
                    property = null;
                }
                if (fieldInspector.DrawPropertyPopup(type, ref property))
                {
                    changed = true;
                    field   = null;
                }
            }
            EditorGUILayout.EndVertical();
            if (type != null && changed)
            {
                if (applyOnSelection)
                {
                    if (Selection.gameObjects.Length > 0)
                    {
                        targets.Clear();
                        foreach (GameObject o in Selection.gameObjects)
                        {
                            foreach (Component c in o.GetComponentsInChildren(type, true))
                            {
                                targets.Add(type, c);
                            }
                        }
                    }
                    else if (Selection.objects.Length > 0)
                    {
                        targets.Clear();
                        foreach (Object o in Selection.objects)
                        {
                            if (o is Component)
                            {
                                targets.Add(o.GetType(), o as Component);
                            }
                        }
                    }
                }
                else if (!applyOnSelection && root != null)
                {
                    targets.Clear();
                    foreach (Component c in root.GetComponentsInChildren(type, true))
                    {
                        targets.Add(type, c);
                    }
                }
            }
            EditorGUILayout.EndHorizontal();
        }