Unity封装Debug调试

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

  1. 打开VS 新建类库;
    Unity封装Debug调试_第1张图片
  2. 添加引用UnityEngine.ll
    Unity封装Debug调试_第2张图片
    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 设置是否输出。

你可能感兴趣的:(Unity)