DragonECS-Unity/src/Debug/DebugService/UnityDebugService.cs

59 lines
1.6 KiB
C#
Raw Normal View History

2023-03-27 17:34:04 +08:00
using System;
using Unity.Profiling;
using UnityEngine;
2023-03-29 19:58:58 +08:00
namespace DCFApixels.DragonECS
2023-03-27 17:34:04 +08:00
{
public class UnityDebugService : DebugService
{
2023-03-27 18:00:13 +08:00
public static void Init() => Set<UnityDebugService>();
2023-03-27 17:34:04 +08:00
private ProfilerMarker[] _profilerMarkers = new ProfilerMarker[64];
public override void Print(string tag, object v)
{
2023-03-30 05:34:38 +08:00
string log;
if (!string.IsNullOrEmpty(tag))
2023-03-27 17:34:04 +08:00
{
2023-05-07 00:50:44 +08:00
log = $".[{tag}] {v}";
2023-03-30 05:34:38 +08:00
string taglower = tag.ToLower();
if (taglower.Contains("warning"))
{
Debug.LogWarning(log);
return;
}
if (taglower.Contains("error"))
{
Debug.LogError(log);
return;
}
Debug.Log(log);
2023-03-27 17:34:04 +08:00
return;
}
2023-03-30 05:34:38 +08:00
Debug.Log(v);
2023-03-27 17:34:04 +08:00
}
2023-06-12 22:17:49 +08:00
public override void ProfilerMarkBegin(int id)
2023-03-27 17:34:04 +08:00
{
_profilerMarkers[id].Begin();
}
2023-06-12 22:17:49 +08:00
public override void ProfilerMarkEnd(int id)
2023-03-27 17:34:04 +08:00
{
_profilerMarkers[id].End();
}
2023-06-12 22:17:49 +08:00
protected override void OnDelProfilerMark(int id)
2023-03-27 17:34:04 +08:00
{
_profilerMarkers[id] = default;
}
2023-06-12 22:17:49 +08:00
protected override void OnNewProfilerMark(int id, string name)
2023-03-27 17:34:04 +08:00
{
if (id >= _profilerMarkers.Length) Array.Resize(ref _profilerMarkers, _profilerMarkers.Length << 1);
_profilerMarkers[id] = new ProfilerMarker(ProfilerCategory.Scripts, name);
}
}
}