/
UIModalManagerInspector.cs
108 lines (80 loc) · 3.29 KB
/
UIModalManagerInspector.cs
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using UIModalManager = M8.UIModal.Manager;
using UIController = M8.UIModal.Controller;
[CustomEditor(typeof(UIModalManager))]
public class UIModalManagerInspector : Editor {
private UIController mNewUI = null;
private TextEditor mTE = null;
void OnEnable() {
mTE = new TextEditor();
}
public override void OnInspectorGUI() {
GUI.changed = false;
UIModalManager input = target as UIModalManager;
if(input.uis == null)
input.uis = new UIModalManager.UIData[0];
int delInd = -1;
for(int i = 0; i < input.uis.Length; i++) {
UIModalManager.UIData dat = input.uis[i];
GUILayout.BeginVertical(GUI.skin.box);
GUILayout.BeginHorizontal();
if(dat.e_ui != null) {
GUILayout.Label(dat.e_ui.name);
}
else {
GUILayout.Label("(Need target!)");
}
GUILayout.FlexibleSpace();
if(dat.e_ui != null) {
if(M8.EditorExt.Utility.DrawCopyButton("Click to copy name.")) {
mTE.content = new GUIContent(dat.e_ui.name);
mTE.SelectAll();
mTE.Copy();
}
GUILayout.Space(4);
}
if(M8.EditorExt.Utility.DrawRemoveButton()) {
delInd = i;
}
GUILayout.EndHorizontal();
dat.e_ui = EditorGUILayout.ObjectField("target", dat.e_ui, typeof(UIController), true) as UIController;
if(dat.e_ui) {
dat.name = dat.e_ui.name;
dat.isPrefab = PrefabUtility.GetPrefabType(dat.e_ui) == PrefabType.Prefab;
if(dat.isPrefab) {
dat.instantiateTo = EditorGUILayout.ObjectField("instantiateTo", dat.instantiateTo, typeof(Transform), true) as Transform;
}
}
bool openOnStart = dat.name == input.openOnStart;
bool newOpenOnStart = EditorGUILayout.Toggle("Open On Start", openOnStart);
if(openOnStart != newOpenOnStart) {
input.openOnStart = newOpenOnStart ? dat.name : "";
GUI.changed = true;
}
GUILayout.EndVertical();
}
if(delInd != -1) {
M8.ArrayUtil.RemoveAt(ref input.uis, delInd);
GUI.changed = true;
}
//add new
GUILayout.BeginVertical(GUI.skin.box);
mNewUI = EditorGUILayout.ObjectField(mNewUI, typeof(UIController), true) as UIController;
bool lastEnabled = GUI.enabled;
GUI.enabled = lastEnabled && mNewUI != null;
if(GUILayout.Button("Add")) {
System.Array.Resize(ref input.uis, input.uis.Length + 1);
UIModalManager.UIData newDat = new UIModalManager.UIData();
newDat.e_ui = mNewUI;
input.uis[input.uis.Length - 1] = newDat;
mNewUI = null;
GUI.changed = true;
}
GUI.enabled = lastEnabled;
GUILayout.EndVertical();
if(GUI.changed)
EditorUtility.SetDirty(target);
}
}