fix debug service

This commit is contained in:
Mikhail 2024-02-26 12:34:09 +08:00
parent 762ba241da
commit 0862067ddd

View File

@ -6,14 +6,22 @@ namespace DCFApixels.DragonECS
{ {
public class UnityDebugService : DebugService public class UnityDebugService : DebugService
{ {
public static void Init() => Set<UnityDebugService>();
private ProfilerMarker[] _profilerMarkers = new ProfilerMarker[64]; private ProfilerMarker[] _profilerMarkers = new ProfilerMarker[64];
public static void Activate()
{
Set<UnityDebugService>();
}
public override void Print(string tag, object v) public override void Print(string tag, object v)
{ {
string log; string log;
if (!string.IsNullOrEmpty(tag)) if (v is Exception e)
{
Debug.LogException(e);
}
bool hasTag = string.IsNullOrEmpty(tag) == false;
if (hasTag)
{ {
log = $".[{tag}] {v}"; log = $".[{tag}] {v}";
string taglower = tag.ToLower(); string taglower = tag.ToLower();
@ -36,25 +44,24 @@ namespace DCFApixels.DragonECS
{ {
Debug.Break(); Debug.Break();
} }
public sealed override void ProfilerMarkBegin(int id)
public override void ProfilerMarkBegin(int id)
{ {
_profilerMarkers[id].Begin(); _profilerMarkers[id].Begin();
} }
public sealed override void ProfilerMarkEnd(int id)
public override void ProfilerMarkEnd(int id)
{ {
_profilerMarkers[id].End(); _profilerMarkers[id].End();
} }
protected sealed override void OnDelProfilerMark(int id)
protected override void OnDelProfilerMark(int id)
{ {
_profilerMarkers[id] = default; _profilerMarkers[id] = default;
} }
protected sealed override void OnNewProfilerMark(int id, string name)
protected override void OnNewProfilerMark(int id, string name)
{ {
if (id >= _profilerMarkers.Length) Array.Resize(ref _profilerMarkers, _profilerMarkers.Length << 1); if (id >= _profilerMarkers.Length)
{
Array.Resize(ref _profilerMarkers, _profilerMarkers.Length << 1);
}
_profilerMarkers[id] = new ProfilerMarker(ProfilerCategory.Scripts, name); _profilerMarkers[id] = new ProfilerMarker(ProfilerCategory.Scripts, name);
} }
} }