I’ve done the same thing except I don’t use icons, but you could easily add them by modifying the MyDebugItem struct. (Example is C#)
In your "global’ class, create a struct(which defines each debug list item) and an ArrayList (our Debug Log) - we overload the method to allow for a title item or title+details items:
//My Debug Log Struct
public struct MyDebugItem
{
public bool ShowDetails;
public string TimeStamp;
public string ItemHeader;
public string ItemDetails;
public MyDebugItem(string mItemHeader, string mItemDetails)
{
this.ShowDetails = false;
this.TimeStamp = DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss");
this.ItemHeader = mItemHeader;
this.ItemDetails = mItemDetails;
}
public MyDebugItem(string mItemHeader)
{
this.ShowDetails = false;
this.TimeStamp = DateTime.Now.ToString("dd-MMM-yyyy HH:mm:ss");
this.ItemHeader = mItemHeader;
this.ItemDetails = "No Additional Information";
}
}
public static ArrayList MyDebugLog = new ArrayList();
To add stuff to the debug log, you have two options (with details or just the title):
MyGlobalScript.MyDebugLog.Add(new MyGlobalScript.MyDebugItem("App Initialized Successfullly"));
MyGlobalScript.MyDebugLog.Add(new MyGlobalScript.MyDebugItem("Data Path", Application.dataPath));
This is the GUI used to display the debug log - mine is also setup for a custom GUISKin so it will probably look strange using the default. However, it does show a nice way to create a collapsable debug log.
using UnityEngine;
using System.Collections;
using System;
public class DebugWindow : MonoBehaviour
{
private Rect DebugWindowPosition;
private Vector2 DebugWindowLogScrollPos;
private bool FocusDebugWindow = false;
void OnGUI()
{
DebugWindowPosition = GUI.Window(1, DebugWindowPosition, DoDebugLogWindow, "My Debug Log");
}
void DoDebugLogWindow(int mWindowID)
{
if (FocusDebugWindow)
{
GUI.BringWindowToFront(mWindowID);
GUI.FocusWindow(mWindowID);
FocusDebugWindow = false;
}
if (GUI.Button(new Rect(284, 10, 16, 16), "", GUI.skin.GetStyle("closebutton16x16"))) ShowDebugWindow = false;
GUILayout.BeginVertical();
GUILayout.Space(25);
DebugWindowLogScrollPos = GUILayout.BeginScrollView(DebugWindowLogScrollPos);
for (int i = 0; i < MyGlobalScript.MyDebugLog.Count; i++)
{
MyGlobalScript.MyDebugItem thisDI = new MyGlobalScript.MyDebugItem();
thisDI = (MyGlobalScript.MyDebugItem)MyGlobalScript.MyDebugLog[i];
if (!thisDI.ShowDetails)
{
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
thisDI.ShowDetails = GUILayout.Toggle(thisDI.ShowDetails, "", GUILayout.Width(28), GUILayout.Height(28));
MyGlobalScript.MyDebugLog[i] = thisDI;
string DebugSummaryItem = thisDI.ItemHeader + ": " + thisDI.ItemDetails;
if (DebugSummaryItem.Length > 32) DebugSummaryItem = DebugSummaryItem.Substring(0, 29) + "...";
GUILayout.Label(DebugSummaryItem, GUILayout.Height(28));
GUILayout.EndHorizontal();
}
else
{
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
thisDI.ShowDetails = GUILayout.Toggle(thisDI.ShowDetails, "", GUILayout.Width(32), GUILayout.Height(28));
MyGlobalScript.MyDebugLog[i] = thisDI;
GUILayout.TextArea(thisDI.TimeStamp + "\n" + thisDI.ItemHeader + "\n" + thisDI.ItemDetails, GUILayout.Width(220));
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
}
GUILayout.EndScrollView();
GUILayout.EndVertical();
GUI.DragWindow();
}
}