Application.logMessageReceived

切换到手册

描述

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

此事件仅在主线程上触发。可在以下情况下使用该事件:您的处理程序需要访问 Unity API 中仅限主线程使用的部分,或者出于其他原因,您的处理程序不具备线程安全性。

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public string output = ""; public string stack = "";

void OnEnable() { Application.logMessageReceived += HandleLog; }

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

void HandleLog(string logString, string stackTrace, LogType type) { output = logString; stack = stackTrace; } }

Did you find this page useful? Please give it a rating: