美文网首页
每日一学13——Unity Debug.Log控制开关

每日一学13——Unity Debug.Log控制开关

作者: ShawnWeasley | 来源:发表于2020-07-08 14:31 被阅读0次

学习来源:https://blog.csdn.net/blog_lee/article/details/81389692

其实我并不是在乎一丢丢性能的影响,我只关心能不能关闭Log,这样就可以在不想看log的时候全都不显示,不过文中的方法也不错。记录一下,没啥能改的,就不改了
开关Log

if (Debug.isDebugBuild) {
    Debug.logger.logEnabled = true;
    //Debug.logger.filterLogType = LogType.Log; //显示所有
} else {
    Debug.logger.logEnabled = false;
    //Debug.logger.filterLogType = LogType.Error;//只显示Error + Exception
}

间接调用

public static class DebugEx {
     //需要在Unity PlayerSettings -> Scripting Define Symbol 添加VERBOSE
     //Release发布时去掉VERBOSE,所有的DebugEx.Log函数调用将不会参与编译。
     //这是简单的实现方式 , 后期功能的扩展以及Debug和Release自动切换机制,可以开发者进行封装。
     [Conditional("VERBOSE")] 
     public static void Log(object message, UnityEngine.Object obj = null) {
         UnityEngine.Debug.Log(message, obj);
     }
 
     public static void LogWarning(object message, UnityEngine.Object obj = null) {
         UnityEngine.Debug.LogWarning(message, obj);
     }
 
     public static void LogError(object message, UnityEngine.Object obj = null) {
         UnityEngine.Debug.LogError(message, obj);
     }
 }

相关文章

网友评论

      本文标题:每日一学13——Unity Debug.Log控制开关

      本文链接:https://www.haomeiwen.com/subject/kyhccktx.html