using System; using UnityEngine; using Object = UnityEngine.Object; public class Log { #region 【属性】 public static bool IsOpen { set; get; } public static bool IsScreenOpen { set; get; } public static bool IsInfo { set; get; } public static bool IsDebug { set; get; } public static bool IsWarning { set; get; } public static bool IsError { set; get; } public static bool IsExcept { set; get; } public static bool IsCritical { set; get; } #endregion static Log() { IsOpen = true; IsScreenOpen = true; IsDebug = true; IsInfo = true; IsWarning = true; IsError = true; IsExcept = true; IsCritical = true; } #region 【公有方法】 /// /// 屏幕日志 /// public static void OpenReporter() { var o = Object.Instantiate(Resources.Load("Reporter")) as Transform; if (o != null) Object.DontDestroyOnLoad(o); } /// /// debug /// /// public static void Debug(object content) { if (!IsDebug) return; string logstr = DateTime.Now.ToString("HH:mm:ss") + " [Debug] " + content; _SetDebugLog(logstr, LEVEL.debug); } /// /// 信息 /// /// public static void Info(object content) { if (!IsInfo) return; string logstr = DateTime.Now.ToString("HH:mm:ss") + " [Info] " + content; _SetDebugLog(logstr, (LEVEL.info)); } /// /// 警告 /// /// public static void Warning(object content) { if (!IsWarning) return; string logstr = DateTime.Now.ToString("HH:mm:ss") + " [Warning] " + content; _SetDebugLog(logstr, LEVEL.warning); } /// /// 错误 /// /// public static void Error(object content) { if (!IsError) return; string logstr = DateTime.Now.ToString("HH:mm:ss") + " [Error] " + content; _SetDebugLog(logstr, LEVEL.error); } /// /// 异常 /// /// public static void Except(object content) { if (!IsExcept) return; string logstr = DateTime.Now.ToString("HH:mm:ss") + " [Except] " + content; _SetDebugLog(logstr, LEVEL.except); } /// /// 重要提示 /// /// public static void Critical(object content) { if (!IsCritical) return; string logstr = DateTime.Now.ToString("HH:mm:ss") + " [Critical] " + content; _SetDebugLog(logstr, LEVEL.critical); } #endregion #region 【私有方法】 /// /// 设置输出log文本信息 /// /// /// private static void _SetDebugLog(object content, LEVEL level) { //开发log if (IsOpen) { string color = _GetLogModeColor(level); if (level == LEVEL.error) { UnityEngine.Debug.LogError("" + content + ""); } else if (level == LEVEL.warning) { UnityEngine.Debug.LogWarning("" + content + ""); } else { UnityEngine.Debug.Log("" + content + ""); } } } /// /// log输出颜色 /// /// /// private static string _GetLogModeColor(LEVEL level) { string nColor = "#878787"; switch (level) { case LEVEL.debug: nColor = "#FFFFFF"; break; case LEVEL.info: nColor = "#0BCD32"; break; case LEVEL.warning: nColor = "#DBDB00"; break; case LEVEL.error: nColor = "#D40909"; break; case LEVEL.except: nColor = "#0707D2"; break; case LEVEL.critical: nColor = "#878787"; break; } return nColor; } #endregion #region 【数据结构】 /// /// log类型 /// public enum LEVEL { normal, debug, info, warning, error, except, critical } #endregion }