-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebugX.cs
89 lines (74 loc) · 3.46 KB
/
DebugX.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
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
// DebugX.cs
// Hayden Scott-Baron (Dock) - http://starfruitgames.com
// Adds a number of useful Debug Draw features
using UnityEngine;
namespace Binocle
{
public class DebugX : MonoBehaviour
{
public static void DrawCube(Vector3 pos, Color col, Vector3 scale)
{
Vector3 halfScale = scale * 0.5f;
Vector3[] points = new Vector3[] {
pos + new Vector3 (halfScale.x, halfScale.y, halfScale.z),
pos + new Vector3 (-halfScale.x, halfScale.y, halfScale.z),
pos + new Vector3 (-halfScale.x, -halfScale.y, halfScale.z),
pos + new Vector3 (halfScale.x, -halfScale.y, halfScale.z),
pos + new Vector3 (halfScale.x, halfScale.y, -halfScale.z),
pos + new Vector3 (-halfScale.x, halfScale.y, -halfScale.z),
pos + new Vector3 (-halfScale.x, -halfScale.y, -halfScale.z),
pos + new Vector3 (halfScale.x, -halfScale.y, -halfScale.z),
};
Debug.DrawLine(points[0], points[1], col);
Debug.DrawLine(points[1], points[2], col);
Debug.DrawLine(points[2], points[3], col);
Debug.DrawLine(points[3], points[0], col);
}
public static void DrawRect(Rect rect, Color col)
{
Vector3 pos = new Vector3(rect.x + rect.width / 2, rect.y + rect.height / 2, 0.0f);
Vector3 scale = new Vector3(rect.width, rect.height, 0.0f);
DebugX.DrawRect(pos, col, scale);
}
public static void DrawRect(Vector3 pos, Color col, Vector3 scale)
{
Vector3 halfScale = scale * 0.5f;
Vector3[] points = new Vector3[] {
pos + new Vector3 (halfScale.x, halfScale.y, halfScale.z),
pos + new Vector3 (-halfScale.x, halfScale.y, halfScale.z),
pos + new Vector3 (-halfScale.x, -halfScale.y, halfScale.z),
pos + new Vector3 (halfScale.x, -halfScale.y, halfScale.z),
};
Debug.DrawLine(points[0], points[1], col);
Debug.DrawLine(points[1], points[2], col);
Debug.DrawLine(points[2], points[3], col);
Debug.DrawLine(points[3], points[0], col);
}
public static void DrawPoint(Vector3 pos, Color col, float scale)
{
Vector3[] points = new Vector3[] {
pos + (Vector3.up * scale),
pos - (Vector3.up * scale),
pos + (Vector3.right * scale),
pos - (Vector3.right * scale),
pos + (Vector3.forward * scale),
pos - (Vector3.forward * scale)
};
Debug.DrawLine(points[0], points[1], col);
Debug.DrawLine(points[2], points[3], col);
Debug.DrawLine(points[4], points[5], col);
Debug.DrawLine(points[0], points[2], col);
Debug.DrawLine(points[0], points[3], col);
Debug.DrawLine(points[0], points[4], col);
Debug.DrawLine(points[0], points[5], col);
Debug.DrawLine(points[1], points[2], col);
Debug.DrawLine(points[1], points[3], col);
Debug.DrawLine(points[1], points[4], col);
Debug.DrawLine(points[1], points[5], col);
Debug.DrawLine(points[4], points[2], col);
Debug.DrawLine(points[4], points[3], col);
Debug.DrawLine(points[5], points[2], col);
Debug.DrawLine(points[5], points[3], col);
}
}
}