使用Application.RegisterLogCallback来调试程序

来源:互联网 发布:服务器架设软件 编辑:程序博客网 时间:2024/05/16 04:55

该方法可以监听到unity中所有的log消息,然后你可以选择保存到文件中或者显示到gui上做调试来用。

通过LogType来判断处理哪些类型的消息需要被保存或显示。

LogType如下:

Error

LogType used for Errors.

Assert

LogType used for Asserts. (These indicate an error inside Unity itself.)

Warning

LogType used for Warnings.

Log

LogType used for regular log messages.

Exception

LogType used for Exceptions.


unity3d提供的例子:

using UnityEngine;using System.Collections;public class example : MonoBehaviour {    public string output = "";    public string stack = "";    void OnEnable() {        Application.RegisterLogCallback(HandleLog);    }    void OnDisable() {        Application.RegisterLogCallback(null);    }    void HandleLog(string logString, string stackTrace, LogType type) {        output = logString;        stack = stackTrace;    }}




原创粉丝点击