using System; namespace BITKit { public static class BIT4Log { #if UNITY_EDITOR [UnityEngine.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 OnException; public static event Action OnWarning; public static event Action OnSetConsoleColor; public static event Action OnNextLine; private static Type currentType; public static void Log(object x, int debugLevel = 0, ConsoleColor color = ConsoleColor.White) { OnSetConsoleColor?.Invoke(color); OnLog?.Invoke(x?.ToString()); } public static void Log(object x, int debugLevel = 0, ConsoleColor color = ConsoleColor.White) { if (currentType != typeof(T)) { OnNextLine?.Invoke(); } #if NET5_0_OR_GREATER Log($"[{DateTime.Now}]{typeof(T).Name}:{x}", debugLevel); #else Log($"{typeof(T).Name}:{x}", debugLevel); #endif currentType = typeof(T); } public static void LogException(Exception e) { OnException?.Invoke(e); } public static void Warning(object x, int debugLevel = 0) { OnWarning?.Invoke(x.ToString()); } public static void Warning(object x, int debugLevel = 0) { Warning($"{typeof(T).Name}:{x}", debugLevel); } } }