Unity 打印信息

发表于2017-08-29
评论0 529浏览

想免费获取内部独家PPT资料库?观看行业大牛直播?点击加入腾讯游戏学院游戏程序行业精英群

711501594
打印这个功能看似比较容易,但是要注意的地方还是有很多的,下面就给大家介绍下Unity中的打印信息。
//********************************************************************
// 文件名: Debug.cs
// 描述:  打印信息
// 作者: 李伟
// 创建时间: 2015-07-16
// https://gist.github.com/onevcat/4036890
//********************************************************************
#define DEBUG_LEVEL_LOG
#define DEBUG_LEVEL_WARN
#define DEBUG_LEVEL_ERROR
using System;
using UnityEngine;
namespace SK
{
    public static class D
    {
        [System.Diagnostics.Conditional("DEBUG_LEVEL_LOG")]
        [System.Diagnostics.Conditional("DEBUG_LEVEL_WARN")]
        [System.Diagnostics.Conditional("DEBUG_LEVEL_ERROR")]
        public static void Log(object format, params object[] paramList)
        {
            if (format is string)
                Debug.Log(string.Format(format as string, paramList));
            else
                Debug.Log(format);
        }
        [System.Diagnostics.Conditional("DEBUG_LEVEL_WARN")]
        public static void Warn(object format, params object[] paramList)
        {
            if (format is string)
                Debug.LogWarning(string.Format(format as string, paramList));
            else
                Debug.LogWarning(format);
        }
        [System.Diagnostics.Conditional("DEBUG_LEVEL_ERROR")]
        public static void Error(object format, params object[] paramList)
        {
            if (format is string)
                Debug.LogError(string.Format(format as string, paramList));
            else
                Debug.LogError(format);
        }
        [System.Diagnostics.Conditional("UNITY_EDITOR")]
        [System.Diagnostics.Conditional("DEBUG_LEVEL_LOG")]
        public static void Assert(bool condition)
        {
            Assert(condition, string.Empty, true);
        }
        [System.Diagnostics.Conditional("UNITY_EDITOR")]
        [System.Diagnostics.Conditional("DEBUG_LEVEL_LOG")]
        public static void Assert(bool condition, string assertString)
        {
            Assert(condition, assertString, false);
        }
        [System.Diagnostics.Conditional("UNITY_EDITOR")]
        [System.Diagnostics.Conditional("DEBUG_LEVEL_LOG")]
        public static void Assert(bool condition, string assertString, bool pauseEditorOnFail)
        {
            if (!condition)
            {
                Debug.LogError("assert failed! "   assertString);
                if (pauseEditorOnFail) Debug.Break();
            }
        }
    }
}

原文链接

著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

如社区发表内容存在侵权行为,您可以点击这里查看侵权投诉指引

游戏学院公众号二维码
腾讯游戏学院
微信公众号

提供更专业的游戏知识学习平台