美文网首页
Unity之屏蔽所有的Debug日志

Unity之屏蔽所有的Debug日志

作者: 小骄傲999 | 来源:发表于2021-06-22 21:18 被阅读0次

将Debug类封装起来,可以控制正式版本不带Log等等,节约性能

using System;

using UnityEngine;

using UnityEngine.Internal;

/// <summary>

/// 重写Debug类

/// </summary>

public class Debug {

    static string EnableLog = "DEBUG_TEST";

    public static bool isDebugBuild

    {

        get { return UnityEngine.Debug.isDebugBuild; }

    }

    public static void DrawLine(Vector3 start, Vector3 end, Color color, float duration)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.DrawLine(start, end, color, duration);

        }

    }

    public static void DrawLine(Vector3 start, Vector3 end)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.DrawLine(start, end);

        }

    }

    public static void DrawLine(Vector3 start, Vector3 end, Color color)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.DrawLine(start, end, color);

        }

    }

    public static void DrawLine(Vector3 start, Vector3 end, [DefaultValue("Color.white")] Color color, [DefaultValue("0.0f")] float duration, [DefaultValue("true")] bool depthTest)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.DrawLine(start, end, color, duration, depthTest);

        }

    }

    public static void Log(object message, UnityEngine.Object context)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.Log(message, context);

        }

    }

    public static void Log(object message)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.Log(message);

        }

    }

    public static void LogAssertion(object message)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.LogAssertion(message);

        }

    }

    public static void LogAssertionFormat(string format, params object[] args)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.LogAssertionFormat(format, args);

        }

    }

    public static void LogError(object message, UnityEngine.Object context)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.LogError(message, context);

        }

    }

    public static void LogError(object message)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.LogError(message);

        }

    }

    public static void LogErrorFormat(string format, params object[] args)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.LogErrorFormat(format, args);

        }

    }

    public static void LogErrorFormat(UnityEngine.Object context, string format, params object[] args)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.LogErrorFormat(context, format, args);

        }

    }

    public static void LogException(Exception exception)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.LogException(exception);

        }

    }

    public static void LogFormat(string format, params object[] args)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.LogFormat(format, args);

        }

    }

    public static void LogWarning(object message)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.LogWarning(message);

        }

    }

    public static void LogWarning(object message, UnityEngine.Object context)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.LogWarning(message, context);

        }

    }

    public static void LogWarningFormat(string format, params object[] args)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.LogWarningFormat(format, args);

        }

    }

    public static void LogWarningFormat(UnityEngine.Object context, string format, params object[] args)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.LogWarningFormat(context, format, args);

        }

    }

    public static void DrawRay(Vector3 start, Vector3 dir, Color color, float duration)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.DrawRay(start, dir, color, duration);

        }

    }

    public static void DrawRay(Vector3 start, Vector3 dir, [DefaultValue("Color.white")] Color color, [DefaultValue("0.0f")] float duration, [DefaultValue("true")] bool depthTest)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.DrawRay(start, dir, color, duration, depthTest);

        }

    }

    public static void DrawRay(Vector3 start, Vector3 dir)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.DrawRay(start, dir);

        }

    }

    public static void DrawRay(Vector3 start, Vector3 dir, Color color)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.DrawRay(start, dir, color);

        }

    }

    public static void Assert(bool condition)

    {

        if (EnableLog == MSDKSetting.APKDebug)

        {

            UnityEngine.Debug.Assert(condition);

        }

    }

}

相关文章

网友评论

      本文标题:Unity之屏蔽所有的Debug日志

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