You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/Feel/MMTools/Editor/MMMaintenance/MMLockInspector.cs

26 lines
915 B
C#

3 months ago
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// A simple class that lets you lock the current inspector by pressing ctrl (or cmd) + L
/// Pressing the same shortcut again unlocks the
/// </summary>
public class MMLockInspector : MonoBehaviour
{
[MenuItem("Tools/More Mountains/Lock Inspector %l")]
static public void LockInspector()
{
Type inspectorType = typeof(Editor).Assembly.GetType("UnityEditor.InspectorWindow");
EditorWindow inspectorWindow = EditorWindow.GetWindow(inspectorType);
PropertyInfo isLockedPropertyInfo = inspectorType.GetProperty("isLocked", BindingFlags.Public | BindingFlags.Instance);
bool state = (bool)isLockedPropertyInfo.GetGetMethod().Invoke(inspectorWindow, new object[] { });
isLockedPropertyInfo.GetSetMethod().Invoke(inspectorWindow, new object[] { !state });
}
}
}