1 #region Copyright Notice & License Information
30 using System.Collections.Generic;
51 const int ConsoleLineSpacing = 7;
55 const int ConsoleMaxDisplayedLines = 24;
59 const int ConsoleMaxLines = 10000;
63 const int ConsolePadding = 5;
68 const string ConsoleUnityPrefix =
"[h] ";
72 const string ShaderText =
"Shader \"hDebug/Text\"\r\n{\r\nProperties\r\n{\r\n_MainTex (\"Main\", 2D) = \"white\" {}\r\n}\r\n\r\nCategory\r\n{\r\n Tags\r\n {\r\n \"Queue\" = \"Transparent\"\r\n }\r\n \r\n Blend SrcAlpha OneMinusSrcAlpha\r\n AlphaTest Greater .01\r\n ColorMask RGB\r\n Cull Off\r\n Lighting Off\r\n ZWrite On\r\n \r\n Fog\r\n {\r\n Color(0, 0, 0, 0)\r\n }\r\n \r\n BindChannels\r\n {\r\n Bind \"Color\", color\r\n Bind \"Vertex\", vertex\r\n Bind \"TexCoord\", texcoord\r\n }\r\n \r\n SubShader\r\n {\r\n Pass\r\n {\r\n SetTexture [_MainTex]\r\n {\r\n combine texture * primary\r\n }\r\n }\r\n }\r\n}\r\n}";
76 const int StatsPadding = 10;
80 const int StatsLineSpacing = 7;
111 static readonly System.Object _syncRoot =
new System.Object ();
115 static volatile hDebug _staticInstance;
116 public static Color
Shadow = Color.black;
118 static readonly
char[] _newLineCharacters =
new char[] {
'\n',
'\r' };
123 static readonly byte[] _fontImageData = {
124 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52,
125 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x80, 0x01, 0x03, 0x00, 0x00, 0x00, 0xF9, 0xF0, 0xF3,
126 0x88, 0x00, 0x00, 0x00, 0x06, 0x50, 0x4C, 0x54, 0x45, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x55,
127 0x7C, 0xF5, 0x6C, 0x00, 0x00, 0x00, 0x01, 0x74, 0x52, 0x4E, 0x53, 0x00, 0x40, 0xE6, 0xD8, 0x66,
128 0x00, 0x00, 0x02, 0x15, 0x49, 0x44, 0x41, 0x54, 0x78, 0x5E, 0xED, 0xD2, 0x41, 0x8A, 0xD5, 0x40,
129 0x10, 0x06, 0xE0, 0x5A, 0xF5, 0xAA, 0x70, 0x5D, 0x60, 0x78, 0x27, 0x70, 0x51, 0x30, 0x12, 0x1F,
130 0x4C, 0x91, 0x8B, 0xB8, 0x29, 0x18, 0xF8, 0x5D, 0xBC, 0xF0, 0x66, 0x44, 0x18, 0x03, 0x36, 0xFD,
131 0x6E, 0xE0, 0x99, 0x04, 0x0F, 0xE0, 0x56, 0x9C, 0x4B, 0x78, 0x03, 0xAD, 0xEE, 0x24, 0x4E, 0x66,
132 0x46, 0x17, 0xCA, 0x2C, 0x5C, 0xCC, 0xBF, 0xC8, 0xE2, 0xE3, 0x4F, 0x77, 0x85, 0x0A, 0xFD, 0x2E,
133 0xF2, 0x00, 0xAE, 0xB6, 0x20, 0xE8, 0xED, 0xEB, 0x5E, 0x58, 0x1B, 0xA4, 0x1D, 0x19, 0x7A, 0x7C,
134 0x1B, 0x45, 0x64, 0x86, 0xB3, 0x80, 0x93, 0x5F, 0x57, 0xE8, 0x2B, 0xF1, 0x2B, 0x32, 0xEA, 0x95,
135 0xF7, 0xA4, 0xDC, 0x2D, 0x20, 0xD4, 0x8B, 0x78, 0xC0, 0xA9, 0x50, 0x21, 0x39, 0xAB, 0xC0, 0x7A,
136 0xB9, 0x36, 0xE4, 0x3C, 0x1E, 0xA7, 0x74, 0x44, 0x40, 0x3B, 0x43, 0xCF, 0x6B, 0x03, 0xAF, 0x2B,
137 0x10, 0x75, 0xD4, 0x69, 0x7B, 0xC5, 0x9E, 0x87, 0x4B, 0x03, 0xDF, 0x51, 0x44, 0x9E, 0x51, 0x83,
138 0x28, 0xF9, 0xAF, 0x6F, 0x61, 0x0D, 0xA4, 0xC7, 0x0A, 0x9B, 0x69, 0xE9, 0x8A, 0x19, 0x51, 0x22,
139 0xB7, 0x42, 0x1D, 0xA0, 0x2E, 0x09, 0xA8, 0xD7, 0x2A, 0x3E, 0x53, 0x06, 0x7A, 0x57, 0x06, 0xBA,
140 0x4E, 0x48, 0x02, 0x38, 0xA5, 0xDE, 0x33, 0x5F, 0x07, 0x68, 0x61, 0xFE, 0x42, 0xCC, 0x5D, 0x9F,
141 0x21, 0x86, 0x3A, 0x66, 0x92, 0x1B, 0x62, 0x49, 0x48, 0x90, 0xE3, 0x40, 0x14, 0x8D, 0x0A, 0x8A,
142 0x53, 0x82, 0x82, 0xEB, 0xE8, 0x42, 0xF1, 0x8A, 0x23, 0x71, 0x80, 0x74, 0x1D, 0x93, 0xCA, 0x27,
143 0xE2, 0x62, 0x69, 0x32, 0xB5, 0x7D, 0xD7, 0x25, 0x72, 0x39, 0x6D, 0x47, 0x7C, 0xB8, 0xD1, 0x47,
144 0x8B, 0x64, 0x9B, 0x4A, 0x31, 0x58, 0x82, 0x5F, 0x5C, 0x58, 0x26, 0x03, 0x46, 0x77, 0x40, 0x1A,
145 0x00, 0x84, 0xC8, 0x0C, 0xA3, 0xBF, 0x7F, 0xD7, 0xC0, 0x03, 0xBC, 0xC1, 0xE1, 0x43, 0x85, 0xEC,
146 0xC8, 0xD9, 0x8B, 0xA4, 0xC9, 0x0F, 0x97, 0xC8, 0x54, 0x5A, 0xE3, 0x38, 0x37, 0xDE, 0xC0, 0x6F,
147 0xCF, 0xC0, 0x18, 0x87, 0xCE, 0x30, 0xCE, 0x80, 0x05, 0xEA, 0x1C, 0x3E, 0xC0, 0x0C, 0x25, 0xE6,
148 0x70, 0x7A, 0xF4, 0x08, 0xED, 0xEF, 0x82, 0x05, 0x59, 0xB6, 0x02, 0x5C, 0x00, 0xC5, 0xDC, 0x40,
149 0x4C, 0x00, 0xA4, 0x41, 0x52, 0x67, 0x8A, 0x00, 0x5E, 0xE1, 0x65, 0x80, 0x2E, 0xA0, 0x01, 0x07,
150 0x01, 0xAF, 0x90, 0xA5, 0x81, 0x89, 0xCA, 0x0C, 0x23, 0x57, 0x78, 0x21, 0xBA, 0x02, 0x52, 0x40,
151 0x0F, 0x71, 0xE5, 0x05, 0x20, 0xB0, 0x0D, 0x18, 0x4C, 0x4C, 0x02, 0x8A, 0x26, 0xBE, 0xBB, 0xF3,
152 0x05, 0xD2, 0x2D, 0x10, 0xDF, 0xFF, 0x10, 0xA3, 0x1F, 0xF4, 0x17, 0x11, 0x5E, 0xC1, 0x29, 0xD1,
153 0x8E, 0x5C, 0xD8, 0xA7, 0x5B, 0xD0, 0xE0, 0xB0, 0x06, 0x96, 0x6D, 0x30, 0x1D, 0xF2, 0x64, 0x90,
154 0x92, 0x2D, 0x53, 0x42, 0x44, 0x01, 0x61, 0xC8, 0x01, 0x40, 0x80, 0x03, 0xA5, 0xC2, 0x38, 0xC3,
155 0x10, 0x50, 0x5A, 0x63, 0x9A, 0x01, 0x01, 0xAE, 0x9B, 0x06, 0x22, 0xBE, 0x3D, 0x63, 0x98, 0x6F,
156 0x41, 0xE1, 0xD8, 0x3E, 0x2C, 0xD3, 0x9C, 0xB4, 0xFE, 0xFB, 0xFE, 0x27, 0x88, 0xE6, 0xB4, 0xC0,
157 0xBF, 0x45, 0x67, 0x60, 0xD1, 0xB7, 0x77, 0x40, 0x44, 0x6E, 0x02, 0x06, 0x0C, 0xCB, 0xFF, 0x11,
158 0xF0, 0x31, 0x00, 0x47, 0x57, 0xE0, 0x00, 0xA4, 0x00, 0xAA, 0x70, 0xD5, 0xC0, 0xC0, 0xEB, 0xB2,
159 0xDD, 0x2A, 0x08, 0xC4, 0x25, 0xCD, 0x90, 0xE6, 0x86, 0xD6, 0xC6, 0x0A, 0xD6, 0x03, 0xBE, 0x9C,
160 0x31, 0x78, 0xDE, 0x0D, 0xD2, 0xC3, 0x4A, 0xC0, 0x76, 0xD9, 0x4C, 0xF7, 0x40, 0xEA, 0xA4, 0x5B,
161 0xF8, 0x5E, 0xED, 0xBF, 0xC8, 0x53, 0x9E, 0xF2, 0x13, 0xCE, 0xA7, 0xD4, 0x2D, 0x81, 0x1E, 0xBF,
162 0x8C, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82
164 static readonly Color _logBackgroundColor =
new Color (0.1337f, 0.1337f, 0.1337f, 0.95f);
165 static readonly List<hDebug.LogMessage> _logMessages =
new List<hDebug.LogMessage> ();
166 static readonly Color[] _logTypeColors = {
167 Hydrogen.Texture.ToColor (Hydrogen.Texture.WebColor.Red, 0.95f),
168 Hydrogen.Texture.ToColor (Hydrogen.Texture.WebColor.Crimson, 0.95f),
169 Hydrogen.Texture.ToColor (Hydrogen.Texture.WebColor.Orange, 0.95f),
170 Hydrogen.Texture.ToColor (Hydrogen.Texture.WebColor.White, 0.95f),
171 Hydrogen.Texture.ToColor (Hydrogen.Texture.WebColor.FireBrick, 0.95f),
173 static readonly List<hDebug.PrintedText> _printedText =
new List<hDebug.PrintedText> ();
174 static readonly Color _statsBackgroundColor =
new Color (0.1337f, 0.1337f, 0.1337f, 0.95f);
175 static readonly Color _statsForegroundColor =
new Color (1f, 1f, 1f, 0.95f);
176 static readonly Dictionary<string, WatchedItem> _watchedItems =
new Dictionary<string, WatchedItem> ();
177 static int _debugLogCount;
179 Texture2D _fontImage;
180 Material _fontMaterial;
184 float[] _glyphBottom;
187 int _watchWidth = 100;
188 int _consoleHeight = 382;
189 hDebug.UVRectangle _whiteUV;
212 if (_staticInstance == null) {
214 _staticInstance = FindObjectOfType (typeof(
hDebug)) as
hDebug;
217 if (_staticInstance == null) {
218 var go = GameObject.Find (Hydrogen.Components.DefaultSingletonName) ??
219 new GameObject (Hydrogen.Components.DefaultSingletonName);
221 go.AddComponent<hDebug> ();
222 _staticInstance = go.GetComponent<hDebug> ();
226 return _staticInstance;
231 get {
return _consoleHeight; }
232 set { _consoleHeight = value; }
240 return _staticInstance != null;
243 public static void Error (
object obj)
245 hDebug.PushLog (obj.ToString (), LogType.Error);
248 public static void Error (
string text)
250 hDebug.PushLog (text, LogType.Error);
253 public static void Error (
string text, params
object[] args)
255 hDebug.PushLog (string.Format (text, args), LogType.Error);
260 var foundConsole = FindObjectOfType (typeof(
hDebug)) as
hDebug;
261 if (foundConsole == null) {
262 var go = GameObject.Find (Hydrogen.Components.DefaultSingletonName) ??
263 new GameObject (Hydrogen.Components.DefaultSingletonName);
264 go.AddComponent<hDebug> ();
265 _staticInstance = go.GetComponent<hDebug> ();
269 public static void Log (
object obj)
271 hDebug.PushLog (obj.ToString (), LogType.Log);
274 public static void Log (
string text)
276 hDebug.PushLog (text, LogType.Log);
279 public static void Log (
string text, params
object[] args)
281 hDebug.PushLog (string.Format (text, args), LogType.Log);
284 public static void Print (
int x,
int y,
object obj)
286 hDebug._printedText.Add (
new hDebug.PrintedText (obj.ToString (), x, y, Color.white));
289 public static void Print (
int x,
int y,
string text)
291 hDebug._printedText.Add (
new hDebug.PrintedText (text, x, y, Color.white));
294 public static void Print (
int x,
int y,
string text, params
object[] args)
296 hDebug._printedText.Add (
new hDebug.PrintedText (string.Format (text, args), x, y, Color.white));
299 public static void Print (
int x,
int y, Color color,
object obj)
301 hDebug._printedText.Add (
new hDebug.PrintedText (obj.ToString (), x, y, color));
304 public static void Print (
int x,
int y, Color color,
string text)
306 hDebug._printedText.Add (
new hDebug.PrintedText (text, x, y, color));
309 public static void Print (
int x,
int y, Color color,
string text, params
object[] args)
311 hDebug._printedText.Add (
new hDebug.PrintedText (string.Format (text, args), x, y, color));
314 public static void Warn (
object obj)
316 hDebug.PushLog (obj.ToString (), LogType.Warning);
319 public static void Warn (
string text)
321 hDebug.PushLog (text, LogType.Warning);
324 public static void Warn (
string text, params
object[] args)
326 hDebug.PushLog (string.Format (text, args), LogType.Warning);
329 public static void Watch (
string key,
bool value)
331 if (_watchedItems.ContainsKey (key) && _watchedItems [key].Type == WatchedItem.ItemType.Boolean) {
332 _watchedItems [key].Data = value.ToString ();
339 public static void Watch (
string key,
string value)
341 if (_watchedItems.ContainsKey (key) && _watchedItems [key].Type == WatchedItem.ItemType.String) {
342 _watchedItems [key].Data = value;
348 public static void Watch (
string key,
int value)
350 if (_watchedItems.ContainsKey (key) && _watchedItems [key].Type == WatchedItem.ItemType.Integer) {
351 _watchedItems [key].Data = value.ToString ();
357 public static void Watch (
string key,
float value)
359 if (_watchedItems.ContainsKey (key) && _watchedItems [key].Type == WatchedItem.ItemType.Float) {
360 _watchedItems [key].Data = value.ToString ();
368 if (_watchedItems.ContainsKey (key))
369 _watchedItems.Remove (key);
372 static void PushLog (
string text, LogType type)
376 if (text.Substring (0, ConsoleUnityPrefix.Length) == ConsoleUnityPrefix)
381 case LogType.Exception:
383 Debug.LogError (ConsoleUnityPrefix + text);
385 case LogType.Warning:
386 Debug.LogWarning (ConsoleUnityPrefix + text);
389 Debug.Log (ConsoleUnityPrefix + text);
394 if (
hDebug._logMessages.Count >= ConsoleMaxLines) {
395 hDebug._logMessages.RemoveAt (0);
398 foreach (var lineItem
in text.Split (_newLineCharacters)) {
399 hDebug._logMessages.Add (
400 new hDebug.LogMessage (
401 "[" + Time.time.ToString ().PadRight (9,
'0') +
"] " + lineItem, type));
402 hDebug._debugLogCount++;
411 Application.RegisterLogCallback (
new Application.LogCallback (HandleException));
420 static void HandleException (
string condition,
string stackTrace, LogType type)
424 hDebug.PushLog (stackTrace, LogType.Error);
425 hDebug.PushLog (condition, LogType.Error);
427 case LogType.Exception:
428 hDebug.PushLog (stackTrace, LogType.Exception);
429 hDebug.PushLog (condition, LogType.Exception);
432 hDebug.PushLog (condition, type);
444 _fontMaterial.SetPass (0);
445 GL.LoadPixelMatrix ();
448 foreach (
hDebug.PrintedText current in
hDebug._printedText) {
449 PrintString (current.Text, current.X, current.Y, current.Color);
453 int itemCount = _watchedItems.Count;
454 int watchHeight = (itemCount *
GlyphHeight) + (itemCount * StatsLineSpacing) + (StatsPadding * 2);
455 int lineOffset = StatsPadding;
456 int lastFrameWidth = _watchWidth;
460 SolidQuad (0, 0, 92, 50, _statsBackgroundColor);
463 PrintString ((1 / Time.smoothDeltaTime).ToString (
"#,##0.00") +
" FPS", 10, 10, _statsForegroundColor);
466 PrintString (
string.Format (
"{0:#,##0.00} MB", (System.GC.GetTotalMemory (
true) / 1048576f)), 10, 25, _statsForegroundColor);
470 if (_watchedItems.Count > 0)
471 SolidQuad (Screen.width - lastFrameWidth, 0, Screen.width, watchHeight, _statsBackgroundColor);
474 foreach (KeyValuePair<string, WatchedItem> entry
in _watchedItems) {
477 if (entry.Value.OutputPaddedSize > _watchWidth) {
478 _watchWidth = entry.Value.OutputPaddedSize;
482 PrintString (entry.Value.Output, Screen.width - lastFrameWidth + StatsPadding, lineOffset, _statsForegroundColor);
489 SolidQuad (0, Screen.height - 50, 92, Screen.height, _statsBackgroundColor);
492 PrintString ((1 / Time.smoothDeltaTime).ToString (
"#,##0.00") +
" FPS", 10, Screen.height - 40, _statsForegroundColor);
495 PrintString (
string.Format (
"{0:#,##0.00} MB", (System.GC.GetTotalMemory (
true) / 1048576f)), 10, Screen.height - 25, _statsForegroundColor);
498 lineOffset = Screen.height - watchHeight + StatsPadding;
501 if (_watchedItems.Count > 0)
502 SolidQuad (Screen.width - lastFrameWidth, Screen.height - watchHeight, Screen.width, Screen.height, _statsBackgroundColor);
505 foreach (KeyValuePair<string, WatchedItem> entry
in _watchedItems) {
508 if (entry.Value.OutputPaddedSize > _watchWidth) {
509 _watchWidth = entry.Value.OutputPaddedSize;
513 PrintString (entry.Value.Output, Screen.width - lastFrameWidth + StatsPadding, lineOffset, _statsForegroundColor);
522 if (
hDebug._logMessages.Count < ConsoleMaxDisplayedLines) {
526 ConsoleHeight = (ConsolePadding * 2) + (15 * ConsoleMaxDisplayedLines) - 1;
530 int num = ConsolePadding;
531 int num2 = hDebug._logMessages.Count - _logOffsetV;
532 if (num2 >
hDebug._debugLogCount) {
533 num2 = hDebug._debugLogCount;
535 if (num2 < ConsoleMaxDisplayedLines) {
536 num2 = ConsoleMaxDisplayedLines;
539 int num3 = num2 - ConsoleMaxDisplayedLines;
545 SolidQuad (0f, -4f, (
float)Screen.width,
ConsoleHeight, _logBackgroundColor);
547 for (
int i = num3; i < num2; i++) {
548 if (i >= 0 && i <
hDebug._logMessages.Count) {
549 hDebug.LogMessage logMessage = hDebug._logMessages [i];
550 PrintString (logMessage.Message, ConsolePadding + (_logOffsetH * 8), num, _logTypeColors [(
int)logMessage.Type]);
555 string text = string.Format (
"{0}-{1}", num3, num2);
556 PrintString (text, Screen.width - ConsolePadding - (text.Length * 8), ConsolePadding, Color.gray);
558 SolidQuad (0f, Screen.height -
ConsoleHeight, (
float)Screen.width, Screen.height + 4, _logBackgroundColor);
561 for (
int i = num3; i < num2; i++) {
562 if (i >= 0 && i <
hDebug._logMessages.Count) {
563 hDebug.LogMessage logMessage = hDebug._logMessages [i];
564 PrintString (logMessage.Message, ConsolePadding + _logOffsetH * 8, num, _logTypeColors [(
int)logMessage.Type]);
568 string text = string.Format (
"{0}-{1}", num3, num2);
570 PrintString (text, Screen.width - ConsolePadding - (text.Length * 8), (Screen.height -
ConsoleHeight) + ConsolePadding, Color.gray);
576 hDebug._printedText.Clear ();
580 void PrintString (
string text,
int x,
int y, Color colour)
583 for (
int i = 0; i < text.Length; i++) {
589 if (num2 < 33 || num2 > 127) {
593 float num3 = (float)num;
595 int num5 = Screen.height - y;
596 int num6 = Screen.height - (y + 15);
598 GL.Color (Color.black);
599 GL.TexCoord2 (_glyphLeft [num2], _glyphBottom [num2]);
600 GL.Vertex3 (num3, (float)num6, 0f);
601 GL.Color (Color.black);
602 GL.TexCoord2 (_glyphLeft [num2], _glyphTop [num2]);
603 GL.Vertex3 (num3, (float)num5, 0f);
604 GL.Color (Color.black);
605 GL.TexCoord2 (_glyphRight [num2], _glyphTop [num2]);
606 GL.Vertex3 ((float)num4, (
float)num5, 0f);
607 GL.Color (Color.black);
608 GL.TexCoord2 (_glyphLeft [num2], _glyphBottom [num2]);
609 GL.Vertex3 (num3, (
float)num6, 0f);
610 GL.Color (Color.black);
611 GL.TexCoord2 (_glyphRight [num2], _glyphTop [num2]);
612 GL.Vertex3 ((
float)num4, (
float)num5, 0f);
613 GL.Color (Color.black);
614 GL.TexCoord2 (_glyphRight [num2], _glyphBottom [num2]);
615 GL.Vertex3 ((
float)num4, (
float)num6, 0f);
616 GL.Color (Color.white);
617 GL.TexCoord2 (_glyphLeft [num2], _glyphBottom [num2]);
618 GL.Vertex3 (num3 - 1f, (
float)(num6 + 1), 0f);
619 GL.Color (Color.white);
620 GL.TexCoord2 (_glyphLeft [num2], _glyphTop [num2]);
621 GL.Vertex3 (num3 - 1f, (
float)(num5 + 1), 0f);
622 GL.Color (Color.white);
623 GL.TexCoord2 (_glyphRight [num2], _glyphTop [num2]);
624 GL.Vertex3 ((
float)(num4 - 1), (
float)(num5 + 1), 0f);
625 GL.Color (Color.white);
626 GL.TexCoord2 (_glyphLeft [num2], _glyphBottom [num2]);
627 GL.Vertex3 (num3 - 1f, (
float)(num6 + 1), 0f);
628 GL.Color (Color.white);
629 GL.TexCoord2 (_glyphRight [num2], _glyphTop [num2]);
630 GL.Vertex3 ((
float)(num4 - 1), (
float)(num5 + 1), 0f);
631 GL.Color (Color.white);
632 GL.TexCoord2 (_glyphRight [num2], _glyphBottom [num2]);
633 GL.Vertex3 ((
float)(num4 - 1), (
float)(num6 + 1), 0f);
636 GL.TexCoord2 (_glyphLeft [num2], _glyphBottom [num2]);
637 GL.Vertex3 (num3, (float)num6, 0f);
639 GL.TexCoord2 (_glyphLeft [num2], _glyphTop [num2]);
640 GL.Vertex3 (num3, (float)num5, 0f);
642 GL.TexCoord2 (_glyphRight [num2], _glyphTop [num2]);
643 GL.Vertex3 ((float)num4, (
float)num5, 0f);
645 GL.TexCoord2 (_glyphLeft [num2], _glyphBottom [num2]);
646 GL.Vertex3 (num3, (
float)num6, 0f);
648 GL.TexCoord2 (_glyphRight [num2], _glyphTop [num2]);
649 GL.Vertex3 ((
float)num4, (
float)num5, 0f);
651 GL.TexCoord2 (_glyphRight [num2], _glyphBottom [num2]);
652 GL.Vertex3 ((
float)num4, (
float)num6, 0f);
659 void SolidQuad (
float left,
float top,
float right,
float bottom, Color color)
661 top = (float)Screen.height - top;
662 bottom = (
float)Screen.height - bottom;
664 GL.TexCoord2 (_whiteUV.U0, _whiteUV.V0);
665 GL.Vertex3 (left, bottom, 0f);
667 GL.TexCoord2 (_whiteUV.U0, _whiteUV.V0);
668 GL.Vertex3 (left, top, 0f);
670 GL.TexCoord2 (_whiteUV.U0, _whiteUV.V0);
671 GL.Vertex3 (right, top, 0f);
673 GL.TexCoord2 (_whiteUV.U0, _whiteUV.V0);
674 GL.Vertex3 (left, bottom, 0f);
676 GL.TexCoord2 (_whiteUV.U0, _whiteUV.V0);
677 GL.Vertex3 (right, top, 0f);
679 GL.TexCoord2 (_whiteUV.U0, _whiteUV.V0);
680 GL.Vertex3 (right, bottom, 0f);
685 _fontImage =
new Texture2D (128, 128);
686 _fontImage.LoadImage (_fontImageData);
687 _fontImage.filterMode = 0;
688 _fontImage.wrapMode = (TextureWrapMode)1;
689 _fontImage.hideFlags = (HideFlags)13;
690 var material =
new Material (
"Shader \"hDebug/Text\"\r\n {\r\n Properties\r\n {\r\n _MainTex (\"Main\", 2D) = \"white\" {}\r\n }\r\n \r\n Category\r\n {\r\n Tags\r\n {\r\n \"Queue\" = \"Transparent\"\r\n }\r\n \r\n Blend SrcAlpha OneMinusSrcAlpha\r\n AlphaTest Greater .01\r\n ColorMask RGB\r\n Cull Off\r\n Lighting Off\r\n ZWrite On\r\n \r\n Fog\r\n {\r\n Color(0, 0, 0, 0)\r\n }\r\n \r\n BindChannels\r\n {\r\n Bind \"Color\", color\r\n Bind \"Vertex\", vertex\r\n Bind \"TexCoord\", texcoord\r\n }\r\n \r\n SubShader\r\n {\r\n Pass\r\n {\r\n SetTexture [_MainTex]\r\n {\r\n combine texture * primary\r\n }\r\n }\r\n }\r\n }\r\n }");
691 material.mainTexture = _fontImage;
692 material.hideFlags = (HideFlags)13;
693 material.shader.hideFlags = (HideFlags)13;
694 _fontMaterial = material;
695 _fontCamera = (Camera)gameObject.AddComponent (
"Camera");
696 _fontCamera.nearClipPlane = 0.1f;
697 _fontCamera.farClipPlane = 1f;
698 _fontCamera.clearFlags = (CameraClearFlags)4;
699 _fontCamera.depth = 99f;
700 _fontCamera.cullingMask = 0;
701 _fontCamera.useOcclusionCulling =
false;
702 _fontCamera.isOrthoGraphic =
true;
703 _glyphLeft =
new float[94];
704 _glyphTop =
new float[94];
705 _glyphRight =
new float[94];
706 _glyphBottom =
new float[94];
709 int width = _fontImage.width;
710 float num3 = 1f / (float)_fontImage.width;
711 float num4 = 1f / (
float)_fontImage.height;
712 for (
int i = 0; i < 94; i++) {
713 _glyphLeft [i] = (float)num;
714 _glyphTop [i] = (float)num2;
715 _glyphRight [i] = (float)(num + 8);
716 _glyphBottom [i] = (float)(num2 + 15);
717 _glyphLeft [i] *= num3;
718 _glyphRight [i] *= num3;
719 _glyphTop [i] *= num4;
720 _glyphBottom [i] *= num4;
721 _glyphTop [i] = 1f - _glyphTop [i];
722 _glyphBottom [i] = 1f - _glyphBottom [i];
729 _whiteUV = hDebug.UVRectangle.CreateFromTexture (3, 5, 1, 1, _fontImage.width, _fontImage.height);
736 case DisplayMode.Off:
737 Mode = DisplayMode.Stats;
739 case DisplayMode.Stats:
740 Mode = DisplayMode.Console;
742 case DisplayMode.Console:
743 Mode = DisplayMode.Off;
750 _logOffsetV += ConsoleMaxDisplayedLines;
751 int num = hDebug._logMessages.Count - ConsoleMaxDisplayedLines;
752 if (_logOffsetV > num) {
759 _logOffsetV -= ConsoleMaxDisplayedLines;
760 if (_logOffsetV < 0) {
788 if ((Input.GetKey (KeyCode.LeftShift) || Input.GetKey (KeyCode.RightShift)) && Input.GetKeyDown (
ToggleKey)) {
789 Mode = DisplayMode.Console;
799 if (Input.GetKeyDown (KeyCode.UpArrow)) {
801 }
else if (Input.GetKeyDown (KeyCode.DownArrow)) {
803 }
else if (Input.GetKey (KeyCode.RightArrow)) {
805 }
else if (Input.GetKey (KeyCode.LeftArrow)) {
813 public readonly Color Color;
814 public readonly
string Text;
815 public readonly
int X;
816 public readonly
int Y;
818 public PrintedText (
string text,
int x,
int y, Color color)
834 public UVRectangle (
float u0,
float v0,
float u1,
float v1)
842 public static hDebug.UVRectangle CreateFromTexture (
int left,
int top,
int width,
int height,
int sourceWidth,
int sourceHeight)
844 float num = 1f / (float)sourceWidth;
845 float num2 = 1f / (float)sourceHeight;
846 return new hDebug.UVRectangle {
847 U0 = (float)left * num,
848 V0 = 1f - (
float)top * num2,
849 U1 = (float)(left + width) * num,
850 V1 = 1f - (float)(top + height) * num2
889 get {
return _data; }
891 if (_data != value) {
915 public readonly
string Message;
919 public readonly LogType Type;
926 public LogMessage (
string message, LogType type)
static bool Exists()
Does the Console already exist?
ItemType Type
What type of item is the data "supposed" to be, as it is stored as a string for output purposes...
static void Print(int x, int y, string text)
static void Warn(object obj)
const int GlyphHeight
Height of a character from our fontImage.
static void Log(object obj)
static void Error(object obj)
static void Warn(string text, params object[] args)
static void Watch(string key, float value)
static void Print(int x, int y, object obj)
static bool EchoToUnityLog
static hDebug Instance
Gets the console instance, creating one if none is found.
static void Print(int x, int y, Color color, string text, params object[] args)
static void Print(int x, int y, string text, params object[] args)
string Key
The index used to store this WatchedItem in the WatchedItems dictionary.
static void Log(string text, params object[] args)
KeyCode ToggleKey
What key should be used to toggle between modes.
DisplayMode Mode
What should be displayed? Stats or Console?
WatchedItem(ItemType type, string key, string data)
static void Watch(string key, string value)
An in-game debugging system to make every developer happy.
static void Error(string text, params object[] args)
static void Print(int x, int y, Color color, string text)
const int GlyphWidth
Width of a character from our fontImage.
static void UnWatch(string key)
static void Watch(string key, int value)
static void Warn(string text)
static void Error(string text)
static void Log(string text)
static void Watch(string key, bool value)
bool CheckForInput
Should we monitor for input?
DisplayLocation Location
Where should the console be displayed on the screen.
static void Print(int x, int y, Color color, object obj)