Version: 2023.1

Application.logMessageReceivedThreaded

切换到手册

描述

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

无论该消息是否来自主线程,都将触发此事件。这意味着处理程序代码必须具有线程安全性。可以从不同的线程调用该代码,也可以并行调用该代码。确保只有已允许非主线程调用的处理程序才能访问 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; } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961