UnityStyles.cs
28.3 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
namespace Unity.PlasticSCM.Editor.UI
{
// Assumption: Members are called from an OnGUI method ( otherwise style composition will fail)
internal static class UnityStyles
{
internal static void Initialize(
Action repaintPlasticWindow)
{
mRepaintPlasticWindow = repaintPlasticWindow;
mLazyBackgroundStyles.Add(WarningMessage);
mLazyBackgroundStyles.Add(SplitterIndicator);
mLazyBackgroundStyles.Add(PlasticWindow.ActiveTabUnderline);
mLazyBackgroundStyles.Add(Notification.GreenNotification);
mLazyBackgroundStyles.Add(Notification.RedNotification);
mLazyBackgroundStyles.Add(CancelButton);
mLazyBackgroundStyles.Add(Inspector.HeaderBackgroundStyle);
mLazyBackgroundStyles.Add(Inspector.DisabledHeaderBackgroundStyle);
}
internal static class Colors
{
internal static Color Transparent = new Color(255f / 255, 255f / 255, 255f / 255, 0f / 255);
internal static Color GreenBackground = new Color(34f / 255, 161f / 255, 63f / 255);
internal static Color GreenText = new Color(0f / 255, 100f / 255, 0f / 255);
internal static Color Red = new Color(194f / 255, 51f / 255, 62f / 255);
internal static Color Warning = new Color(255f / 255, 255f / 255, 176f / 255);
internal static Color Splitter = new Color(100f / 255, 100f / 255, 100f / 255);
internal static Color BarBorder = EditorGUIUtility.isProSkin ?
(Color)new Color32(35, 35, 35, 255) :
(Color)new Color32(153, 153, 153, 255);
#if UNITY_2019
internal static Color InspectorHeaderBackground = (EditorGUIUtility.isProSkin) ?
new Color(60f / 255, 60f / 255, 60f / 255) :
new Color(203f / 255, 203f / 255, 203f / 255);
#else
internal static Color InspectorHeaderBackground = Transparent;
#endif
#if UNITY_2019_1_OR_NEWER
internal static Color InspectorHeaderBackgroundDisabled = (EditorGUIUtility.isProSkin) ?
new Color(58f / 255, 58f / 255, 58f / 255) :
new Color(199f / 255, 199f / 255, 199f / 255);
#else
internal static Color InspectorHeaderBackgroundDisabled = (EditorGUIUtility.isProSkin) ?
new Color(60f / 255, 60f / 255, 60f / 255) :
new Color(210f / 255, 210f / 255, 210f / 255);
#endif
internal static Color TabUnderline = new Color(58f / 255, 121f / 255, 187f / 255);
internal static Color Link = new Color(0f, 120f / 255, 218f / 255);
internal static Color SecondaryLabel = (EditorGUIUtility.isProSkin) ?
new Color(196f / 255, 196f / 255, 196f / 255) :
new Color(105f / 255, 105f / 255, 105f / 255);
internal static Color BackgroundBar = (EditorGUIUtility.isProSkin) ?
new Color(35f / 255, 35f / 255, 35f / 255) :
new Color(160f / 255, 160f / 255, 160f / 255);
internal static Color TreeViewBackground = (EditorGUIUtility.isProSkin) ?
new Color(48f / 255, 48f / 255, 48f / 255) :
new Color(194f / 255, 194f / 255, 194f / 255);
internal static Color CommentsBackground = (EditorGUIUtility.isProSkin) ?
new Color(60f / 255, 60f / 255, 60f / 255) :
new Color(160f / 255, 160f / 255, 160f / 255);
internal static Color ColumnsBackground = (EditorGUIUtility.isProSkin) ?
new Color(56f / 255, 56f / 255, 56f / 255) :
new Color(221f / 255, 221f / 255, 221f / 255);
}
internal static class HexColors
{
internal const string LINK_COLOR = "#0078DA";
}
internal static class Dialog
{
internal static readonly LazyStyle MessageTitle = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.boldLabel);
style.contentOffset = new Vector2(0, -5);
style.wordWrap = true;
style.fontSize = MODAL_FONT_SIZE + 1;
return style;
});
internal static readonly LazyStyle MessageText = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
style.wordWrap = true;
style.fontSize = MODAL_FONT_SIZE;
return style;
});
internal static readonly LazyStyle Toggle = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.boldLabel);
style.fontSize = MODAL_FONT_SIZE;
style.clipping = TextClipping.Overflow;
return style;
});
internal static readonly LazyStyle RadioToggle = new LazyStyle(() =>
{
var radioToggleStyle = new GUIStyle(EditorStyles.radioButton);
radioToggleStyle.fontSize = MODAL_FONT_SIZE;
radioToggleStyle.clipping = TextClipping.Overflow;
radioToggleStyle.font = EditorStyles.largeLabel.font;
return radioToggleStyle;
});
internal static readonly LazyStyle Foldout = new LazyStyle(() =>
{
GUIStyle paragraphStyle = Paragraph;
var foldoutStyle = new GUIStyle(EditorStyles.foldout);
foldoutStyle.fontSize = MODAL_FONT_SIZE;
foldoutStyle.font = paragraphStyle.font;
return foldoutStyle;
});
internal static readonly LazyStyle EntryLabel = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.textField);
style.wordWrap = true;
style.fontSize = MODAL_FONT_SIZE;
return style;
});
internal static readonly LazyStyle AcceptButtonText = new LazyStyle(() =>
{
var style = new GUIStyle(GetEditorSkin().GetStyle("WhiteLabel"));
style.alignment = TextAnchor.MiddleCenter;
style.fontSize = MODAL_FONT_SIZE + 1;
style.normal.background = null;
return style;
});
internal static readonly LazyStyle NormalButton = new LazyStyle(() =>
{
var style = new GUIStyle(GetEditorSkin().button);
style.alignment = TextAnchor.MiddleCenter;
style.fontSize = MODAL_FONT_SIZE;
return style;
});
}
internal static class Tree
{
internal static readonly LazyStyle IconStyle = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.largeLabel);
style.alignment = TextAnchor.MiddleLeft;
return style;
});
internal static readonly LazyStyle Label = new LazyStyle(() =>
{
var style = new GUIStyle(TreeView.DefaultStyles.label);
style.fontSize = 11;
style.alignment = TextAnchor.MiddleLeft;
return style;
});
internal static readonly LazyStyle SecondaryLabel = new LazyStyle(() =>
{
var style = new GUIStyle(TreeView.DefaultStyles.label);
style.fontSize = 11;
style.alignment = TextAnchor.MiddleLeft;
style.active = new GUIStyleState() { textColor = Colors.SecondaryLabel };
style.focused = new GUIStyleState() { textColor = Colors.SecondaryLabel };
style.hover = new GUIStyleState() { textColor = Colors.SecondaryLabel };
style.normal = new GUIStyleState() { textColor = Colors.SecondaryLabel };
return style;
});
internal static readonly LazyStyle InfoLabel = new LazyStyle(() =>
{
var style = new GUIStyle(MultiColumnHeader.DefaultStyles.columnHeader);
return style;
});
internal static readonly LazyStyle SecondaryBoldLabel = new LazyStyle(() =>
{
var style = new GUIStyle(SecondaryLabel);
style.fontStyle = FontStyle.Bold;
return style;
});
internal static readonly LazyStyle RedLabel = new LazyStyle(() =>
{
var style = new GUIStyle(Label);
style.active = new GUIStyleState() { textColor = Colors.Red };
style.focused = new GUIStyleState() { textColor = Colors.Red };
style.hover = new GUIStyleState() { textColor = Colors.Red };
style.normal = new GUIStyleState() { textColor = Colors.Red };
return style;
});
internal static readonly LazyStyle GreenLabel = new LazyStyle(() =>
{
var style = new GUIStyle(Label);
style.active = new GUIStyleState() { textColor = Colors.GreenText };
style.focused = new GUIStyleState() { textColor = Colors.GreenText };
style.hover = new GUIStyleState() { textColor = Colors.GreenText };
style.normal = new GUIStyleState() { textColor = Colors.GreenText };
return style;
});
internal static readonly LazyStyle BoldLabel = new LazyStyle(() =>
{
var style = new GUIStyle(TreeView.DefaultStyles.boldLabel);
style.fontSize = 11;
style.alignment = TextAnchor.MiddleLeft;
return style;
});
internal static readonly LazyStyle LabelRightAligned = new LazyStyle(() =>
{
var style = new GUIStyle(TreeView.DefaultStyles.label);
style.fontSize = 11;
style.alignment = TextAnchor.MiddleRight;
return style;
});
internal static readonly LazyStyle SecondaryLabelRightAligned = new LazyStyle(() =>
{
var style = new GUIStyle(SecondaryLabel);
style.alignment = TextAnchor.MiddleRight;
return style;
});
internal static readonly LazyStyle SecondaryLabelBoldRightAligned = new LazyStyle(() =>
{
var style = new GUIStyle(SecondaryLabelRightAligned);
style.fontStyle = FontStyle.Bold;
return style;
});
internal static readonly LazyStyle StatusLabel = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
style.alignment = TextAnchor.MiddleCenter;
style.fontSize = 14;
style.padding = new RectOffset(
0, 0,
UnityConstants.TREEVIEW_STATUS_CONTENT_PADDING, UnityConstants.TREEVIEW_STATUS_CONTENT_PADDING);
style.stretchWidth = false;
return style;
});
internal static readonly LazyStyle Columns = new LazyStyle(() =>
{
var style = new GUIStyle();
style.normal.background = Images.GetColumnsBackgroundTexture();
return style;
});
}
public static class Inspector
{
public static readonly LazyStyle HeaderBackgroundStyle = new LazyStyle(() =>
{
return CreateUnderlineStyle(
Colors.InspectorHeaderBackground,
UnityConstants.INSPECTOR_ACTIONS_HEADER_BACK_RECTANGLE_HEIGHT);
});
public static readonly LazyStyle DisabledHeaderBackgroundStyle = new LazyStyle(() =>
{
return CreateUnderlineStyle(
Colors.InspectorHeaderBackgroundDisabled,
UnityConstants.INSPECTOR_ACTIONS_HEADER_BACK_RECTANGLE_HEIGHT);
});
}
internal static class PlasticWindow
{
internal static readonly LazyStyle TabButton = new LazyStyle(() =>
{
GUIStyle result = new GUIStyle(EditorStyles.label);
result.padding = EditorStyles.toolbarButton.padding;
result.margin = EditorStyles.toolbarButton.margin;
result.contentOffset = EditorStyles.toolbarButton.contentOffset;
result.alignment = EditorStyles.toolbarButton.alignment;
result.fixedHeight = EditorStyles.toolbarButton.fixedHeight;
return result;
});
internal static readonly LazyStyle ActiveTabUnderline = new LazyStyle(() =>
{
return CreateUnderlineStyle(
Colors.TabUnderline,
UnityConstants.ACTIVE_TAB_UNDERLINE_HEIGHT);
});
}
internal static class StatusBar
{
internal static readonly LazyStyle Icon = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
style.padding.left = 0;
style.padding.right = 0;
return style;
});
internal static readonly LazyStyle Label = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
return style;
});
internal static readonly LazyStyle NotificationLabel = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
style.fontStyle = FontStyle.Bold;
return style;
});
internal static readonly LazyStyle Button = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.miniButtonLeft);
style.fixedWidth = 60;
return style;
});
}
internal static class DiffPanel
{
internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
style.fontSize = 10;
style.fontStyle = FontStyle.Bold;
#if UNITY_2019_1_OR_NEWER
style.contentOffset = new Vector2(0, 1.5f);
#endif
return style;
});
}
internal static class PendingChangesTab
{
internal static readonly LazyStyle CommentPlaceHolder = new LazyStyle(() =>
{
var style = new GUIStyle();
style.normal = new GUIStyleState() { textColor = Color.gray };
style.padding = new RectOffset(7, 0, 4, 0);
return style;
});
internal static readonly LazyStyle CommentTextArea = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.textArea);
style.margin = new RectOffset(7, 4, 0, 0);
style.padding = new RectOffset(0, 0, 4, 0);
return style;
});
internal static readonly LazyStyle CommentWarningIcon = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
style.fontSize = 10;
#if !UNITY_2019_1_OR_NEWER
style.margin = new RectOffset(0, 0, 0, 0);
#endif
return style;
});
internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
style.fontSize = 10;
style.fontStyle = FontStyle.Bold;
#if UNITY_2019_1_OR_NEWER
style.contentOffset = new Vector2(0, 1.5f);
#endif
return style;
});
internal static readonly LazyStyle Comment = new LazyStyle(() =>
{
var style = new GUIStyle();
style.normal.background = Images.GetCommentBackgroundTexture();
return style;
});
internal static readonly GUIStyle DefaultMultiColumHeader = MultiColumnHeader.DefaultStyles.background;
}
internal static class IncomingChangesTab
{
internal static readonly LazyStyle PendingConflictsLabel = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
style.fontSize = 11;
style.padding.top = 2;
style.fontStyle = FontStyle.Bold;
return style;
});
internal static readonly LazyStyle RedPendingConflictsOfTotalLabel = new LazyStyle(() =>
{
var style = new GUIStyle(PendingConflictsLabel);
style.normal = new GUIStyleState() { textColor = Colors.Red };
return style;
});
internal static readonly LazyStyle GreenPendingConflictsOfTotalLabel = new LazyStyle(() =>
{
var style = new GUIStyle(PendingConflictsLabel);
style.normal = new GUIStyleState() { textColor = Colors.GreenText };
return style;
});
internal static readonly LazyStyle ChangesToApplySummaryLabel = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
style.fontSize = 11;
style.padding.top = 2;
return style;
});
internal readonly static LazyStyle HeaderWarningLabel
= new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
style.fontSize = 11;
#if !UNITY_2019_1_OR_NEWER
style.margin = new RectOffset(0, 0, 0, 0);
#endif
return style;
});
}
internal static class ChangesetsTab
{
internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
style.fontSize = 10;
style.fontStyle = FontStyle.Bold;
#if UNITY_2019_1_OR_NEWER
style.contentOffset = new Vector2(0, 1.5f);
#endif
return style;
});
}
internal static class HistoryTab
{
internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
style.fontSize = 10;
style.fontStyle = FontStyle.Bold;
#if UNITY_2019_1_OR_NEWER
style.contentOffset = new Vector2(0, 1.5f);
#endif
return style;
});
}
internal static class DirectoryConflictResolution
{
internal readonly static LazyStyle WarningLabel
= new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
style.alignment = TextAnchor.MiddleLeft;
#if !UNITY_2019_1_OR_NEWER
style.margin = new RectOffset(0, 0, 0, 0);
#endif
return style;
});
}
internal static class Notification
{
internal static readonly LazyStyle Label = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
#if !UNITY_2019_1_OR_NEWER
style.fontSize = 10;
#endif
style.normal = new GUIStyleState() { textColor = Color.white };
return style;
});
internal static readonly LazyStyle GreenNotification = new LazyStyle(() =>
{
var style = new GUIStyle();
style.wordWrap = true;
style.margin = new RectOffset();
style.padding = new RectOffset(4, 4, 2, 2);
style.stretchWidth = true;
style.stretchHeight = true;
style.alignment = TextAnchor.UpperLeft;
var bg = new Texture2D(1, 1);
bg.SetPixel(0, 0, Colors.GreenBackground);
bg.Apply();
style.normal.background = bg;
return style;
});
internal static readonly LazyStyle RedNotification = new LazyStyle(() =>
{
var style = new GUIStyle();
style.wordWrap = true;
style.margin = new RectOffset();
style.padding = new RectOffset(4, 4, 2, 2);
style.stretchWidth = true;
style.stretchHeight = true;
style.alignment = TextAnchor.UpperLeft;
var bg = new Texture2D(1, 1);
bg.SetPixel(0, 0, Colors.Red);
bg.Apply();
style.normal.background = bg;
return style;
});
}
internal static class DirectoryConflicts
{
internal readonly static LazyStyle TitleLabel = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.largeLabel);
RectOffset margin = new RectOffset(
style.margin.left,
style.margin.right,
style.margin.top - 1,
style.margin.bottom);
style.margin = margin;
style.fontStyle = FontStyle.Bold;
return style;
});
internal readonly static LazyStyle BoldLabel = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
style.fontStyle = FontStyle.Bold;
return style;
});
internal readonly static LazyStyle FileNameTextField = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.textField);
RectOffset margin = new RectOffset(
style.margin.left,
style.margin.right,
style.margin.top + 2,
style.margin.bottom);
style.margin = margin;
return style;
});
}
internal static readonly LazyStyle ActionToolbar = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.toolbar);
style.fixedHeight = 40f;
style.padding = new RectOffset(5, 5, 5, 5);
return style;
});
internal static readonly LazyStyle SplitterIndicator = new LazyStyle(() =>
{
return CreateUnderlineStyle(
Colors.Splitter,
UnityConstants.SPLITTER_INDICATOR_HEIGHT);
});
internal static readonly LazyStyle HelpBoxLabel = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
style.fontSize = 10;
style.wordWrap = true;
return style;
});
internal static readonly LazyStyle ProgressLabel = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.label);
style.fontSize = 10;
#if !UNITY_2019_1_OR_NEWER
style.margin = new RectOffset(0, 0, 0, 0);
#endif
return style;
});
internal static readonly LazyStyle TextFieldWithWrapping = new LazyStyle(() =>
{
var style = new GUIStyle(GetEditorSkin().textArea);
style.normal = new GUIStyleState() {
textColor = GetEditorSkin().textArea.normal.textColor,
background = Images.GetTreeviewBackgroundTexture()
};
style.wordWrap = true;
return style;
});
internal static readonly LazyStyle Search = new LazyStyle(() =>
{
var style = new GUIStyle();
style.normal = new GUIStyleState() { textColor = Color.gray };
style.padding = new RectOffset(18, 0, 0, 0);
return style;
});
internal static readonly LazyStyle WarningMessage = new LazyStyle(() =>
{
var style = new GUIStyle(GetEditorSkin().box);
style.wordWrap = true;
style.margin = new RectOffset();
style.padding = new RectOffset(8, 8, 6, 6);
style.stretchWidth = true;
style.alignment = TextAnchor.UpperLeft;
var bg = new Texture2D(1, 1);
bg.SetPixel(0, 0, Colors.Warning);
bg.Apply();
style.normal.background = bg;
return style;
});
internal static readonly LazyStyle CancelButton = new LazyStyle(() =>
{
var normalIcon = Images.GetImage(Images.Name.IconCloseButton);
var pressedIcon = Images.GetImage(Images.Name.IconPressedCloseButton);
var style = new GUIStyle();
style.normal = new GUIStyleState() { background = normalIcon };
style.onActive = new GUIStyleState() { background = pressedIcon };
style.active = new GUIStyleState() { background = pressedIcon };
return style;
});
internal static readonly LazyStyle MiniToggle = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.boldLabel);
style.fontSize = MODAL_FONT_SIZE - 1;
style.clipping = TextClipping.Overflow;
return style;
});
internal static readonly LazyStyle Paragraph = new LazyStyle(() =>
{
var style = new GUIStyle(EditorStyles.largeLabel);
style.wordWrap = true;
style.richText = true;
style.fontSize = MODAL_FONT_SIZE;
return style;
});
static GUISkin GetEditorSkin()
{
GUISkin editorSkin = null;
if (EditorGUIUtility.isProSkin)
editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);
else
editorSkin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);
return editorSkin;
}
static GUIStyle CreateUnderlineStyle(Color color, int height)
{
GUIStyle style = new GUIStyle();
Texture2D pixel = new Texture2D(1, height);
for (int i = 0; i < height; i++)
pixel.SetPixel(0, i, color);
pixel.wrapMode = TextureWrapMode.Repeat;
pixel.Apply();
style.normal.background = pixel;
style.fixedHeight = height;
return style;
}
static void EnsureBackgroundStyles(LazyStyle lazy)
{
// The editor cleans the GUIStyleState.background property
// when entering the edit mode (exiting the play mode)
// and also in other situations (e.g when you use Zoom app)
// Because of this, we have to reset them in order to
// re-instantiate them the next time they're used
if (!mLazyBackgroundStyles.Contains(lazy))
return;
bool needsRepaint = false;
foreach (LazyStyle style in mLazyBackgroundStyles)
{
if (!style.IsInitialized)
continue;
if (style.Value.normal.background != null)
continue;
style.Reset();
needsRepaint = true;
}
if (!needsRepaint)
return;
if (mRepaintPlasticWindow != null)
mRepaintPlasticWindow();
}
static List<LazyStyle> mLazyBackgroundStyles = new List<LazyStyle>();
internal class LazyStyle
{
internal bool IsInitialized { get; private set; }
internal LazyStyle(Func<GUIStyle> builder)
{
mBuilder = builder;
IsInitialized = false;
}
internal GUIStyle Value { get; private set; }
internal void Reset()
{
IsInitialized = false;
}
public static implicit operator GUIStyle(LazyStyle lazy)
{
if (lazy.IsInitialized)
{
EnsureBackgroundStyles(lazy);
return lazy.Value;
}
lazy.Value = lazy.mBuilder();
lazy.IsInitialized = true;
return lazy.Value;
}
readonly Func<GUIStyle> mBuilder;
}
static Action mRepaintPlasticWindow;
const int MODAL_FONT_SIZE = 13;
}
}