Adam Ramberg 70f8130797
Debug events by displaying stack traces for events (#159)
* Add stack trace toggled via user prefs

* Add docs regarding preferences

* Rename color getter functions

* Fix minior order of execution bug

* Use GUID + improved styling of detailed stack view

* - Changed the AddStackTrace method to be conditional (from one of your initial suggestions).
- Removed the implicit conversion operator in StackTraceEntry and is instead using ToString explicitly when needed.
- Improved implementation of GetFirstLine
- Simplified Equals implementation of the StackTraceEntry class
2020-06-06 22:19:07 +02:00

39 lines
1.2 KiB
C#

#if UNITY_EDITOR
using System.Diagnostics;
using System.Collections.ObjectModel;
using System.Collections.Generic;
namespace UnityAtoms
{
public static class StackTraces
{
private static Dictionary<int, ObservableCollection<StackTraceEntry>> _stackTracesById = new Dictionary<int, ObservableCollection<StackTraceEntry>>();
[Conditional("UNITY_EDITOR")]
public static void AddStackTrace(int id, StackTraceEntry stackTrace)
{
if (AtomPreferences.IsDebugModeEnabled)
{
GetStackTraces(id).Insert(0, stackTrace);
}
}
public static void ClearStackTraces(int id) => GetStackTraces(id).Clear();
public static ObservableCollection<StackTraceEntry> GetStackTraces(int id)
{
if (!_stackTracesById.ContainsKey(id))
{
_stackTracesById.Add(id, new ObservableCollection<StackTraceEntry>());
}
else if (_stackTracesById[id] == null)
{
_stackTracesById[id] = new ObservableCollection<StackTraceEntry>();
}
return _stackTracesById[id];
}
}
}
#endif