9
9
using UnityEditor ;
10
10
using UnityEngine ;
11
11
12
- namespace MultiScene . Editor
12
+ namespace MultiScene . Core . Editor
13
13
{
14
14
[ CustomEditor ( typeof ( SceneGroup ) ) ]
15
15
public class SceneGroupEditor : UnityEditor . Editor
16
16
{
17
- public static Color Green => new Color32 ( 72 , 222 , 55 , 255 ) ;
18
- public static Color Yellow => new Color32 ( 245 , 234 , 56 , 255 ) ;
19
- public static Color Orange => new Color32 ( 255 , 170 , 134 , 255 ) ;
20
- public static Color Red => new Color32 ( 255 , 150 , 157 , 255 ) ;
21
- public static Color Blue => new Color32 ( 151 , 196 , 255 , 255 ) ;
22
- public static Color Purple => new Color32 ( 196 , 151 , 255 , 255 ) ;
23
- public static Color Pink => new Color32 ( 255 , 151 , 242 , 255 ) ;
24
- public static Color LightGrey => new Color32 ( 199 , 199 , 199 , 255 ) ;
25
- public static Color DarkGrey => new Color32 ( 88 , 88 , 88 , 255 ) ;
26
- public static Color White => Color . white ;
27
- public static Color Black => Color . black ;
28
-
17
+ private static Color Green => new Color32 ( 72 , 222 , 55 , 255 ) ;
18
+ private static Color Yellow => new Color32 ( 245 , 234 , 56 , 255 ) ;
19
+ private static Color Red => new Color32 ( 255 , 150 , 157 , 255 ) ;
20
+
29
21
30
22
private SerializedProperty scenes ;
31
- private Color defaultBGCol ;
32
- private Color defaultGUICol ;
23
+ private static Color defaultBGCol ;
24
+ private static Color defaultGUICol ;
33
25
26
+
34
27
private void OnEnable ( )
35
28
{
36
29
scenes = serializedObject . FindProperty ( "scenes" ) ;
@@ -43,15 +36,12 @@ public override void OnInspectorGUI()
43
36
{
44
37
serializedObject . Update ( ) ;
45
38
46
- HorizontalCentered ( ( ) =>
47
- {
48
- BoldCompact ( " Scene Group " ) ;
49
- } ) ;
39
+ // Renders the title for the group...
40
+ HorizontalCentered ( RenderSceneGroupTitle ) ;
50
41
42
+ // Shows the base field button if there are no entries in the scene group...
51
43
if ( scenes == null || scenes . arraySize <= 0 )
52
- {
53
44
GreenButton ( "Add Base Scene" , CallAddBaseField ) ;
54
- }
55
45
56
46
if ( scenes . arraySize > 0 )
57
47
{
@@ -60,22 +50,39 @@ public override void OnInspectorGUI()
60
50
if ( scenes . arraySize > 1 )
61
51
RenderAdditiveSceneFields ( ) ;
62
52
else
63
- YellowButton ( "Add Scene" , CallAddNewAdditiveScene ) ;
53
+ YellowButton ( "Add Additive Scene" , CallAddNewAdditiveScene ) ;
54
+
55
+ GUILayout . Space ( 25f ) ;
56
+ RedButton ( "Reset" , CallResetGroup ) ;
64
57
}
65
58
59
+ // Applies changes if changes have been made...
60
+ if ( ! serializedObject . hasModifiedProperties ) return ;
66
61
serializedObject . ApplyModifiedProperties ( ) ;
67
-
68
- // Un-comment for debugging...
69
- //base.OnInspectorGUI();
70
62
}
71
63
72
64
65
+ /// <summary>
66
+ /// Adds the base scene to the editor
67
+ /// </summary>
73
68
private void CallAddBaseField ( )
74
69
{
75
70
scenes . InsertArrayElementAtIndex ( 0 ) ;
76
71
}
72
+
73
+
74
+ /// <summary>
75
+ /// Renders the title section of the editor...
76
+ /// </summary>
77
+ private void RenderSceneGroupTitle ( )
78
+ {
79
+ BoldCompact ( " Scene Group " ) ;
80
+ }
77
81
78
82
83
+ /// <summary>
84
+ /// Renders the base scene grouping...
85
+ /// </summary>
79
86
private void RenderBaseSceneField ( )
80
87
{
81
88
GUI . backgroundColor = Green ;
@@ -87,6 +94,9 @@ private void RenderBaseSceneField()
87
94
}
88
95
89
96
97
+ /// <summary>
98
+ /// Renders the additive scenes into a grouping...
99
+ /// </summary>
90
100
private void RenderAdditiveSceneFields ( )
91
101
{
92
102
GUI . backgroundColor = Yellow ;
@@ -98,33 +108,56 @@ private void RenderAdditiveSceneFields()
98
108
{
99
109
Horizontal ( ( ) =>
100
110
{
111
+ GUI . backgroundColor = Yellow ;
112
+
101
113
EditorGUILayout . PropertyField ( scenes . GetArrayElementAtIndex ( i ) , GUIContent . none ) ;
102
114
103
115
GreenButton ( "+" , ( ) => CallAddNewAdditiveScene ( i ) ) ;
104
116
RedButton ( "-" , ( ) => CallRemoveElementAtIndex ( i ) ) ;
117
+
118
+ GUI . backgroundColor = defaultBGCol ;
105
119
} ) ;
106
120
}
107
121
108
122
GUI . backgroundColor = defaultBGCol ;
109
123
}
110
124
111
-
125
+
126
+ /// <summary>
127
+ /// Removed the element at the index entered...
128
+ /// </summary>
129
+ /// <param name="i">The element to edit</param>
112
130
private void CallRemoveElementAtIndex ( int i )
113
131
{
114
132
scenes . DeleteArrayElementAtIndex ( i ) ;
115
133
}
116
134
135
+ /// <summary>
136
+ /// Adds a new element to the scenes list that is blank at the element entered.
137
+ /// </summary>
138
+ /// <param name="i">The element to edit</param>
117
139
private void CallAddNewAdditiveScene ( int i )
118
140
{
119
141
scenes . InsertArrayElementAtIndex ( i ) ;
120
142
scenes . GetArrayElementAtIndex ( i + 1 ) . stringValue = string . Empty ;
121
143
}
122
144
145
+ /// <summary>
146
+ /// Adds a new element to the scenes list that is blank.
147
+ /// </summary>
123
148
private void CallAddNewAdditiveScene ( )
124
149
{
125
150
scenes . InsertArrayElementAtIndex ( scenes . arraySize - 1 ) ;
126
151
scenes . GetArrayElementAtIndex ( scenes . arraySize - 1 ) . stringValue = string . Empty ;
127
152
}
153
+
154
+ /// <summary>
155
+ /// Resets the scenes list to a new list.
156
+ /// </summary>
157
+ private void CallResetGroup ( )
158
+ {
159
+ scenes . ClearArray ( ) ;
160
+ }
128
161
129
162
/// <summary>
130
163
/// Shows a compact button where the label controls the size of the button.
@@ -145,11 +178,10 @@ private static bool CompactButton(string label)
145
178
/// <param name="options">GUILayoutOption[] | Layout options.</param>
146
179
private static void GreenButton ( string label , Action callback , params GUILayoutOption [ ] options )
147
180
{
148
- var _default = GUI . backgroundColor ;
149
181
GUI . backgroundColor = Green ;
150
182
if ( GUILayout . Button ( label , options ) )
151
183
callback ( ) ;
152
- GUI . backgroundColor = _default ;
184
+ GUI . backgroundColor = defaultBGCol ;
153
185
}
154
186
155
187
@@ -161,11 +193,10 @@ private static void GreenButton(string label, Action callback, params GUILayoutO
161
193
/// <param name="options">GUILayoutOption[] | Layout options.</param>
162
194
private static void YellowButton ( string label , Action callback , params GUILayoutOption [ ] options )
163
195
{
164
- var _default = GUI . backgroundColor ;
165
196
GUI . backgroundColor = Yellow ;
166
197
if ( GUILayout . Button ( label , options ) )
167
198
callback ( ) ;
168
- GUI . backgroundColor = _default ;
199
+ GUI . backgroundColor = defaultBGCol ;
169
200
}
170
201
171
202
@@ -175,13 +206,12 @@ private static void YellowButton(string label, Action callback, params GUILayout
175
206
/// <param name="label">String | Label for the button.</param>
176
207
/// <param name="callback">Action | The actions to perform on button press.</param>
177
208
/// <param name="options">GUILayoutOption[] | Layout options.</param>
178
- public static void RedButton ( string label , Action callback , params GUILayoutOption [ ] options )
209
+ private static void RedButton ( string label , Action callback , params GUILayoutOption [ ] options )
179
210
{
180
- var _default = GUI . backgroundColor ;
181
211
GUI . backgroundColor = Red ;
182
212
if ( GUILayout . Button ( label , options ) )
183
213
callback ( ) ;
184
- GUI . backgroundColor = _default ;
214
+ GUI . backgroundColor = defaultBGCol ;
185
215
}
186
216
187
217
/// <summary>
@@ -221,7 +251,7 @@ private static float TextWidth(string text)
221
251
/// </summary>
222
252
/// <param name="blockElements">Action | Stuff to display</param>
223
253
/// <remarks>Actions can be () => {} or a method.</remarks>
224
- public static void Horizontal ( Action blockElements )
254
+ private static void Horizontal ( Action blockElements )
225
255
{
226
256
EditorGUILayout . BeginHorizontal ( ) ;
227
257
blockElements ( ) ;
@@ -234,7 +264,7 @@ public static void Horizontal(Action blockElements)
234
264
/// </summary>
235
265
/// <param name="blockElements">Action | Stuff to display</param>
236
266
/// <remarks>Actions can be () => {} or a method.</remarks>
237
- public static void HorizontalCentered ( Action blockElements )
267
+ private static void HorizontalCentered ( Action blockElements )
238
268
{
239
269
EditorGUILayout . BeginHorizontal ( ) ;
240
270
GUILayout . FlexibleSpace ( ) ;
0 commit comments