-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathNGUIDebug.cs
103 lines (93 loc) · 2.19 KB
/
NGUIDebug.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System.Collections.Generic;
using UnityEngine;
[AddComponentMenu("NGUI/Internal/Debug")]
public class NGUIDebug : MonoBehaviour
{
private static bool mRayDebug = false;
private static List<string> mLines = new List<string>();
private static NGUIDebug mInstance = null;
public static bool debugRaycast
{
get
{
return mRayDebug;
}
set
{
if (Application.isPlaying)
{
mRayDebug = value;
if (value)
{
CreateInstance();
}
}
}
}
public static void CreateInstance()
{
if (mInstance == null)
{
GameObject gameObject = new GameObject("_NGUI Debug");
mInstance = gameObject.AddComponent<NGUIDebug>();
Object.DontDestroyOnLoad(gameObject);
}
}
private static void LogString(string text)
{
if (Application.isPlaying)
{
if (mLines.Count > 20)
{
mLines.RemoveAt(0);
}
mLines.Add(text);
CreateInstance();
}
else
{
Debug.Log(text);
}
}
public static void Log(params object[] objs)
{
string text = string.Empty;
for (int i = 0; i < objs.Length; i++)
{
text = ((i != 0) ? (text + ", " + objs[i].ToString()) : (text + objs[i].ToString()));
}
LogString(text);
}
public static void Clear()
{
mLines.Clear();
}
public static void DrawBounds(Bounds b)
{
Vector3 center = b.center;
Vector3 vector = b.center - b.extents;
Vector3 vector2 = b.center + b.extents;
Debug.DrawLine(new Vector3(vector.x, vector.y, center.z), new Vector3(vector2.x, vector.y, center.z), Color.red);
Debug.DrawLine(new Vector3(vector.x, vector.y, center.z), new Vector3(vector.x, vector2.y, center.z), Color.red);
Debug.DrawLine(new Vector3(vector2.x, vector.y, center.z), new Vector3(vector2.x, vector2.y, center.z), Color.red);
Debug.DrawLine(new Vector3(vector.x, vector2.y, center.z), new Vector3(vector2.x, vector2.y, center.z), Color.red);
}
private void OnGUI()
{
if (mLines.Count == 0)
{
if (mRayDebug && UICamera.hoveredObject != null && Application.isPlaying)
{
GUILayout.Label("Last Hit: " + NGUITools.GetHierarchy(UICamera.hoveredObject).Replace("\"", string.Empty));
}
}
else
{
int i = 0;
for (int count = mLines.Count; i < count; i++)
{
GUILayout.Label(mLines[i]);
}
}
}
}