A game about forced loneliness, made by TACStudios
1using System;
2using System.Collections.Generic;
3using System.ComponentModel;
4using UnityEditor;
5using UnityEditor.IMGUI.Controls;
6using UnityEngine;
7
8namespace Unity.PlasticSCM.Editor.UI
9{
10 // Assumption: Members are called from an OnGUI method ( otherwise style composition will fail)
11 internal static class UnityStyles
12 {
13 internal static void Initialize(
14 Action repaintPlasticWindow)
15 {
16 mRepaintPlasticWindow = repaintPlasticWindow;
17
18 mLazyBackgroundStyles.Add(WarningMessage);
19 mLazyBackgroundStyles.Add(SplitterIndicator);
20 mLazyBackgroundStyles.Add(PlasticWindow.ActiveTabUnderline);
21 mLazyBackgroundStyles.Add(Notification.GreenNotification);
22 mLazyBackgroundStyles.Add(Notification.RedNotification);
23 mLazyBackgroundStyles.Add(CancelButton);
24 mLazyBackgroundStyles.Add(Inspector.HeaderBackgroundStyle);
25 mLazyBackgroundStyles.Add(Inspector.DisabledHeaderBackgroundStyle);
26 }
27
28 internal static class Colors
29 {
30 internal static Color Transparent = new Color(255f / 255, 255f / 255, 255f / 255, 0f / 255);
31 internal static Color GreenBackground = new Color(34f / 255, 161f / 255, 63f / 255);
32 internal static Color GreenText = new Color(0f / 255, 100f / 255, 0f / 255);
33 internal static Color Red = new Color(194f / 255, 51f / 255, 62f / 255);
34 internal static Color Warning = new Color(255f / 255, 255f / 255, 176f / 255);
35 internal static Color Splitter = new Color(100f / 255, 100f / 255, 100f / 255);
36 internal static Color BarBorder = EditorGUIUtility.isProSkin ?
37 (Color)new Color32(35, 35, 35, 255) :
38 (Color)new Color32(153, 153, 153, 255);
39 internal static Color DarkGray = new Color(88f / 255, 88f / 255, 88f / 255);
40
41 internal static Color InspectorHeaderBackground = Transparent;
42
43 internal static Color InspectorHeaderBackgroundDisabled = EditorGUIUtility.isProSkin ?
44 new Color(58f / 255, 58f / 255, 58f / 255) :
45 new Color(199f / 255, 199f / 255, 199f / 255);
46
47 internal static Color TabUnderline = new Color(58f / 255, 121f / 255, 187f / 255);
48 internal static Color Link = new Color(0f, 120f / 255, 218f / 255);
49 internal static Color SecondaryLabel = EditorGUIUtility.isProSkin ?
50 new Color(196f / 255, 196f / 255, 196f / 255) :
51 new Color(105f / 255, 105f / 255, 105f / 255);
52 internal static Color BackgroundBar = EditorGUIUtility.isProSkin ?
53 new Color(35f / 255, 35f / 255, 35f / 255) :
54 new Color(160f / 255, 160f / 255, 160f / 255);
55
56 internal static Color TreeViewBackground = EditorGUIUtility.isProSkin ?
57 new Color(48f / 255, 48f / 255, 48f / 255) :
58 new Color(194f / 255, 194f / 255, 194f / 255);
59
60 internal static Color CommentsBackground = EditorGUIUtility.isProSkin ?
61 new Color(60f / 255, 60f / 255, 60f / 255) :
62 new Color(160f / 255, 160f / 255, 160f / 255);
63
64 internal static Color ColumnsBackground = EditorGUIUtility.isProSkin ?
65 new Color(56f / 255, 56f / 255, 56f / 255) :
66 new Color(221f / 255, 221f / 255, 221f / 255);
67
68 internal static Color ToggleOffText = EditorGUIUtility.isProSkin ?
69 new Color(131f / 255, 131f / 255, 131f / 255) :
70 new Color(151f / 255, 151f / 255, 151f / 255);
71
72 internal static Color ToggleHoverText = EditorGUIUtility.isProSkin ?
73 new Color(129f / 255, 180f / 255, 255f / 255) :
74 new Color(7f / 255, 68f / 255, 146f / 255);
75 }
76
77 internal static class Dialog
78 {
79 internal static readonly LazyStyle MessageTitle = new LazyStyle(() =>
80 {
81 var style = new GUIStyle(EditorStyles.boldLabel);
82 style.contentOffset = new Vector2(0, -5);
83 style.wordWrap = true;
84 style.fontSize = MODAL_FONT_SIZE + 1;
85 return style;
86 });
87
88 internal static readonly LazyStyle SectionTitle = new LazyStyle(() =>
89 {
90 var style = new GUIStyle(EditorStyles.boldLabel);
91 style.contentOffset = new Vector2(0, -5);
92 style.wordWrap = true;
93 style.fontSize = MODAL_FONT_SIZE;
94 return style;
95 });
96
97 internal static readonly LazyStyle MessageText = new LazyStyle(() =>
98 {
99 var style = new GUIStyle(EditorStyles.label);
100 style.wordWrap = true;
101 style.fontSize = MODAL_FONT_SIZE;
102 return style;
103 });
104
105 internal static readonly LazyStyle BoldText = new LazyStyle(() =>
106 {
107 var style = new GUIStyle(EditorStyles.label);
108 style.wordWrap = true;
109 style.fontSize = MODAL_FONT_SIZE;
110 style.fontStyle = FontStyle.Bold;
111 return style;
112 });
113
114 internal static readonly LazyStyle Toggle = new LazyStyle(() =>
115 {
116 var style = new GUIStyle(EditorStyles.boldLabel);
117 style.fontSize = MODAL_FONT_SIZE;
118 style.clipping = TextClipping.Overflow;
119 return style;
120 });
121
122 internal static readonly LazyStyle CheckBox = new LazyStyle(() =>
123 {
124 var radioToggleStyle = new GUIStyle(EditorStyles.toggle);
125 radioToggleStyle.fontSize = MODAL_FONT_SIZE - 1;
126 radioToggleStyle.clipping = TextClipping.Overflow;
127 radioToggleStyle.contentOffset = new Vector2(5, 0);
128 return radioToggleStyle;
129 });
130
131 internal static readonly LazyStyle RadioToggle = new LazyStyle(() =>
132 {
133 var radioToggleStyle = new GUIStyle(EditorStyles.radioButton);
134 radioToggleStyle.fontSize = MODAL_FONT_SIZE - 1;
135 radioToggleStyle.clipping = TextClipping.Overflow;
136 radioToggleStyle.contentOffset = new Vector2(5, -2);
137 return radioToggleStyle;
138 });
139
140 internal static readonly LazyStyle BoldRadioToggle = new LazyStyle(() =>
141 {
142 var radioToggleStyle = new GUIStyle(EditorStyles.radioButton);
143 radioToggleStyle.fontSize = MODAL_FONT_SIZE;
144 radioToggleStyle.fontStyle = FontStyle.Bold;
145 radioToggleStyle.clipping = TextClipping.Overflow;
146 radioToggleStyle.contentOffset = new Vector2(5, -2);
147 return radioToggleStyle;
148 });
149
150 internal static readonly LazyStyle Foldout = new LazyStyle(() =>
151 {
152 GUIStyle paragraphStyle = Paragraph;
153 var foldoutStyle = new GUIStyle(EditorStyles.foldout);
154 foldoutStyle.fontSize = MODAL_FONT_SIZE;
155 foldoutStyle.font = paragraphStyle.font;
156 return foldoutStyle;
157 });
158
159 internal static readonly LazyStyle EntryLabel = new LazyStyle(() =>
160 {
161 var style = new GUIStyle(EditorStyles.textField);
162 style.wordWrap = true;
163 style.fontSize = MODAL_FONT_SIZE;
164 return style;
165 });
166
167 internal static readonly LazyStyle AcceptButtonText = new LazyStyle(() =>
168 {
169 var style = new GUIStyle(GetEditorSkin().GetStyle("WhiteLabel"));
170 style.alignment = TextAnchor.MiddleCenter;
171 style.fontSize = MODAL_FONT_SIZE + 1;
172 style.normal.background = null;
173 return style;
174 });
175
176 internal static readonly LazyStyle NormalButton = new LazyStyle(() =>
177 {
178 var style = new GUIStyle(GetEditorSkin().button);
179 style.alignment = TextAnchor.MiddleCenter;
180 style.fontSize = MODAL_FONT_SIZE;
181 return style;
182 });
183
184 internal static readonly UnityStyles.LazyStyle FlatButton = new UnityStyles.LazyStyle(() =>
185 {
186 var style = new GUIStyle(EditorStyles.miniButton);
187 style.alignment = TextAnchor.MiddleCenter;
188 style.fixedWidth = 22;
189 style.fixedHeight = 22;
190 style.margin = new RectOffset(10, 0, 0, 0);
191 style.padding = new RectOffset(0, 0, 0, 0);
192 return style;
193 });
194 }
195
196 internal static class Tree
197 {
198 internal static readonly LazyStyle IconStyle = new LazyStyle(() =>
199 {
200 var style = new GUIStyle(EditorStyles.largeLabel);
201 style.alignment = TextAnchor.MiddleLeft;
202 return style;
203 });
204
205 internal static readonly LazyStyle Label = new LazyStyle(() =>
206 {
207 var style = new GUIStyle(TreeView.DefaultStyles.label);
208 style.fontSize = UnityConstants.LABEL_FONT_SIZE;
209 style.alignment = TextAnchor.MiddleLeft;
210 return style;
211 });
212
213 internal static readonly LazyStyle SecondaryLabel = new LazyStyle(() =>
214 {
215 var style = new GUIStyle(TreeView.DefaultStyles.label);
216 style.fontSize = UnityConstants.LABEL_FONT_SIZE;
217 style.alignment = TextAnchor.MiddleLeft;
218
219 style.active = new GUIStyleState() { textColor = Colors.SecondaryLabel };
220 style.focused = new GUIStyleState() { textColor = Colors.SecondaryLabel };
221 style.hover = new GUIStyleState() { textColor = Colors.SecondaryLabel };
222 style.normal = new GUIStyleState() { textColor = Colors.SecondaryLabel };
223
224 return style;
225 });
226
227 internal static readonly LazyStyle InfoLabel = new LazyStyle(() =>
228 {
229 var style = new GUIStyle(MultiColumnHeader.DefaultStyles.columnHeader);
230 return style;
231 });
232
233 internal static readonly LazyStyle SecondaryBoldLabel = new LazyStyle(() =>
234 {
235 var style = new GUIStyle(SecondaryLabel);
236 style.fontStyle = FontStyle.Bold;
237 return style;
238 });
239
240 internal static readonly LazyStyle RedLabel = new LazyStyle(() =>
241 {
242 var style = new GUIStyle(Label);
243 style.active = new GUIStyleState() { textColor = Colors.Red };
244 style.focused = new GUIStyleState() { textColor = Colors.Red };
245 style.hover = new GUIStyleState() { textColor = Colors.Red };
246 style.normal = new GUIStyleState() { textColor = Colors.Red };
247 return style;
248 });
249
250 internal static readonly LazyStyle GreenLabel = new LazyStyle(() =>
251 {
252 var style = new GUIStyle(Label);
253 style.active = new GUIStyleState() { textColor = Colors.GreenText };
254 style.focused = new GUIStyleState() { textColor = Colors.GreenText };
255 style.hover = new GUIStyleState() { textColor = Colors.GreenText };
256 style.normal = new GUIStyleState() { textColor = Colors.GreenText };
257 return style;
258 });
259
260 internal static readonly LazyStyle BoldLabel = new LazyStyle(() =>
261 {
262 var style = new GUIStyle(TreeView.DefaultStyles.boldLabel);
263 style.fontSize = UnityConstants.LABEL_FONT_SIZE;
264 style.alignment = TextAnchor.MiddleLeft;
265 return style;
266 });
267
268 internal static readonly LazyStyle LabelRightAligned = new LazyStyle(() =>
269 {
270 var style = new GUIStyle(TreeView.DefaultStyles.label);
271 style.fontSize = UnityConstants.LABEL_FONT_SIZE;
272 style.alignment = TextAnchor.MiddleRight;
273 return style;
274 });
275
276 internal static readonly LazyStyle SecondaryLabelRightAligned = new LazyStyle(() =>
277 {
278 var style = new GUIStyle(SecondaryLabel);
279 style.alignment = TextAnchor.MiddleRight;
280 return style;
281 });
282
283 internal static readonly LazyStyle SecondaryLabelBoldRightAligned = new LazyStyle(() =>
284 {
285 var style = new GUIStyle(SecondaryLabelRightAligned);
286 style.fontStyle = FontStyle.Bold;
287 return style;
288 });
289
290 internal static readonly LazyStyle StatusLabel = new LazyStyle(() =>
291 {
292 var style = new GUIStyle(EditorStyles.label);
293 style.alignment = TextAnchor.MiddleCenter;
294 style.fontSize = 14;
295 style.stretchWidth = false;
296 return style;
297 });
298
299 internal static readonly LazyStyle CopyToClipboardButton = new LazyStyle(() =>
300 {
301 var style = new GUIStyle(EditorStyles.miniButton);
302 style.alignment = TextAnchor.MiddleCenter;
303 style.fixedWidth = 28;
304 style.fixedHeight = 22;
305 style.margin = new RectOffset(0, 0, 0, 0);
306 style.padding = new RectOffset(0, 0, 2, 2);
307 return style;
308 });
309
310 internal static readonly LazyStyle Columns = new LazyStyle(() =>
311 {
312 var style = new GUIStyle();
313 style.normal.background = Images.GetColumnsBackgroundTexture();
314 return style;
315 });
316 }
317
318 // Internal usage. This isn't a public API.
319 [EditorBrowsable(EditorBrowsableState.Never)]
320 public static class Inspector
321 {
322 // Internal usage. This isn't a public API.
323 [EditorBrowsable(EditorBrowsableState.Never)]
324 public static readonly LazyStyle HeaderBackgroundStyle = new LazyStyle(() =>
325 {
326 return CreateUnderlineStyle(
327 Colors.InspectorHeaderBackground,
328 UnityConstants.INSPECTOR_ACTIONS_HEADER_BACK_RECTANGLE_HEIGHT);
329 });
330
331 // Internal usage. This isn't a public API.
332 [EditorBrowsable(EditorBrowsableState.Never)]
333 public static readonly LazyStyle DisabledHeaderBackgroundStyle = new LazyStyle(() =>
334 {
335 return CreateUnderlineStyle(
336 Colors.InspectorHeaderBackgroundDisabled,
337 UnityConstants.INSPECTOR_ACTIONS_HEADER_BACK_RECTANGLE_HEIGHT);
338 });
339 }
340
341 internal static class ProjectSettings
342 {
343 internal static readonly LazyStyle ToggleOn = new LazyStyle(() =>
344 {
345 GUIStyle result = new GUIStyle(Toggle);
346 result.hover.textColor = Colors.ToggleHoverText;
347 return result;
348 });
349
350 internal static readonly LazyStyle FoldoutHeader = new LazyStyle(() =>
351 {
352 GUIStyle result = new GUIStyle(EditorStyles.foldoutHeader);
353 result.fontStyle = FontStyle.Bold;
354 result.fontSize = MODAL_FONT_SIZE;
355 return result;
356 });
357
358 internal static readonly LazyStyle SectionTitle = new LazyStyle(() =>
359 {
360 GUIStyle result = new GUIStyle(EditorStyles.label);
361 result.fontStyle = FontStyle.Bold;
362 result.fontSize = MODAL_FONT_SIZE;
363 return result;
364 });
365
366 internal static readonly LazyStyle Title = new LazyStyle(() =>
367 {
368 GUIStyle result = new GUIStyle(EditorStyles.label);
369 result.fontStyle = FontStyle.Bold;
370 result.fontSize = MODAL_FONT_SIZE - 1;
371 return result;
372 });
373
374 internal static readonly LazyStyle Paragraph = new LazyStyle(() =>
375 {
376 var style = new GUIStyle(EditorStyles.label);
377 style.wordWrap = true;
378 style.richText = true;
379 style.fontSize = MODAL_FONT_SIZE - 1;
380 return style;
381 });
382
383 static readonly LazyStyle Toggle = new LazyStyle(() =>
384 {
385 GUIStyle result = new GUIStyle(EditorStyles.miniButton);
386 result.fixedHeight = 22;
387 result.fixedWidth = 85;
388 result.fontSize = 12;
389 return result;
390 });
391 }
392
393 internal static class PlasticWindow
394 {
395 internal static readonly LazyStyle TabButton = new LazyStyle(() =>
396 {
397 GUIStyle result = new GUIStyle(EditorStyles.label);
398 result.padding = EditorStyles.toolbarButton.padding;
399 result.margin = EditorStyles.toolbarButton.margin;
400 result.contentOffset = EditorStyles.toolbarButton.contentOffset;
401 result.alignment = EditorStyles.toolbarButton.alignment;
402 result.fixedHeight = EditorStyles.toolbarButton.fixedHeight;
403 return result;
404 });
405
406 internal static readonly LazyStyle ActiveTabUnderline = new LazyStyle(() =>
407 {
408 return CreateUnderlineStyle(
409 Colors.TabUnderline,
410 UnityConstants.ACTIVE_TAB_UNDERLINE_HEIGHT);
411 });
412 }
413
414 internal static class StatusBar
415 {
416 internal static readonly LazyStyle Icon = new LazyStyle(() =>
417 {
418 var style = new GUIStyle(EditorStyles.label);
419 style.padding.left = 0;
420 style.padding.right = 0;
421 return style;
422 });
423
424 internal static readonly LazyStyle Label = new LazyStyle(() =>
425 {
426 var style = new GUIStyle(EditorStyles.label);
427 return style;
428 });
429
430 internal static readonly LazyStyle LinkLabel = new LazyStyle(() =>
431 {
432 var style = new GUIStyle(EditorStyles.linkLabel);
433 style.padding = EditorStyles.label.padding;
434 return style;
435 });
436
437 internal static readonly LazyStyle NotificationLabel = new LazyStyle(() =>
438 {
439 var style = new GUIStyle(EditorStyles.label);
440 style.fontStyle = FontStyle.Bold;
441 return style;
442 });
443
444 internal static readonly LazyStyle Button = new LazyStyle(() =>
445 {
446 var style = new GUIStyle(EditorStyles.miniButtonLeft);
447 style.fixedWidth = 60;
448 return style;
449 });
450
451 internal static readonly LazyStyle NotificationPanel = new LazyStyle(() =>
452 {
453 var style = new GUIStyle(EditorStyles.helpBox);
454 style.fixedHeight = 24;
455 return style;
456 });
457
458 internal static readonly LazyStyle NotificationPanelCloseButton = new LazyStyle(() =>
459 {
460 var style = new GUIStyle(EditorStyles.label);
461 style.fixedHeight = 16;
462 style.fixedWidth = 16;
463 return style;
464 });
465
466 internal static readonly LazyStyle CopyToClipboardButton = new LazyStyle(() =>
467 {
468 var style = new GUIStyle(EditorStyles.miniButton);
469 style.alignment = TextAnchor.MiddleCenter;
470 style.fixedWidth = 28;
471 style.fixedHeight = 22;
472 style.margin = new RectOffset(0, 0, 0, 0);
473 style.padding = new RectOffset(0, 0, 2, 2);
474 return style;
475 });
476 }
477
478 internal static class DiffPanel
479 {
480 internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
481 {
482 var style = new GUIStyle(EditorStyles.label);
483 style.fontSize = 10;
484 style.fontStyle = FontStyle.Bold;
485 style.contentOffset = new Vector2(0, 1.5f);
486 return style;
487 });
488 }
489
490 internal static class PendingChangesTab
491 {
492 internal static readonly LazyStyle CommentPlaceHolder = new LazyStyle(() =>
493 {
494 var style = new GUIStyle();
495 style.normal = new GUIStyleState() { textColor = Color.gray };
496 style.padding = new RectOffset(7, 0, 4, 0);
497 return style;
498 });
499
500 internal static readonly LazyStyle CommentTextArea = new LazyStyle(() =>
501 {
502 var style = new GUIStyle(EditorStyles.textArea);
503 style.margin = new RectOffset(7, 4, 0, 0);
504 style.padding = new RectOffset(0, 0, 4, 0);
505
506 return style;
507 });
508
509 internal static readonly LazyStyle CommentWarningIcon = new LazyStyle(() =>
510 {
511 var style = new GUIStyle(EditorStyles.label);
512 style.fontSize = 10;
513 return style;
514 });
515
516 internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
517 {
518 var style = new GUIStyle(EditorStyles.label);
519 style.fontSize = 10;
520 style.fontStyle = FontStyle.Bold;
521 style.contentOffset = new Vector2(0, 1.5f);
522 return style;
523 });
524
525 internal static readonly LazyStyle Comment = new LazyStyle(() =>
526 {
527 var style = new GUIStyle();
528 style.normal.background = Images.GetCommentBackgroundTexture();
529 return style;
530 });
531
532 internal static readonly GUIStyle DefaultMultiColumHeader = MultiColumnHeader.DefaultStyles.background;
533 }
534
535 internal static class MergeTab
536 {
537 internal static readonly LazyStyle PendingConflictsLabel = new LazyStyle(() =>
538 {
539 var style = new GUIStyle(EditorStyles.label);
540 style.fontSize = 11;
541 style.padding.top = 2;
542 style.fontStyle = FontStyle.Bold;
543 return style;
544 });
545
546 internal static readonly LazyStyle RedPendingConflictsOfTotalLabel = new LazyStyle(() =>
547 {
548 var style = new GUIStyle(PendingConflictsLabel);
549 style.normal = new GUIStyleState() { textColor = Colors.Red };
550 return style;
551 });
552
553 internal static readonly LazyStyle GreenPendingConflictsOfTotalLabel = new LazyStyle(() =>
554 {
555 var style = new GUIStyle(PendingConflictsLabel);
556 style.normal = new GUIStyleState() { textColor = Colors.GreenText };
557 return style;
558 });
559
560 internal static readonly LazyStyle TitleLabel = new LazyStyle(() =>
561 {
562 var style = new GUIStyle(EditorStyles.label);
563 style.fontSize = 12;
564 style.fontStyle = FontStyle.Bold;
565 return style;
566 });
567
568 internal static readonly LazyStyle InfoLabel = new LazyStyle(() =>
569 {
570 var style = new GUIStyle(EditorStyles.label);
571 style.fontSize = 11;
572 style.padding.top = 2;
573 return style;
574 });
575
576 internal static readonly LazyStyle LinkLabel = new LazyStyle(() =>
577 {
578 var style = new GUIStyle(UnityStyles.LinkLabel);
579 style.fontSize = ((GUIStyle)InfoLabel).fontSize;
580 style.padding.top = ((GUIStyle)InfoLabel).padding.top;
581 style.padding.left = 0;
582 style.stretchWidth = false;
583 return style;
584 });
585 }
586
587 internal static class ChangesetsTab
588 {
589 internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
590 {
591 var style = new GUIStyle(EditorStyles.label);
592 style.fontSize = 10;
593 style.fontStyle = FontStyle.Bold;
594 style.contentOffset = new Vector2(0, 1.5f);
595 return style;
596 });
597 }
598
599 internal static class HistoryTab
600 {
601 internal static readonly LazyStyle HeaderLabel = new LazyStyle(() =>
602 {
603 var style = new GUIStyle(EditorStyles.label);
604 style.fontSize = 12;
605 style.fontStyle = FontStyle.Bold;
606 return style;
607 });
608 }
609
610 internal static class DirectoryConflictResolution
611 {
612 internal readonly static LazyStyle WarningLabel
613 = new LazyStyle(() =>
614 {
615 var style = new GUIStyle(EditorStyles.label);
616 style.alignment = TextAnchor.MiddleLeft;
617 return style;
618 });
619 }
620
621 internal static class Notification
622 {
623 internal static readonly LazyStyle Label = new LazyStyle(() =>
624 {
625 var style = new GUIStyle(EditorStyles.label);
626 style.normal = new GUIStyleState() { textColor = Color.white };
627 return style;
628 });
629
630 internal static readonly LazyStyle GreenNotification = new LazyStyle(() =>
631 {
632 var style = new GUIStyle();
633 style.wordWrap = true;
634 style.margin = new RectOffset();
635 style.padding = new RectOffset(4, 4, 2, 2);
636 style.stretchWidth = true;
637 style.stretchHeight = true;
638 style.alignment = TextAnchor.UpperLeft;
639
640 var bg = new Texture2D(1, 1);
641 bg.SetPixel(0, 0, Colors.GreenBackground);
642 bg.Apply();
643 style.normal.background = bg;
644 return style;
645 });
646
647 internal static readonly LazyStyle RedNotification = new LazyStyle(() =>
648 {
649 var style = new GUIStyle();
650 style.wordWrap = true;
651 style.margin = new RectOffset();
652 style.padding = new RectOffset(4, 4, 2, 2);
653 style.stretchWidth = true;
654 style.stretchHeight = true;
655 style.alignment = TextAnchor.UpperLeft;
656
657 var bg = new Texture2D(1, 1);
658 bg.SetPixel(0, 0, Colors.Red);
659 bg.Apply();
660 style.normal.background = bg;
661 return style;
662 });
663 }
664
665 internal static class DirectoryConflicts
666 {
667 internal readonly static LazyStyle TitleLabel = new LazyStyle(() =>
668 {
669 var style = new GUIStyle(EditorStyles.largeLabel);
670 RectOffset margin = new RectOffset(
671 style.margin.left,
672 style.margin.right,
673 style.margin.top - 1,
674 style.margin.bottom);
675 style.margin = margin;
676 style.fontStyle = FontStyle.Bold;
677 return style;
678 });
679
680 internal readonly static LazyStyle BoldLabel = new LazyStyle(() =>
681 {
682 var style = new GUIStyle(EditorStyles.label);
683 style.fontStyle = FontStyle.Bold;
684 return style;
685 });
686
687 internal readonly static LazyStyle FileNameTextField = new LazyStyle(() =>
688 {
689 var style = new GUIStyle(EditorStyles.textField);
690 RectOffset margin = new RectOffset(
691 style.margin.left,
692 style.margin.right,
693 style.margin.top + 2,
694 style.margin.bottom);
695 style.margin = margin;
696 return style;
697 });
698 }
699
700 internal static readonly LazyStyle ActionToolbar = new LazyStyle(() =>
701 {
702 var style = new GUIStyle(EditorStyles.toolbar);
703 style.fixedHeight = 40f;
704 style.padding = new RectOffset(5, 5, 5, 5);
705 return style;
706 });
707
708 internal static readonly LazyStyle SplitterIndicator = new LazyStyle(() =>
709 {
710 return CreateUnderlineStyle(
711 Colors.Splitter,
712 UnityConstants.SPLITTER_INDICATOR_HEIGHT);
713 });
714
715 internal static readonly LazyStyle HelpBoxLabel = new LazyStyle(() =>
716 {
717 var style = new GUIStyle(EditorStyles.label);
718 style.fontSize = 10;
719 style.wordWrap = true;
720 return style;
721 });
722
723 internal static readonly LazyStyle HeaderWarningLabel
724 = new LazyStyle(() =>
725 {
726 var style = new GUIStyle(EditorStyles.label);
727 style.fontSize = 11;
728 return style;
729 });
730
731 internal static readonly LazyStyle ProgressLabel = new LazyStyle(() =>
732 {
733 var style = new GUIStyle(EditorStyles.label);
734 style.fontSize = 10;
735 return style;
736 });
737
738 internal static readonly LazyStyle TextFieldWithWrapping = new LazyStyle(() =>
739 {
740 var style = new GUIStyle(GetEditorSkin().textArea);
741 style.normal = new GUIStyleState() {
742 textColor = GetEditorSkin().textArea.normal.textColor,
743 background = Images.GetTreeviewBackgroundTexture()
744 };
745
746 style.wordWrap = true;
747 return style;
748 });
749
750 internal static readonly LazyStyle WarningMessage = new LazyStyle(() =>
751 {
752 var style = new GUIStyle(GetEditorSkin().box);
753 style.wordWrap = true;
754 style.margin = new RectOffset();
755 style.padding = new RectOffset(8, 8, 6, 6);
756 style.stretchWidth = true;
757 style.alignment = TextAnchor.UpperLeft;
758
759 var bg = new Texture2D(1, 1);
760 bg.SetPixel(0, 0, Colors.Warning);
761 bg.Apply();
762 style.normal.background = bg;
763 return style;
764 });
765
766 internal static readonly LazyStyle CancelButton = new LazyStyle(() =>
767 {
768 var normalIcon = Images.GetImage(Images.Name.IconCloseButton);
769 var pressedIcon = Images.GetImage(Images.Name.IconPressedCloseButton);
770
771 var style = new GUIStyle();
772 style.normal = new GUIStyleState() { background = normalIcon };
773 style.onActive = new GUIStyleState() { background = pressedIcon };
774 style.active = new GUIStyleState() { background = pressedIcon };
775 return style;
776 });
777
778 internal static readonly LazyStyle MiniToggle = new LazyStyle(() =>
779 {
780 var style = new GUIStyle(EditorStyles.boldLabel);
781 style.fontSize = MODAL_FONT_SIZE - 1;
782 style.clipping = TextClipping.Overflow;
783 return style;
784 });
785
786 internal static readonly LazyStyle Paragraph = new LazyStyle(() =>
787 {
788 var style = new GUIStyle(EditorStyles.largeLabel);
789 style.wordWrap = true;
790 style.richText = true;
791 style.fontSize = MODAL_FONT_SIZE;
792 return style;
793 });
794
795 internal static readonly LazyStyle LinkLabel = new LazyStyle(() =>
796 {
797 var style = new GUIStyle(GUI.skin.label);
798 style.normal.textColor = EditorStyles.linkLabel.normal.textColor;
799 style.hover.textColor = EditorStyles.linkLabel.hover.textColor;
800 style.active.textColor = EditorStyles.linkLabel.active.textColor;
801
802 return style;
803 });
804
805 internal static readonly LazyStyle NoSizeStyle = new LazyStyle(() =>
806 {
807 var style = new GUIStyle();
808 style.margin = new RectOffset(0, 0, 0, 0);
809 style.padding = new RectOffset(0, 0, 0, 0);
810 style.border = new RectOffset(0, 0, 0, 0);
811 style.stretchWidth = false;
812 style.stretchHeight = false;
813 return style;
814 });
815
816 static GUISkin GetEditorSkin()
817 {
818 if (EditorGUIUtility.isProSkin)
819 return EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);
820
821 return EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector);
822 }
823
824 static GUIStyle CreateUnderlineStyle(Color color, int height)
825 {
826 GUIStyle style = new GUIStyle();
827
828 Texture2D pixel = new Texture2D(1, height);
829
830 for (int i = 0; i < height; i++)
831 pixel.SetPixel(0, i, color);
832
833 pixel.wrapMode = TextureWrapMode.Repeat;
834 pixel.Apply();
835
836 style.normal.background = pixel;
837 style.fixedHeight = height;
838
839 return style;
840 }
841
842 static void EnsureBackgroundStyles(LazyStyle lazy)
843 {
844 // The editor cleans the GUIStyleState.background property
845 // when entering the edit mode (exiting the play mode)
846 // and also in other situations (e.g when you use Zoom app)
847 // Because of this, we have to reset them in order to
848 // re-instantiate them the next time they're used
849
850 if (!mLazyBackgroundStyles.Contains(lazy))
851 return;
852
853 bool needsRepaint = false;
854
855 foreach (LazyStyle style in mLazyBackgroundStyles)
856 {
857 if (!style.IsInitialized)
858 continue;
859
860 if (style.Value.normal.background != null)
861 continue;
862
863 style.Reset();
864
865 needsRepaint = true;
866 }
867
868 if (!needsRepaint)
869 return;
870
871 if (mRepaintPlasticWindow != null)
872 mRepaintPlasticWindow();
873 }
874
875 static List<LazyStyle> mLazyBackgroundStyles = new List<LazyStyle>();
876
877 internal class LazyStyle
878 {
879 internal bool IsInitialized { get; private set; }
880
881 internal LazyStyle(Func<GUIStyle> builder)
882 {
883 mBuilder = builder;
884 IsInitialized = false;
885 }
886 internal GUIStyle Value { get; private set; }
887
888 internal void Reset()
889 {
890 IsInitialized = false;
891 }
892
893 // Note: User-defined operator must be declared static and public
894 public static implicit operator GUIStyle(LazyStyle lazy)
895 {
896 if (lazy.IsInitialized)
897 {
898 EnsureBackgroundStyles(lazy);
899 return lazy.Value;
900 }
901
902 lazy.Value = lazy.mBuilder();
903 lazy.IsInitialized = true;
904 return lazy.Value;
905 }
906
907 readonly Func<GUIStyle> mBuilder;
908 }
909
910 static Action mRepaintPlasticWindow;
911
912 const int MODAL_FONT_SIZE = 13;
913 }
914}