ソースコード
using System.Reflection;
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public static class Example
{
static Example()
{
Editor.finishedDefaultHeaderGUI += OnGUI;
}
private static void OnGUI( Editor editor )
{
EditorGUILayout.BeginHorizontal();
if ( GUILayout.Button( "Lock" ) )
{
var tracker = ActiveEditorTracker.sharedTracker;
tracker.isLocked = !tracker.isLocked;
tracker.ForceRebuild();
}
if ( GUILayout.Button( "Debug" ) )
{
var window = Resources.FindObjectsOfTypeAll<EditorWindow>();
var inspectorWindow = ArrayUtility.Find( window, c => c.GetType().Name == "InspectorWindow" );
if ( inspectorWindow == null ) return;
var inspectorType = inspectorWindow.GetType();
var tracker = ActiveEditorTracker.sharedTracker;
var isNormal = tracker.inspectorMode == InspectorMode.Normal;
var methodName = isNormal ? "SetDebug" : "SetNormal";
var attr = BindingFlags.NonPublic | BindingFlags.Instance;
var methodInfo = inspectorType.GetMethod( methodName, attr );
methodInfo.Invoke( inspectorWindow, null );
tracker.ForceRebuild();
}
EditorGUILayout.EndHorizontal();
}
}
使用例