- 【前言】
- 【放出代码】
- Debug.SuperLog接口封装
- 简单调用测试
- 测试输出结果
我们在使用脚本语言(lua或者python)之后会发现有个常用的输出log方法,他的原型大致为
--原型,其中...是传递的可变参数列表 --print(...) --举个例子 print(1,"two",true) -->1 two true
以上lua代码输出了1 two true,对于同时输出多个对象就可以方便的打log。
而Unity中的UnityEngine.Debug.Log和MonoBehaviour.print都只有一个参数的重载,所以我们用C#中实现像lua中print(…)一样可以传递多个对象参数,然后整条输出log。
public class Debug
{
///
/// 多参数长log输出
///
/// 输出结果是否带有类型
/// 输出对象,多参数
public static void LongLog(bool isShowType,params object[] obj)
{
string deubgObject = null;
foreach (var item in obj)
{
if (isShowType)
{
deubgObject += item.GetType().Name + ":" + item + " ";
}
else
{
deubgObject += item + " ";
}
}
if (deubgObject == null)
{
deubgObject = " LongLog ( params object[] = null? )";
}
UnityEngine.Debug.Log(deubgObject);
}
}
简单调用测试
private void Start()
{
string par1 = "string1";
int par2 = 123;
bool par3 = true;
GameObject par4 = this.gameObject;
Debug par5 = new Debug();
Debug.SuperLog(true,par1,par2,par3,par4,par5);//调用入口
}
测试输出结果



