A game about forced loneliness, made by TACStudios
1using System;
2using UnityEngine;
3
4namespace UnityEditor.Timeline
5{
6 readonly struct OverlayDrawer
7 {
8 enum OverlayType
9 {
10 BackgroundColor,
11 BackgroundTexture,
12 TextBox
13 }
14
15 readonly OverlayType m_Type;
16 readonly Rect m_Rect;
17 readonly string m_Text;
18 readonly Texture2D m_Texture;
19 readonly Color m_Color;
20 readonly GUIStyle m_BackgroundTextStyle;
21 readonly GUIStyle m_TextStyle;
22
23 OverlayDrawer(Rect rectangle, Color backgroundColor)
24 {
25 m_Type = OverlayType.BackgroundColor;
26 m_Rect = rectangle;
27 m_Color = backgroundColor;
28 m_Text = string.Empty;
29 m_Texture = null;
30 m_BackgroundTextStyle = null;
31 m_TextStyle = null;
32 }
33
34 OverlayDrawer(Rect rectangle, Texture2D backTexture)
35 {
36 m_Type = OverlayType.BackgroundTexture;
37 m_Rect = rectangle;
38 m_Color = Color.clear;
39 m_Text = string.Empty;
40 m_Texture = backTexture;
41 m_BackgroundTextStyle = null;
42 m_TextStyle = null;
43 }
44
45 OverlayDrawer(Rect rectangle, string msg, GUIStyle textStyle, Color textColor, Color bgTextColor, GUIStyle bgTextStyle)
46 {
47 m_Type = OverlayType.TextBox;
48 m_Rect = rectangle;
49 m_Text = msg;
50 m_TextStyle = textStyle;
51 m_TextStyle.normal.textColor = textColor;
52 m_BackgroundTextStyle = bgTextStyle;
53 m_BackgroundTextStyle.normal.textColor = bgTextColor;
54 m_Texture = null;
55 m_Color = Color.clear;
56 }
57
58 public static OverlayDrawer CreateColorOverlay(Rect rectangle, Color backgroundColor)
59 {
60 return new OverlayDrawer(rectangle, backgroundColor);
61 }
62
63 public static OverlayDrawer CreateTextureOverlay(Rect rectangle, Texture2D backTexture)
64 {
65 return new OverlayDrawer(rectangle, backTexture);
66 }
67
68 public static OverlayDrawer CreateTextBoxOverlay(Rect rectangle, string msg, GUIStyle textStyle, Color textColor, Color bgTextColor, GUIStyle bgTextStyle)
69 {
70 return new OverlayDrawer(rectangle, msg, textStyle, textColor, bgTextColor, bgTextStyle);
71 }
72
73 public void Draw()
74 {
75 Rect overlayRect = GUIClip.Clip(m_Rect);
76 switch (m_Type)
77 {
78 case OverlayType.BackgroundColor:
79 EditorGUI.DrawRect(overlayRect, m_Color);
80 break;
81 case OverlayType.BackgroundTexture:
82 Graphics.DrawTextureRepeated(overlayRect, m_Texture);
83 break;
84 case OverlayType.TextBox:
85 {
86 using (new GUIColorOverride(m_BackgroundTextStyle.normal.textColor))
87 GUI.Box(overlayRect, GUIContent.none, m_BackgroundTextStyle);
88 Graphics.ShadowLabel(overlayRect, GUIContent.Temp(m_Text), m_TextStyle, m_TextStyle.normal.textColor, Color.black);
89 break;
90 }
91 }
92 }
93 }
94}