Version: 2020.3

Application.logMessageReceivedThreaded

切换到手册

描述

收到日志消息时触发的事件。

无论该消息是否来自主线程,都将触发此事件。这意味着处理程序代码必须具有线程安全性。可以从不同的线程调用该代码,也可以并行调用该代码。确保只有已允许非主线程调用的处理程序才能访问 Unity API。

注意:不必同时订阅 Application.logMessageReceivedApplication.logMessageReceivedThreaded。还会调用多线程变体以获取主线程的消息。

另请参阅: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; } }