@@ -141,36 +141,18 @@ public delegate void DisplayDelegate(
141
141
/// GUIStyle to render label with word-wrap.
142
142
/// </summary>
143
143
static public GUIStyle DefaultLabelStyle {
144
- get {
145
- if ( defaultLabelStyle != null ) {
146
- return defaultLabelStyle ;
147
- } else {
148
- defaultLabelStyle = new GUIStyle ( EditorStyles . label ) ;
149
- defaultLabelStyle . wordWrap = true ;
150
-
151
- return defaultLabelStyle ;
152
- }
153
- }
144
+ get ; private set ;
154
145
}
155
- static private GUIStyle defaultLabelStyle ;
146
+
147
+ /// <summary>
148
+ /// GUIStyle to render dialog title.
149
+ /// </summary>
150
+ static private GUIStyle DefaultTitleStyle ;
156
151
157
152
/// <summary>
158
153
/// GUIStyle to render dialog message.
159
154
/// </summary>
160
- static private GUIStyle DefaultMessageStyle {
161
- get {
162
- if ( defaultMessageStyle != null ) {
163
- return defaultMessageStyle ;
164
- } else {
165
- defaultMessageStyle = new GUIStyle ( EditorStyles . largeLabel ) ;
166
- defaultMessageStyle . fontStyle = FontStyle . Bold ;
167
- defaultMessageStyle . wordWrap = true ;
168
-
169
- return defaultMessageStyle ;
170
- }
171
- }
172
- }
173
- static private GUIStyle defaultMessageStyle ;
155
+ static private GUIStyle DefaultMessageStyle ;
174
156
175
157
// Context for this dialog window.
176
158
private DialogContext dialogContext = new DialogContext ( ) ;
@@ -266,6 +248,28 @@ public static void Display(string title, string message, Option defaultOption,
266
248
windowCloseOption , complete , renderContent , renderButtons , init ) ;
267
249
}
268
250
251
+ /// <summary>
252
+ /// Initialize GUIStyles used by this dialog.
253
+ /// </summary>
254
+ void InitializeStyles ( ) {
255
+ if ( DefaultLabelStyle == null ) {
256
+ DefaultLabelStyle = new GUIStyle ( EditorStyles . label ) ;
257
+ DefaultLabelStyle . wordWrap = true ;
258
+ }
259
+
260
+ if ( DefaultTitleStyle == null ) {
261
+ DefaultTitleStyle = new GUIStyle ( EditorStyles . largeLabel ) ;
262
+ DefaultTitleStyle . fontStyle = FontStyle . Bold ;
263
+ DefaultTitleStyle . wordWrap = true ;
264
+ }
265
+
266
+ if ( DefaultMessageStyle == null ) {
267
+ DefaultMessageStyle = new GUIStyle ( EditorStyles . boldLabel ) ;
268
+ DefaultMessageStyle . wordWrap = true ;
269
+ }
270
+
271
+ }
272
+
269
273
/// <summary>
270
274
/// Render the dialog according to the context.
271
275
/// </summary>
@@ -283,8 +287,15 @@ void OnGUI() {
283
287
} , runNow : false ) ;
284
288
}
285
289
290
+ InitializeStyles ( ) ;
291
+
286
292
Rect rect = EditorGUILayout . BeginVertical ( ) ;
287
293
294
+ if ( ! String . IsNullOrEmpty ( dialogContext . Title ) ) {
295
+ GUILayout . Label ( dialogContext . Title , EditorStyles . boldLabel ) ;
296
+ EditorGUILayout . Space ( ) ;
297
+ }
298
+
288
299
// Render the dialog message.
289
300
GUILayout . Label ( dialogContext . Message , DefaultMessageStyle ) ;
290
301
EditorGUILayout . Space ( ) ;
@@ -321,12 +332,11 @@ void OnGUI() {
321
332
/// Get a list of pairs of the text and enum of each non-empty option.
322
333
/// </summary>
323
334
/// <return>A list of key-value pair where key is text and value is enum.</return>
324
- private List < KeyValuePair < string , Option > > GetOptionMap ( ) {
335
+ private List < KeyValuePair < string , Option > > GetOptionList ( ) {
325
336
List < KeyValuePair < string , Option > > options = new List < KeyValuePair < string , Option > > ( ) ;
326
- if ( ! String . IsNullOrEmpty ( dialogContext . Option0String ) ) {
327
- options . Add ( new KeyValuePair < string , Option > (
328
- dialogContext . Option0String , Option . Selected0 ) ) ;
329
- }
337
+
338
+ // Order the buttons similar to Unity dialog.
339
+ // [ Option 1 (Cancel) ] [ Option 2 (Alt) ] [ Option 0 (Ok) ]
330
340
if ( ! String . IsNullOrEmpty ( dialogContext . Option1String ) ) {
331
341
options . Add ( new KeyValuePair < string , Option > (
332
342
dialogContext . Option1String , Option . Selected1 ) ) ;
@@ -335,6 +345,10 @@ private List<KeyValuePair<string, Option>> GetOptionMap() {
335
345
options . Add ( new KeyValuePair < string , Option > (
336
346
dialogContext . Option2String , Option . Selected2 ) ) ;
337
347
}
348
+ if ( ! String . IsNullOrEmpty ( dialogContext . Option0String ) ) {
349
+ options . Add ( new KeyValuePair < string , Option > (
350
+ dialogContext . Option0String , Option . Selected0 ) ) ;
351
+ }
338
352
return options ;
339
353
}
340
354
@@ -345,8 +359,24 @@ private void RenderOptionButtons () {
345
359
Option selected = Option . SelectedNone ;
346
360
347
361
// Render options with non-empty text.
348
- var options = GetOptionMap ( ) ;
362
+ var options = GetOptionList ( ) ;
363
+
364
+ // Space the button similar to Unity dialog. Ex.
365
+ // | [ Option 1 (Cancel) ] [ Option 2 (Alt) ] [ Option 0 (Ok) ] |
366
+ // | [ Option 1 (Cancel) ] [ Option 0 (Ok) ] |
367
+ // | [ Option 0 (Ok) ] |
368
+ List < int > spacesBeforeButtons = new List < int > ( options . Count == 3 ?
369
+ new int [ 3 ] { 0 , 2 , 0 } :
370
+ new int [ 3 ] { 2 , 0 , 0 } ) ;
371
+
349
372
for ( int i = 0 ; i < options . Count ; ++ i ) {
373
+ // Place spaces before the button.
374
+ if ( i < spacesBeforeButtons . Count ) {
375
+ for ( int j = 0 ; j < spacesBeforeButtons [ i ] ; ++ j ) {
376
+ EditorGUILayout . Space ( ) ;
377
+ }
378
+ }
379
+
350
380
var pair = options [ i ] ;
351
381
if ( GUILayout . Button ( pair . Key ) ) {
352
382
selected = pair . Value ;
0 commit comments