A game about forced loneliness, made by TACStudios
1using UnityEngine;
2
3namespace UnityEditor.Timeline
4{
5 static class Graphics
6 {
7 public static void ShadowLabel(Rect rect, string text, GUIStyle style, Color textColor, Color shadowColor)
8 {
9 ShadowLabel(rect, GUIContent.Temp(text), style, textColor, shadowColor);
10 }
11
12 public static void ShadowLabel(Rect rect, GUIContent content, GUIStyle style, Color textColor, Color shadowColor)
13 {
14 var shadowRect = rect;
15 shadowRect.xMin += 2.0f;
16 shadowRect.yMin += 2.0f;
17 style.normal.textColor = shadowColor;
18 style.hover.textColor = shadowColor;
19 GUI.Label(shadowRect, content, style);
20
21 style.normal.textColor = textColor;
22 style.hover.textColor = textColor;
23 GUI.Label(rect, content, style);
24 }
25
26 public static void DrawLine(Vector3 p1, Vector3 p2, Color color)
27 {
28 var c = Handles.color;
29 Handles.color = color;
30 Handles.DrawLine(p1, p2);
31 Handles.color = c;
32 }
33
34 public static void DrawPolygonAA(Color color, Vector3[] vertices)
35 {
36 var prevColor = Handles.color;
37 Handles.color = color;
38 Handles.DrawAAConvexPolygon(vertices);
39 Handles.color = prevColor;
40 }
41
42 public static void DrawDottedLine(Vector3 p1, Vector3 p2, float segmentsLength, Color col)
43 {
44 HandleUtility.ApplyWireMaterial();
45
46 GL.Begin(GL.LINES);
47 GL.Color(col);
48
49 var length = Vector3.Distance(p1, p2); // ignore z component
50 var count = Mathf.CeilToInt(length / segmentsLength);
51 for (var i = 0; i < count; i += 2)
52 {
53 GL.Vertex((Vector3.Lerp(p1, p2, i * segmentsLength / length)));
54 GL.Vertex((Vector3.Lerp(p1, p2, (i + 1) * segmentsLength / length)));
55 }
56
57 GL.End();
58 }
59
60 public static void DrawLineAtTime(WindowState state, double time, Color color, bool dotted = false)
61 {
62 var t = state.TimeToPixel(time);
63
64 var p0 = new Vector3(t, state.timeAreaRect.yMax);
65 var p1 = new Vector3(t, state.timeAreaRect.yMax + state.windowHeight - WindowConstants.sliderWidth);
66
67 if (dotted)
68 DrawDottedLine(p0, p1, 4.0f, color);
69 else
70 DrawLine(p0, p1, color);
71 }
72
73 public static void DrawTextureRepeated(Rect area, Texture texture)
74 {
75 if (texture == null || Event.current.type != EventType.Repaint)
76 return;
77
78 GUI.BeginClip(area);
79 int w = Mathf.CeilToInt(area.width / texture.width);
80 int h = Mathf.CeilToInt(area.height / texture.height);
81 for (int x = 0; x < w; x++)
82 {
83 for (int y = 0; y < h; y++)
84 {
85 GUI.DrawTexture(new Rect(x * texture.width, y * texture.height, texture.width, texture.height), texture);
86 }
87 }
88
89 GUI.EndClip();
90 }
91
92 public static void DrawShadow(Rect clientRect)
93 {
94 var rect = clientRect;
95 rect.height = WindowConstants.shadowUnderTimelineHeight;
96 GUI.Box(rect, GUIContent.none, DirectorStyles.Instance.bottomShadow);
97 }
98
99 public static void DrawBackgroundRect(WindowState state, Rect rect, bool subSequenceMode = false)
100 {
101 Color c = subSequenceMode ? DirectorStyles.Instance.customSkin.colorSubSequenceBackground : DirectorStyles.Instance.customSkin.colorSequenceBackground;
102 EditorGUI.DrawRect(rect, c);
103 if (state.IsEditingAPrefabAsset())
104 {
105 c = SceneView.kSceneViewPrefabBackground.Color;
106 c.a = 0.5f;
107 EditorGUI.DrawRect(rect, c);
108 }
109 }
110
111 public static Rect CalculateTextBoxSize(Rect trackRect, GUIStyle font, GUIContent content, float padding)
112 {
113 Rect textRect = trackRect;
114 textRect.width = font.CalcSize(content).x + padding;
115 textRect.x += (trackRect.width - textRect.width) / 2f;
116 textRect.height -= 4f;
117 textRect.y += 2f;
118 return textRect;
119 }
120 }
121}