mirror of
https://github.com/unity-atoms/unity-atoms.git
synced 2025-01-21 23:58:49 -05:00
- 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
This commit is contained in:
parent
09493101fa
commit
2ca682f9b6
@ -107,8 +107,7 @@ namespace UnityAtoms.Editor
|
||||
{
|
||||
field.isReadOnly = true;
|
||||
field.multiline = true;
|
||||
field.value = selectedStackTraceId != -1 ? stackTraces[selectedStackTraceId] : "";
|
||||
field.value = selectedStackTraceId != -1 ? stackTraces[selectedStackTraceId] : "";
|
||||
field.value = selectedStackTraceId != -1 ? stackTraces[selectedStackTraceId].ToString() : "";
|
||||
field.style.borderLeftWidth = 0;
|
||||
field.style.borderRightWidth = 0;
|
||||
field.style.borderTopWidth = 0;
|
||||
|
@ -44,6 +44,10 @@ namespace UnityAtoms
|
||||
return new string(a);
|
||||
}
|
||||
|
||||
public static string GetFirstLine(this string str) => str.Split(new[] { '\r', '\n' }).FirstOrDefault();
|
||||
public static string GetFirstLine(this string str)
|
||||
{
|
||||
var indexFirstNewLineChar = str.IndexOfAny(new char[] { '\r', '\n' });
|
||||
return indexFirstNewLineChar == -1 ? str : str.Substring(0, indexFirstNewLineChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -61,13 +61,8 @@ namespace UnityAtoms
|
||||
/// <param name="item">The value associated with the Event.</param>
|
||||
public void Raise(T item)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (AtomPreferences.IsDebugModeEnabled)
|
||||
{
|
||||
StackTraces.AddStackTrace(GetInstanceID(), StackTraceEntry.Create(item));
|
||||
}
|
||||
#endif
|
||||
|
||||
StackTraces.AddStackTrace(GetInstanceID(), StackTraceEntry.Create(item));
|
||||
base.Raise();
|
||||
_onEvent?.Invoke(item);
|
||||
AddToReplayBuffer(item);
|
||||
|
@ -18,12 +18,7 @@ namespace UnityAtoms
|
||||
|
||||
public virtual void Raise()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (AtomPreferences.IsDebugModeEnabled)
|
||||
{
|
||||
StackTraces.AddStackTrace(GetInstanceID(), StackTraceEntry.Create());
|
||||
}
|
||||
#endif
|
||||
StackTraces.AddStackTrace(GetInstanceID(), StackTraceEntry.Create());
|
||||
OnEventNoValue?.Invoke();
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using UnityEngine;
|
||||
|
||||
namespace UnityAtoms
|
||||
@ -34,24 +35,14 @@ namespace UnityAtoms
|
||||
}
|
||||
}
|
||||
|
||||
public static StackTraceEntry Create(object obj) => new StackTraceEntry(Environment.StackTrace, obj);
|
||||
public static StackTraceEntry Create(object obj, int skipFrames = 0) => new StackTraceEntry(new StackTrace(skipFrames).ToString(), obj);
|
||||
|
||||
public static StackTraceEntry Create() => new StackTraceEntry(Environment.StackTrace);
|
||||
public static StackTraceEntry Create(int skipFrames = 0) => new StackTraceEntry(new StackTrace(skipFrames).ToString());
|
||||
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (obj == null) return false;
|
||||
public override bool Equals(object obj) => Equals(obj as StackTraceEntry);
|
||||
|
||||
if (obj is StackTraceEntry)
|
||||
{
|
||||
return Equals(obj as StackTraceEntry);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool Equals(StackTraceEntry other) => other._id == _id;
|
||||
public bool Equals(StackTraceEntry other) => other?._id == _id;
|
||||
|
||||
public override int GetHashCode() => _id.GetHashCode();
|
||||
|
||||
@ -60,7 +51,5 @@ namespace UnityAtoms
|
||||
_constructedWithValue ?
|
||||
$"{_frameCount} [{(_value == null ? "null" : _value.ToString())}] {_stackTrace}" :
|
||||
$"{_frameCount} {_stackTrace}";
|
||||
|
||||
public static implicit operator string(StackTraceEntry trace) => trace.ToString();
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
#if UNITY_EDITOR
|
||||
using System.Diagnostics;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@ -8,7 +9,14 @@ namespace UnityAtoms
|
||||
{
|
||||
private static Dictionary<int, ObservableCollection<StackTraceEntry>> _stackTracesById = new Dictionary<int, ObservableCollection<StackTraceEntry>>();
|
||||
|
||||
public static void AddStackTrace(int id, StackTraceEntry stackTrace) => GetStackTraces(id).Insert(0, stackTrace);
|
||||
[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();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user