using System.Collections; using System.Collections.Generic; using UnityEngine; using System.Text; using YKMoon; using System.IO; namespace YKMoon { public class YKDebug : USingleton, IUSingletonEventHandler { public enum ELogLevel { None = 0, Error = 1, Warning = 2, Info = 3, } public enum ELogType { Game, Editor, } public void OnCreateSingleton() { if (!Application.isPlaying) { return; } ClearLogFile(ELogType.Game); } public static ELogLevel logLevel = ELogLevel.Info; public static void Log(string format, params object[] args) { Instance.LogInner(ELogType.Game, ELogLevel.Info, null, format, args); } public static void LogWarning(string format, params object[] args) { Instance.LogInner(ELogType.Game, ELogLevel.Warning, null, format, args); } public static void LogError(string format, params object[] args) { Instance.LogInner(ELogType.Game, ELogLevel.Error, null, format, args); } public static void EditorLog(string format, params object[] args) { Instance.LogInner(ELogType.Editor, ELogLevel.Info, null, format, args); } public static void EditorLogWarning(string format, params object[] args) { Instance.LogInner(ELogType.Editor, ELogLevel.Warning, null, format, args); } public static void EditorLogError(string format, params object[] args) { Instance.LogInner(ELogType.Editor, ELogLevel.Error, null, format, args); } private void LogInner(ELogType logType, ELogLevel logLevel, Object obj, string format, params object[] args) { if(YKDebug.logLevel < logLevel) { return; } StringBuilder sb = StringBuilderPool.Get(); sb.AppendFormat(format, args); switch(logLevel) { case ELogLevel.Info: if(obj != null) { Debug.Log(sb.ToString(), obj); } else { Debug.Log(sb.ToString()); } break; case ELogLevel.Warning: if(obj != null) { Debug.LogWarning(sb.ToString(), obj); } else { Debug.LogWarning(sb.ToString()); } break; case ELogLevel.Error: if(obj != null) { Debug.LogError(sb.ToString(), obj); } else { Debug.LogError(sb.ToString()); } break; } StringBuilderPool.Release(sb); //UNDONE:这里要加输出文件 switch(logType) { case ELogType.Game: break; case ELogType.Editor: break; } } #region Files private Dictionary logFilePath = new Dictionary() { { ELogType.Editor, "" }, { ELogType.Game, "" }, }; private Dictionary logStreams = new Dictionary(); private bool WriteLog(string logStr) { return true; } private void CreateLogFile(ELogType tag) { } private void ClearLogFile(ELogType tag) { } #endregion } }