using DCFApixels.DragonECS.Unity.Internal; using System; using System.Reflection; 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 { // Методы юнитевского Debug и ProfilerMarker потоко безопасны public partial class UnityDebugService : DebugService { private ProfilerMarker[] _profilerMarkers = new ProfilerMarker[64]; static UnityDebugService() { Activate(); } public static void Activate() { if (Instance.GetType() == typeof(UnityDebugService)) { return; } Set(); } protected override void OnEnableBaseService(DebugService oldService) { EditorGUI.hyperLinkClicked -= EditorGUI_hyperLinkClicked; EditorGUI.hyperLinkClicked += EditorGUI_hyperLinkClicked; Application.logMessageReceived -= Application_logMessageReceived; Application.logMessageReceived += Application_logMessageReceived; } protected override void OnDisableBaseService(DebugService nextService) { Application.logMessageReceived -= Application_logMessageReceived; EditorGUI.hyperLinkClicked -= EditorGUI_hyperLinkClicked; } private void EditorGUI_hyperLinkClicked(EditorWindow editor, HyperLinkClickedEventArgs args) { throw new NotImplementedException(); } private void Application_logMessageReceived(string logString, string stackTrace, LogType type) { } protected override DebugService CreateThreadInstance() { return new UnityDebugService(); } #if UNITY_2021_3_OR_NEWER [HideInCallstack] #endif public override void Print(string tag, object v) { if (v is Exception e) { Debug.LogException(e); return; } string msg = AutoConvertObjectToString(v); bool hasTag = string.IsNullOrEmpty(tag) == false; if (hasTag) { string taglower = tag.ToLower(); switch (taglower) { case "pass": Debug.Log( $"[{tag}] {msg}"); break; case "warning": Debug.LogWarning( $"[{tag}] {msg}"); break; case "error": Debug.LogError( $"[{tag}] {msg}"); break; default: Debug.Log( $"[{tag}] {msg}"); break; } return; } Debug.Log(msg); } public override void Break() { Debug.Break(); } public sealed override void ProfilerMarkBegin(int id) { _profilerMarkers[id].Begin(); } public sealed override void ProfilerMarkEnd(int id) { _profilerMarkers[id].End(); } protected sealed override void OnDelProfilerMark(int id) { _profilerMarkers[id] = default; } protected sealed override void OnNewProfilerMark(int id, string name) { if (id >= _profilerMarkers.Length) { Array.Resize(ref _profilerMarkers, _profilerMarkers.Length << 1); } _profilerMarkers[id] = new ProfilerMarker(ProfilerCategory.Scripts, name); } } }