ソースコード
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
public class Example : MonoBehaviour
{
private readonly List<string> m_conditions = new List<string>();
private void Awake()
{
Application.logMessageReceivedThreaded += ( condition, trace, type ) =>
{
m_conditions.Add( condition );
};
}
private void OnGUI()
{
if ( GUILayout.Button( "Log" ) )
{
Debug.Log( "ピカチュウ" );
}
if ( GUILayout.Button( "Log" ) )
{
var attrs = BindingFlags.GetField | BindingFlags.Static | BindingFlags.NonPublic;
var type = typeof( Application );
var field = type.GetField( "s_LogCallbackHandlerThreaded", attrs );
var @delegate = ( Delegate ) field.GetValue( null );
field.SetValue( null, null );
Debug.Log( "ピカチュウ" );
field.SetValue( null, @delegate );
}
foreach ( var condition in m_conditions )
{
GUILayout.Label( condition );
}
}
}