mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-23 08:38:23 -05:00
70f8130797
* 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
55 lines
1.7 KiB
C#
55 lines
1.7 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
using UnityEngine;
|
|
|
|
namespace UnityAtoms
|
|
{
|
|
public class StackTraceEntry : IEquatable<StackTraceEntry>
|
|
{
|
|
private readonly Guid _id;
|
|
private readonly int _frameCount;
|
|
private readonly string _stackTrace;
|
|
private readonly object _value;
|
|
private readonly bool _constructedWithValue = false;
|
|
|
|
private StackTraceEntry(string stackTrace)
|
|
{
|
|
_id = Guid.NewGuid();
|
|
_stackTrace = stackTrace;
|
|
|
|
if (Application.isPlaying)
|
|
{
|
|
_frameCount = Time.frameCount;
|
|
}
|
|
}
|
|
private StackTraceEntry(string stackTrace, object value)
|
|
{
|
|
_value = value;
|
|
_constructedWithValue = true;
|
|
_id = Guid.NewGuid();
|
|
_stackTrace = stackTrace;
|
|
|
|
if (Application.isPlaying)
|
|
{
|
|
_frameCount = Time.frameCount;
|
|
}
|
|
}
|
|
|
|
public static StackTraceEntry Create(object obj, int skipFrames = 0) => new StackTraceEntry(new StackTrace(skipFrames).ToString(), obj);
|
|
|
|
public static StackTraceEntry Create(int skipFrames = 0) => new StackTraceEntry(new StackTrace(skipFrames).ToString());
|
|
|
|
|
|
public override bool Equals(object obj) => Equals(obj as StackTraceEntry);
|
|
|
|
public bool Equals(StackTraceEntry other) => other?._id == _id;
|
|
|
|
public override int GetHashCode() => _id.GetHashCode();
|
|
|
|
|
|
public override string ToString() =>
|
|
_constructedWithValue ?
|
|
$"{_frameCount} [{(_value == null ? "null" : _value.ToString())}] {_stackTrace}" :
|
|
$"{_frameCount} {_stackTrace}";
|
|
}
|
|
} |