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