summaryrefslogtreecommitdiff
path: root/Assets/Plugins/Editor/AdvancedInspector/Examples/ExternalInspectorWindow.cs
blob: e1a7cdacf3bcae8232311c2e946f384c5592fc8e (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using UnityEngine;
using UnityEditor;

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

using AdvancedInspector;

public class ExternalInspectorWindow : EditorWindow
{
    private ExternalEditor editor;

    private GameObject go;
    private Component component;

    [MenuItem("Window/Advanced Insector Example")]
    public static void Init()
    {
        ExternalInspectorWindow window = EditorWindow.GetWindow<ExternalInspectorWindow>();
        window.wantsMouseMove = true;
        window.editor = ExternalEditor.CreateInstance<ExternalEditor>();

        window.editor.DraggableSeparator = false;
        window.editor.DivisionSeparator = 150;
    }

    private void OnSelectionChange()
    {
        go = Selection.activeGameObject;
        Repaint();
    }

    private void OnGUI()
    {
        if (go == null)
        {
            GUILayout.Label("Select a GameObject...");
            component = null;
            editor.Instances = new object[0];
        }
        else
        {
            Component[] components = go.GetComponents(typeof(Component));
            GUIContent[] contents = new GUIContent[components.Length + 1];
            contents[0] = new GUIContent("None");
            int index = -1;
            for (int i = 0; i < components.Length; i++)
            {
                contents[i + 1] = new GUIContent(components[i].GetType().Name);
                if (components[i] == component)
                    index = i + 1;
            }

            EditorGUI.BeginChangeCheck();
            index = EditorGUILayout.Popup(new GUIContent("Select a component: "), index, contents);
            if (EditorGUI.EndChangeCheck())
            {
                if (index == 0)
                {
                    component = null;
                    editor.Instances = new object[0];
                }
                else
                {
                    component = components[index - 1];
                    editor.Instances = new object[] { component };
                }
            }
        }

        if (editor.Draw(new Rect(0, 16, position.width, position.height - 16)))
            Repaint();
    }
}