80 lines
2.3 KiB
C#
80 lines
2.3 KiB
C#
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<string> OnLog;
|
|
public static event Action<string,Type> OnLogCallback;
|
|
public static event Action<Exception> OnException;
|
|
public static event Action<Exception,Type> OnExceptionCallback;
|
|
public static event Action<string> OnWarning;
|
|
public static event Action<string,Type> OnWarningCallback;
|
|
public static event Action<ConsoleColor> 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<T>(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($"<color=#add8e6ff><b>{typeof(T).Name}</b></color>:{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<T>(object x)
|
|
{
|
|
Warning($"<color=#ffa500ff><b>{typeof(T).Name}</b></color>:{x}");
|
|
}
|
|
}
|
|
}
|