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

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

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

 

第一种方法:(重写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;    
}

  

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

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

转载于:https://www.cnblogs.com/baosong/p/10925302.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值