65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
|
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<string> OnLog;
|
|||
|
public static event Action<Exception> OnException;
|
|||
|
public static event Action<string> OnWarning;
|
|||
|
public static event Action<ConsoleColor> OnSetConsoleColor;
|
|||
|
public static event Action OnNextLine;
|
|||
|
private static bool LogTime;
|
|||
|
private static Type currentType;
|
|||
|
[BITCommand]
|
|||
|
public static void UseLogTime()
|
|||
|
{
|
|||
|
LogTime = true;
|
|||
|
}
|
|||
|
public static void Log(object x, int debugLevel = 0, ConsoleColor color = ConsoleColor.White)
|
|||
|
{
|
|||
|
if (x is not null)
|
|||
|
{
|
|||
|
OnSetConsoleColor?.Invoke(color);
|
|||
|
OnLog?.Invoke( LogTime ? $"[{DateTime.Now}]{x}":x.ToString());
|
|||
|
}
|
|||
|
}
|
|||
|
public static void Log<T>(object x, int debugLevel = 0, ConsoleColor color = ConsoleColor.White)
|
|||
|
{
|
|||
|
if (currentType == typeof(T))
|
|||
|
{
|
|||
|
Log(x, debugLevel);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
OnNextLine?.Invoke();
|
|||
|
Log($"{typeof(T).Name}:{x}", debugLevel);
|
|||
|
}
|
|||
|
currentType = typeof(T);
|
|||
|
}
|
|||
|
public static void LogException(Exception e)
|
|||
|
{
|
|||
|
OnException?.Invoke(e);
|
|||
|
}
|
|||
|
public static void Warnning(object x, int debugLevel = 0)
|
|||
|
{
|
|||
|
OnWarning?.Invoke(x.ToString());
|
|||
|
}
|
|||
|
public static void Warnning<T>(object x, int debugLevel = 0)
|
|||
|
{
|
|||
|
Warnning($"{typeof(T).Name}:{x}", debugLevel);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|