收到日志消息时触发的事件。
无论该消息是否来自主线程,都将触发此事件。这意味着处理程序代码必须具有线程安全性。可以从不同的线程调用该代码,也可以并行调用该代码。确保只有已允许非主线程调用的处理程序才能访问 Unity API。
Note: It is not necessary to subscribe to both Application.logMessageReceived and Application.logMessageReceivedThreaded
. The multi-threaded variant will also be called for messages on the main thread.
另请参阅:Application.logMessageReceived。
using UnityEngine; using System.Collections;
public class ExampleClass : MonoBehaviour { public string output = ""; public string stack = "";
void OnEnable() { Application.logMessageReceivedThreaded += HandleLog; }
void OnDisable() { Application.logMessageReceivedThreaded -= HandleLog; }
void HandleLog(string logString, string stackTrace, LogType type) { output = logString; stack = stackTrace; } }