Unity封装Debug调试

当项目发布后调试用的Debug信息就没必要打印了。将Unity的Debug信息封装。

  1. 打开VS 新建类库;
    这里写图片描述
  2. 添加引用UnityEngine.ll
    这里写图片描述
    3.血代码
public class Debuger
{
    public static bool EnableLogger = true;

    public static void Log(object message)
    {
        if (EnableLogger) Debug.Log(message);
    }

    public static void Log(object message, UnityEngine.Object context)
    {
        if (EnableLogger) Debug.Log(message, context);
    }

    public static void LogError(object message)
    {
        if (EnableLogger) Debug.LogError(message);
    }

    public static void LogError(object message, UnityEngine.Object context)
    {
        if (EnableLogger) Debug.LogError(message, context);
    }

    public static void LogErrorFormat(string format, params object[] args)
    {
        if (EnableLogger) Debug.LogErrorFormat(format, args);
    }

    public static void LogErrorFormat(UnityEngine.Object context,
        string format, params object[] args)
    {
        if (EnableLogger) Debug.LogErrorFormat(context, format, args);
    }

    public static void LogException(Exception exception)
    {
        if (EnableLogger) Debug.LogException(exception);
    }

    public static void LogException(Exception exception,
        UnityEngine.Object context)
    {
        if (EnableLogger) Debug.LogException(exception, context);
    }

    public static void LogFormat(string format, params object[] args)
    {
        if (EnableLogger) Debug.LogFormat(format, args);
    }

    public static void LogFormat(UnityEngine.Object context,
        string format, params object[] args)
    {
        if (EnableLogger) Debug.LogFormat(context, format, args);
    }

    public static void LogWarning(object message)
    {
        if (EnableLogger) Debug.LogWarning(message);
    }

    public static void LogWarning(object message,
        UnityEngine.Object context)
    {
        if (EnableLogger) Debug.LogWarning(message, context);
    }

    public static void LogWarningFormat(string format,
        params object[] args)
    {
        if (EnableLogger) Debug.LogWarningFormat(format, args);
    }

    public static void LogWarningFormat(UnityEngine.Object context,
        string format, params object[] args)
    {
        if (EnableLogger) Debug.LogWarningFormat(context, format, args);
    }
}

通过设置参数EnableLogger 设置是否输出。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值