Unity日志工具类的两种封装 发表于 2019-08-29 本文字数: 2.9k | 阅读时长 ≈ 3 分钟 思考并回答以下问题: 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126using System;#if UNITY_ENGINE using UnityEngine;#endif public enum LogLevel { None = 0, Exception = 1, Error = 2, Warning = 3, Normal = 4, Max = 5, } public static class Log { public static void LogInfo(this object selfMsg) { I(selfMsg); } public static void LogWarning(this object selfMsg) { W(selfMsg); } public static void LogError(this object selfMsg) { E(selfMsg); } public static void LogException(this Exception selfExp) { E(selfExp); } private static LogLevel mLogLevel = LogLevel.Normal; public static LogLevel Level { get { return mLogLevel; } set { mLogLevel = value; } } public static void I(object msg, params object[] args) { if (mLogLevel < LogLevel.Normal) { return; } if (args == null || args.Length == 0) {#if UNITY_ENGINE Debug.Log(msg);#endif } else {#if UNITY_ENGINE Debug.LogFormat(msg.ToString(), args); #endif } } public static void E(Exception e) { if (mLogLevel < LogLevel.Exception) { return; }#if UNITY_ENGINE Debug.LogException(e);#endif } public static void E(object msg, params object[] args) { if (mLogLevel < LogLevel.Error) { return; } if (args == null || args.Length == 0) {#if UNITY_ENGINE Debug.LogError(msg);#endif } else {#if UNITY_ENGINE Debug.LogError(string.Format(msg.ToString(), args));#endif } } public static void W(object msg) { if (mLogLevel < LogLevel.Warning) { return; }#if UNITY_ENGINE Debug.LogWarning(msg);#endif } public static void W(string msg, params object[] args) { if (mLogLevel < LogLevel.Warning) { return; }#if UNITY_ENGINE Debug.LogWarning(string.Format(msg, args));#endif } }} 插件,DLL格式12