using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DebugDemo : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Debug.Log(" 一般日志 ");
Debug.LogWarning(" 警告日志 ");
Debug.LogError(" 错误日志 ");
// Player Information
string strPlayerName = "Peter";
int iPlayerHpValue = 32500;
short shPlayerLevel = 10;
long lAdvantureExp = 114514;
Debug.Log("Player Information \nName: " + strPlayerName + " Hp: " + iPlayerHpValue +" Level: " + shPlayerLevel + " Exp: " + lAdvantureExp);
Debug.LogFormat("Player Information \nName: {0}, Hp: {1}, Level: {2}, Exp: {3}", strPlayerName, iPlayerHpValue, shPlayerLevel, lAdvantureExp);
}
}
1 日志生成
我们在开发过程中一般会通过调用 Unity 提供的 Debug 接口来输出日志,最常用到以下方法。
Debug.Log()
Debug.LogWarning()
Debug.LogError()
开发中对某个Scene的某个Object下挂载此C#脚本后,运行得到输出日志
Debug.Log() 生成一般日志
Debug.LogWarning() 生成警告日志
Debug.LogError() 生成错误日志
2 日志输出信息
Debug.Log("\nName: " + strName + " Hp: " + iHpValue +" Level: " + shLevel + " Exp: " + lExp);
Debug.LogFormat("\nName: {0}, Hp: {1}, Level: {2}, Exp: {3}", strName, iHpValue, shLevel, lExp);
针对上述两个日志信息输出方式,使用 Debug.Log() 输出与 Debug.LogFormat() 相比
使用 Debug.LogFormat() 将各个字符串变量填充,避免 Debug.Log() 用 + 将字符串拼接造成内存浪费
声明:
1、欢迎各位读者通过讨论区或私信讨论,如有错误或疏漏恳请读者批评指正,共勉。
2、本文是作者个人的学习总结,转载请注明。
3、该部分随学随用随更。