Created
January 17, 2019 00:30
-
-
Save pointcache/0517328c69e8118e7f335cc203828878 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class DebugPanel : MonoBehaviour | |
{ | |
private static DebugPanel i; | |
private void Awake() | |
{ | |
i = this; | |
} | |
private struct Message | |
{ | |
public string name; | |
public string value; | |
} | |
private int msgCount = 0; | |
private Message[] messages = new Message[256]; | |
public static void SetMessage(string name, object value) | |
{ | |
i.setmsg(name, value.ToString()); | |
} | |
public static void SetMessage(string name, string value) | |
{ | |
i.setmsg(name, value); | |
} | |
private void setmsg(string name, string value) | |
{ | |
if (!enabled) | |
return; | |
messages[msgCount].name = name; | |
messages[msgCount].value = value; | |
msgCount++; | |
} | |
private void OnGUI() | |
{ | |
Event e = Event.current; | |
int width = 200; | |
int lineHeight = 20; | |
Rect root = new Rect(20, 20, width, lineHeight * (msgCount + 2)); | |
GUI.Box(root, ""); | |
GUILayout.BeginArea(root); | |
GUILayout.Label("Debug Panel"); | |
for (int i = 0; i < msgCount; i++) | |
{ | |
GUILayout.BeginHorizontal(); | |
GUILayout.Label(messages[i].name); | |
GUILayout.Label(messages[i].value); | |
GUILayout.EndHorizontal(); | |
} | |
GUILayout.EndArea(); | |
if(e.type == EventType.Repaint) | |
msgCount = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment