将Unity的Debug.Log输出到屏幕

using UnityEngine;

class TestConsole : MonoBehaviour
{
    void OnEnable()
    {
        Application.logMessageReceived += HandleLog;
    }

    void OnDisable()
    {
        Application.logMessageReceived -= HandleLog;
    }

    void OnDestroy()
    {
        Application.logMessageReceived -= HandleLog;
    }

    /// 
    /// Records a log from the log callback.
    /// 
    /// Message.
    /// Trace of where the message came from.
    /// Type of message (error, exception, warning, assert).
    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)