我们在做项目的时候经常会遇到这样的一种情况,进行打印输出特别多,用来调试错误,但是我们往往会遇到这种情况,项目后期我们往往会去取消那些打印,但是当我们一个一个去取消的话就会显得相对较为麻烦,
现在我告诉大家快速取消注释和打开注释的两种方法:
第一种方法:(重写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;
}
以上两种方式,就是进行打印取消的两种快捷方式,欢迎大家在下面留言给一些更好的建议,同时也欢迎大家在评论区留下自己想要实现的功能,我会去努力帮大家实现,同时会在下一个博客分享出来,
欢迎大家的留言!!!!!!!!!!!!!!!