using UnityEngine; class TestConsole : MonoBehaviour { void OnEnable() { Application.logMessageReceived += HandleLog; } void OnDisable() { Application.logMessageReceived -= HandleLog; } void OnDestroy() { Application.logMessageReceived -= HandleLog; } /// <summary> /// Records a log from the log callback. /// </summary> /// <param name="message">Message.</param> /// <param name="stackTrace">Trace of where the message came from.</param> /// <param name="type">Type of message (error, exception, warning, assert).</param> void HandleLog(string message, string stackTrace, LogType type) { if (Application.isEditor) return; if (type == LogType.Exception || type == LogType.Error) { NGUIDebug.Log(type.ToString() + ":" + message + "\n stack: " + stackTrace); } else if (type == LogType.Log) { NGUIDebug.Log(message); } } }
文章来源: 将Unity的Debug.Log输出到屏幕