Skip to content

Instantly share code, notes, and snippets.

@pointcache
Created January 17, 2019 00:30
Show Gist options
  • Save pointcache/0517328c69e8118e7f335cc203828878 to your computer and use it in GitHub Desktop.
Save pointcache/0517328c69e8118e7f335cc203828878 to your computer and use it in GitHub Desktop.
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