using System; using System.Diagnostics; #if UNITY_5_3_OR_NEWER using UnityEngine; #endif namespace BITKit { public static class BIT4Log { #if UNITY_EDITOR && UNITY_5_3_OR_NEWER [RuntimeInitializeOnLoadMethod] private static void Reload() { OnLog = null; OnException = null; OnWarning = null; OnSetConsoleColor = null; OnNextLine = null; } #endif public static event Action OnLog; public static event Action OnLogCallback; public static event Action OnException; public static event Action OnExceptionCallback; public static event Action OnWarning; public static event Action OnWarningCallback; public static event Action OnSetConsoleColor; public static event Action OnNextLine; private static Type currentType; #if UNITY_5_3_OR_NEWER //[HideInCallstack] #endif public static void Log(object x, ConsoleColor color = ConsoleColor.White) { OnSetConsoleColor?.Invoke(color); OnLog?.Invoke(x?.ToString()); OnLogCallback?.Invoke(x?.ToString(),currentType); } #if UNITY_5_3_OR_NEWER [HideInCallstack] #endif public static void Log(object x, ConsoleColor color = ConsoleColor.White) { if (currentType != typeof(T)) { OnNextLine?.Invoke(); } #if NET5_0_OR_GREATER Log($"[{DateTime.Now}]{typeof(T).Name}:{x}"); #else Log($"{typeof(T).Name}:{x}"); #endif currentType = typeof(T); } #if UNITY_5_3_OR_NEWER [HideInCallstack] #endif public static void LogException(Exception e) { OnException?.Invoke(e); } #if UNITY_5_3_OR_NEWER [HideInCallstack] #endif public static void Warning(object x) { OnWarning?.Invoke(x.ToString()); } #if UNITY_5_3_OR_NEWER [HideInCallstack] #endif public static void Warning(object x) { Warning($"{typeof(T).Name}:{x}"); } } }