20
20
using UnityEditor ;
21
21
namespace Spiral . EditorToolkit
22
22
{
23
- public enum PanelType { Vertical , Horizontal }
23
+ public enum GroupType { Vertical , Horizontal }
24
24
25
25
public static class SpiralEditor
26
26
{
@@ -31,6 +31,8 @@ public static class SpiralEditor
31
31
public static Color colorLightRed { get ; private set ; } = new Color ( 0.9f , 0.7f , 0.7f ) ;
32
32
public static Color colorLightGreen { get ; private set ; } = new Color ( 0.7f , 0.9f , 0.7f ) ;
33
33
public static Color colorLightBlue { get ; private set ; } = new Color ( 0.5f , 0.7f , 0.8f ) ;
34
+ public static Color colorLightYellow { get ; private set ; } = new Color ( 0.9f , 0.9f , 0.7f ) ;
35
+ public static Color colorLightOrange { get ; private set ; } = new Color ( 0.8f , 0.9f , 0.7f ) ;
34
36
35
37
// PANELS ---------------------------------------------------------------------------------
36
38
public static GUIStyle panel { get ; private set ; }
@@ -67,6 +69,45 @@ public static GUIContent GetLabel(string text, string tooltip)
67
69
return output ;
68
70
}
69
71
72
+ // Buttons --------------------------------------------------------------------------------
73
+ public static bool DrawRoundButton ( string name , params GUILayoutOption [ ] options )
74
+ {
75
+ Color prevColor = GUI . color ;
76
+ GUI . color = defaultButtonColor ;
77
+ bool result = GUILayout . Button ( name , buttonNormal , options ) ;
78
+ GUI . color = prevColor ;
79
+ return result ;
80
+ }
81
+
82
+ public static bool DrawRoundButton ( GUIContent name , params GUILayoutOption [ ] options )
83
+ {
84
+ Color prevColor = GUI . color ;
85
+ GUI . color = defaultButtonColor ;
86
+ bool result = GUILayout . Button ( name , buttonNormal , options ) ;
87
+ GUI . color = prevColor ;
88
+ return result ;
89
+ }
90
+
91
+ public static bool DrawRoundButton ( string name , GUIStyle style , params GUILayoutOption [ ] options )
92
+ {
93
+ Color prevColor = GUI . color ;
94
+ GUI . color = defaultButtonColor ;
95
+ if ( style == null ) style = buttonNormal ;
96
+ bool result = GUILayout . Button ( name , style , options ) ;
97
+ GUI . color = prevColor ;
98
+ return result ;
99
+ }
100
+
101
+ public static bool DrawRoundButton ( GUIContent name , GUIStyle style , params GUILayoutOption [ ] options )
102
+ {
103
+ Color prevColor = GUI . color ;
104
+ GUI . color = defaultButtonColor ;
105
+ if ( style == null ) style = buttonNormal ;
106
+ bool result = GUILayout . Button ( name , style , options ) ;
107
+ GUI . color = prevColor ;
108
+ return result ;
109
+ }
110
+
70
111
public static bool DrawRoundButton ( string name , Color ? color = null , params GUILayoutOption [ ] options )
71
112
{
72
113
Color prevColor = GUI . color ;
@@ -85,6 +126,7 @@ public static bool DrawRoundButton(GUIContent name, Color? color = null, params
85
126
return result ;
86
127
}
87
128
129
+ // Captions -------------------------------------------------------------------------------
88
130
public static void DrawCaptionLabel ( GUIContent content , bool selectable = false , bool small = false , params GUILayoutOption [ ] options )
89
131
{
90
132
GUIStyle style = small ? smallBoldLabel : boldLabel ;
@@ -110,44 +152,61 @@ public static void DrawCaptionLabel(GUIContent content, params GUILayoutOption[]
110
152
EditorGUILayout . LabelField ( content , boldLabel , options ) ;
111
153
}
112
154
155
+ // Panels ---------------------------------------------------------------------------------
156
+ private static readonly List < GroupType > panelTypesStack = new List < GroupType > ( ) ;
157
+
158
+ public static void BeginGroup ( GroupType groupType )
159
+ {
160
+ if ( groupType == GroupType . Vertical ) EditorGUILayout . BeginVertical ( ) ;
161
+ else EditorGUILayout . BeginHorizontal ( ) ;
162
+ panelTypesStack . Add ( groupType ) ;
163
+ }
113
164
114
- private static readonly List < PanelType > panelTypesStack = new List < PanelType > ( ) ;
165
+ public static void BeginGroup ( GroupType groupType , Color color )
166
+ {
167
+ Color prevColor = GUI . color ;
168
+ GUI . color = color ;
169
+ if ( groupType == GroupType . Vertical ) EditorGUILayout . BeginVertical ( ) ;
170
+ else EditorGUILayout . BeginHorizontal ( ) ;
171
+ panelTypesStack . Add ( groupType ) ;
172
+ GUI . color = prevColor ;
173
+ }
115
174
116
- public static void BeginPanel ( PanelType panelType , Color ? color = null )
175
+ public static void BeginPanel ( GroupType groupType , Color ? color = null )
117
176
{
118
177
Color prevColor = GUI . color ;
119
178
GUI . color = color != null ? ( Color ) color : defaultPanelColor ;
120
- if ( panelType == PanelType . Vertical ) EditorGUILayout . BeginVertical ( panel ) ;
179
+ if ( groupType == GroupType . Vertical ) EditorGUILayout . BeginVertical ( panel ) ;
121
180
else EditorGUILayout . BeginHorizontal ( panel ) ;
122
- panelTypesStack . Add ( panelType ) ;
181
+ panelTypesStack . Add ( groupType ) ;
123
182
GUI . color = prevColor ;
124
183
}
125
184
126
185
public static void BeginPanel ( string caption , bool smallCaption , params GUILayoutOption [ ] options )
127
186
{
128
- BeginPanel ( PanelType . Vertical ) ;
187
+ BeginPanel ( GroupType . Vertical ) ;
129
188
GUIStyle style = smallCaption ? smallBoldLabel : boldLabel ;
130
189
EditorGUILayout . LabelField ( caption , style , options ) ;
131
190
}
132
191
133
192
public static void BeginPanel ( string caption , Color color , params GUILayoutOption [ ] options )
134
193
{
135
- BeginPanel ( PanelType . Vertical , color ) ;
194
+ BeginPanel ( GroupType . Vertical , color ) ;
136
195
EditorGUILayout . LabelField ( caption , boldLabel , options ) ;
137
196
}
138
197
139
198
public static void BeginPanel ( string caption , bool smallCaption = false , Color ? color = null , params GUILayoutOption [ ] options )
140
199
{
141
200
Color sendColor = color != null ? ( Color ) color : defaultPanelColor ;
142
- BeginPanel ( PanelType . Vertical , sendColor ) ;
201
+ BeginPanel ( GroupType . Vertical , sendColor ) ;
143
202
GUIStyle style = smallCaption ? smallBoldLabel : boldLabel ;
144
203
EditorGUILayout . LabelField ( caption , style , options ) ;
145
204
}
146
205
147
206
public static void BeginPanel ( GUIContent caption , bool smallCaption = false , Color ? color = null , params GUILayoutOption [ ] options )
148
207
{
149
208
Color sendColor = color != null ? ( Color ) color : defaultPanelColor ;
150
- BeginPanel ( PanelType . Vertical , sendColor ) ;
209
+ BeginPanel ( GroupType . Vertical , sendColor ) ;
151
210
GUIStyle style = smallCaption ? smallBoldLabel : boldLabel ;
152
211
EditorGUILayout . LabelField ( caption , style , options ) ;
153
212
}
@@ -156,18 +215,24 @@ public static void EndPanel()
156
215
{
157
216
if ( panelTypesStack . Count == 0 )
158
217
{
159
- Debug . LogWarning ( "No panels to close" ) ;
218
+ Debug . LogWarning ( "No panels or groups to close" ) ;
160
219
return ;
161
220
}
162
- PanelType panelType = panelTypesStack . GetLast ( ) ;
163
- if ( panelType == PanelType . Vertical ) EditorGUILayout . EndVertical ( ) ;
221
+ GroupType panelType = panelTypesStack . GetLast ( ) ;
222
+ if ( panelType == GroupType . Vertical ) EditorGUILayout . EndVertical ( ) ;
164
223
else EditorGUILayout . EndHorizontal ( ) ;
165
224
panelTypesStack . RemoveLast ( ) ;
166
225
}
167
226
227
+ public static void EndGroup ( )
228
+ {
229
+ EndPanel ( ) ;
230
+ }
231
+
232
+ // Script fields --------------------------------------------------------------------------
168
233
public static void DrawScriptField ( SerializedObject serializedObject )
169
234
{
170
- BeginPanel ( PanelType . Vertical ) ;
235
+ BeginPanel ( GroupType . Vertical ) ;
171
236
SerializedProperty prop = serializedObject . FindProperty ( "m_Script" ) ;
172
237
GUI . enabled = prop != null ;
173
238
EditorGUILayout . PropertyField ( prop , true ) ;
@@ -177,7 +242,7 @@ public static void DrawScriptField(SerializedObject serializedObject)
177
242
178
243
public static void DrawEditorScriptField ( ScriptableObject editor )
179
244
{
180
- BeginPanel ( PanelType . Vertical ) ;
245
+ BeginPanel ( GroupType . Vertical ) ;
181
246
GUI . enabled = false ;
182
247
Type type = editor . GetType ( ) ;
183
248
MonoScript monoScript = MonoScript . FromScriptableObject ( editor ) ;
@@ -195,7 +260,7 @@ public static void DrawEditorScriptField(ScriptableObject editor)
195
260
196
261
public static void DrawEditorWindowScriptField ( ScriptableObject editor )
197
262
{
198
- BeginPanel ( PanelType . Vertical ) ;
263
+ BeginPanel ( GroupType . Vertical ) ;
199
264
GUI . enabled = false ;
200
265
Type type = editor . GetType ( ) ;
201
266
MonoScript monoScript = MonoScript . FromScriptableObject ( editor ) ;
@@ -211,6 +276,7 @@ public static void DrawEditorWindowScriptField(ScriptableObject editor)
211
276
EndPanel ( ) ;
212
277
}
213
278
279
+ // Misc -----------------------------------------------------------------------------------
214
280
public static void DrawLogoLine ( Color ? color = null )
215
281
{
216
282
Color defaultColor = GUI . color ;
@@ -223,7 +289,7 @@ public static void DrawLogoLine(Color? color = null)
223
289
224
290
public static void ShowHelp ( string message , ref bool showHelp , MessageType messageType = MessageType . None )
225
291
{
226
- BeginPanel ( PanelType . Vertical ) ;
292
+ BeginPanel ( GroupType . Vertical ) ;
227
293
EditorGUI . indentLevel += 1 ;
228
294
string helpFoldout = showHelp ? "Hide help" : "Show help" ;
229
295
showHelp = EditorGUILayout . Foldout ( showHelp , helpFoldout ) ;
0 commit comments