-
Notifications
You must be signed in to change notification settings - Fork 8
/
Renderer.cs
47 lines (42 loc) · 1.6 KB
/
Renderer.cs
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
using UnityEngine;
namespace UmbraMenu.monsoon
{
public class Renderer
{
public static GUIStyle StringStyle { get; set; } = new GUIStyle(GUI.skin.label);
public static Color Color
{
get { return GUI.color; }
set { GUI.color = value; }
}
public static void DrawLine(Vector2 from, Vector2 to, Color color)
{
Color = color;
DrawLine(from, to);
}
public static void DrawLine(Vector2 from, Vector2 to)
{
var angle = Vector2.SignedAngle(from, to);
GUIUtility.RotateAroundPivot(angle, from);
DrawBox(from, Vector2.right * (from - to).magnitude, false);
GUIUtility.RotateAroundPivot(-angle, from);
}
public static void DrawBox(Vector2 position, Vector2 size, Color color, bool centered = true)
{
Color = color;
DrawBox(position, size, centered);
}
public static void DrawBox(Vector2 position, Vector2 size, bool centered = true)
{
var upperLeft = centered ? position - size / 2f : position;
GUI.DrawTexture(new Rect(upperLeft, size), Texture2D.whiteTexture, ScaleMode.StretchToFill);
}
public static void DrawString(Vector2 position, string label, GUIStyle style, bool centered = true)
{
var content = new GUIContent(label);
var size = StringStyle.CalcSize(content);
var upperLeft = centered ? position - size / 2f : position;
GUI.Label(new Rect(upperLeft, size), content, style);
}
}
}