using System;
public delegate void LogHandle(Object log);
public class PlayerHandle
{
public static LogHandle DebugHandle;
public static LogHandle WarningHandle;
public static LogHandle ErrorHandle;
public static ELogLevel LogLevel;
public static void Debug(Object log)
{
if (LogLevel >= ELogLevel.Log)
DebugHandle(log);
}
public static void Warning(Object log)
{
if (LogLevel >= ELogLevel.Warning)
WarningHandle(log);
}
public static void Error(Object log)
{
if (LogLevel >= ELogLevel.Error)
ErrorHandle(log);
}
public enum ELogLevel
{
None = 0,
Error = 1,
Warning = 2,
Log = 4,
}
}
项目初始启动的时候,先去注册定义的几个事件,在项目中打印日志的时候,直接用类中定义的那几个静态方法。这样就可以通过简单的调整LogLevel的值,来控制显示的日志级别。