43 lines
1.3 KiB
C#
43 lines
1.3 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class LogGUI : MonoBehaviour
|
|
{
|
|
private string _log = string.Empty;
|
|
private readonly Dictionary<string, ValueWrapper<int>> _trackedInt = new Dictionary<string, ValueWrapper<int>>();
|
|
private readonly Dictionary<string, ValueWrapper<float>> _trackedFloat = new Dictionary<string, ValueWrapper<float>>(10);
|
|
|
|
public void Log(object message)
|
|
{
|
|
_log += message;
|
|
}
|
|
|
|
public void Track<T>(object message, ValueWrapper<T> target)
|
|
{
|
|
if (target is ValueWrapper<int> intValue)
|
|
_trackedInt.Add(message.ToString(), intValue);
|
|
else if (target is ValueWrapper<float> floatValue)
|
|
_trackedFloat.Add(message.ToString(), floatValue);
|
|
else
|
|
return;
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
GUILayout.Label(_log, GetStyle());
|
|
|
|
foreach (KeyValuePair<string, ValueWrapper<int>> item in _trackedInt)
|
|
GUILayout.Label($"{item.Key} {item.Value.Value}", GetStyle());
|
|
|
|
foreach (KeyValuePair<string, ValueWrapper<float>> item in _trackedFloat)
|
|
GUILayout.Label($"{item.Key} {item.Value.Value}", GetStyle());
|
|
}
|
|
|
|
private GUIStyle GetStyle()
|
|
{
|
|
return new GUIStyle
|
|
{
|
|
fontSize = 30
|
|
};
|
|
}
|
|
} |