【Unity】常用接口使用学习总结——Debug

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、该部分随学随用随更。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值