Update UnityDebugService.cs

This commit is contained in:
Mikhail 2024-10-05 12:45:01 +08:00
parent b25c752c7f
commit 336a9f3cfe

View File

@ -1,14 +1,22 @@
using System; using System;
using Unity.Profiling; using Unity.Profiling;
using UnityEditor;
using UnityEngine; using UnityEngine;
#region [InitializeOnLoad]
#if UNITY_EDITOR
namespace DCFApixels.DragonECS
{
using UnityEditor;
[InitializeOnLoad]
public partial class UnityDebugService { }
}
#endif
#endregion
namespace DCFApixels.DragonECS namespace DCFApixels.DragonECS
{ {
#if UNITY_EDITOR // Методы юнитевского Debug и ProfilerMarker потоко безопасны
[InitializeOnLoad] public partial class UnityDebugService : DebugService
#endif
public class UnityDebugService : DebugService
{ {
private ProfilerMarker[] _profilerMarkers = new ProfilerMarker[64]; private ProfilerMarker[] _profilerMarkers = new ProfilerMarker[64];
@ -20,15 +28,18 @@ namespace DCFApixels.DragonECS
{ {
Set<UnityDebugService>(); Set<UnityDebugService>();
} }
protected override DebugService CreateThreadInstance()
{
return new UnityDebugService();
}
public override void Print(string tag, object v) public override void Print(string tag, object v)
{ {
string log;
if (v is Exception e) if (v is Exception e)
{ {
Debug.LogException(e); Debug.LogException(e);
return; return;
} }
string msg = AutoConvertObjectToString(v); string msg = AutoConvertObjectToString(v);
bool hasTag = string.IsNullOrEmpty(tag) == false; bool hasTag = string.IsNullOrEmpty(tag) == false;
if (hasTag) if (hasTag)
@ -37,20 +48,20 @@ namespace DCFApixels.DragonECS
switch (taglower) switch (taglower)
{ {
case "pass": case "pass":
log = $"[<color=#00ff00>{tag}</color>] {msg}"; Debug.Log(
Debug.Log(log); $"[<color=#00ff00>{tag}</color>] {msg}");
break; break;
case "warning": case "warning":
log = $"[<color=#ffff00>{tag}</color>] {msg}"; Debug.LogWarning(
Debug.LogWarning(log); $"[<color=#ffff00>{tag}</color>] {msg}");
break; break;
case "error": case "error":
log = $"[<color=#ff4028>{tag}</color>] {msg}"; Debug.LogError(
Debug.LogError(log); $"[<color=#ff4028>{tag}</color>] {msg}");
break; break;
default: default:
log = $"[{tag}] {msg}"; Debug.Log(
Debug.Log(log); $"[{tag}] {msg}");
break; break;
} }
return; return;
@ -82,4 +93,4 @@ namespace DCFApixels.DragonECS
_profilerMarkers[id] = new ProfilerMarker(ProfilerCategory.Scripts, name); _profilerMarkers[id] = new ProfilerMarker(ProfilerCategory.Scripts, name);
} }
} }
} }