码迷,mamicode.com
首页 > 编程语言 > 详细

Unity 中Debug打印的全局注释方式和重写

时间:2019-05-26 11:07:52      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:turn   两种方法   error   打印   img   obj   com   ams   erro   

我们在做项目的时候经常会遇到这样的一种情况,进行打印输出特别多,用来调试错误,但是我们往往会遇到这种情况,项目后期我们往往会去取消那些打印,但是当我们一个一个去取消的话就会显得相对较为麻烦,

现在我告诉大家快速取消注释和打开注释的两种方法:

 

第一种方法:(重写Debug类)

using System;
using UnityEngine;


public class Debug
{
    public static bool EnableLog = true;
    public static void DrawLine(Vector3 start, Vector3 end, Color color, float duration)
    {
        if (EnableLog)
        {
            UnityEngine.Debug.DrawLine(start, end, color, duration);
        }
    }
    public static void DrawLine(Vector3 start, Vector3 end)
    {
        if (EnableLog)
        {
            UnityEngine.Debug.DrawLine(start, end);
        }
    }
    public static void DrawLine(Vector3 start, Vector3 end, Color color)
    {
        if (EnableLog)
        {
            UnityEngine.Debug.DrawLine(start, end, color);
        }
    }
    public static void Log(object message, UnityEngine.Object context)
    {
        if (EnableLog)
        {
            UnityEngine.Debug.Log(message, context);
        }
    }
    public static void Log(object message)
    {
        if (EnableLog)
        {
            UnityEngine.Debug.Log(message);
        }
    }
    public static void LogAssertion(object message)
    {
        if (EnableLog)
        {
            UnityEngine.Debug.LogAssertion(message);
        }
    }
    public static void LogAssertionFormat(string format, params object[] args)
    {
        if (EnableLog)
        {
            UnityEngine.Debug.LogAssertionFormat(format, args);
        }
    }
    public static void LogError(object message, UnityEngine.Object context)
    {
        if (EnableLog)
        {
            UnityEngine.Debug.LogError(message, context);
        }
    }
    public static void LogError(object message)
    {
        if (EnableLog)
        {
            UnityEngine.Debug.LogError(message);
        }
    }
    public static void LogErrorFormat(string format, params object[] args)
    {
        if (EnableLog)
        {
            UnityEngine.Debug.LogErrorFormat(format, args);
        }
    }
    public static void LogException(Exception exception)
    {
        if (EnableLog)
        {
            UnityEngine.Debug.LogException(exception);
        }
    }
    public static void LogFormat(string format, params object[] args)
    {
        if (EnableLog)
        {
            UnityEngine.Debug.LogFormat(format, args);
        }
    }
    public static void LogWarning(object message)
    {
        if (EnableLog)
        {
            UnityEngine.Debug.LogWarning(message);
        }
    }
    public static void LogWarning(object message, UnityEngine.Object context)
    {
        if (EnableLog)
        {
            UnityEngine.Debug.LogWarning(message, context);
        }
    }
    public static void LogWarningFormat(string format, params object[] args)
    {
        if (EnableLog)
        {
            UnityEngine.Debug.LogWarningFormat(format, args);
        }
    }
}

 第一种方式进行重写之后,我们想要取消其中的打印,就可以直接通过下面代码就可以实现了

 void Start () {
     Debug.EnableLog = false;
     Debug.Log("1111111111");
     }

  

第二种方法:进行项目中的替换功能(这样的话如果碰到Return 输出 会报错)

如下图:

技术图片

这种方法进行替换的时候碰到一些直接Reutrn的会报错,比如下面这种情况

if(true)
{
  Debug.Log("111111111");
  Return;    
}

  

 以上两种方式,就是进行打印取消的两种快捷方式,欢迎大家在下面留言给一些更好的建议,同时也欢迎大家在评论区留下自己想要实现的功能,我会去努力帮大家实现,同时会在下一个博客分享出来,

欢迎大家的留言!!!!!!!!!!!!!!!

Unity 中Debug打印的全局注释方式和重写

标签:turn   两种方法   error   打印   img   obj   com   ams   erro   

原文地址:https://www.cnblogs.com/baosong/p/10925302.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!