I’ve done a little bit of searching and can’t find a good, up to date, shortcut list that has this one listed, if it even exists.
I’m find myself constantly using the lock icon for the inspector so I keep the inspector locked on a Game Object and select a different object. Is there a shortcut key to toggle this option on and off so I don’t have to keep moving my mouse to that corner of the screen?
Thanks a lot! I wonder why the lock command hasn’t been exposed. It’s really useful when displaying Handles in the OnSceneGUI. If you clic just a bit off you loose the gameObject selection and you have to select it again. It can get frustrating.
very useful . thank you Abomb.
nb : for my students, simply add an “Editor” folder in Project et place this code. … nothing else
Locking and unlocking by pressing Alt + Q
Is this still working in 2018.2+? I can’t get this to work. I’m copying the code exactly and have made sure there are no key conflicts. Clicking in the Tools menu doesn’t work either.
EDIT: Beware of having 2 inspectors. My second one was hidden but that was the one being locked and unlocked.
Here’s my version of Abomb’s post above. Hover mouse over the inspector you want to lock/unlock then press the hotkey. If you’re testing this on an empty inspector it won’t work. You have to click a game object first, which makes sense, but I kept testing various inspector locking hotkey implementations on an empty inspector and the lock wasn’t changing. Stupid me.
using System;
using System.Reflection;
using UnityEditor;
public class InspectorLockToggle
{
[MenuItem("Tools/Toggle Lock &q")]
static void ToggleInspectorLock() // Inspector must be inspecting something to be locked
{
EditorWindow inspectorToBeLocked = EditorWindow.mouseOverWindow; // "EditorWindow.focusedWindow" can be used instead
if (inspectorToBeLocked != null && inspectorToBeLocked.GetType().Name == "InspectorWindow")
{
Type type = Assembly.GetAssembly(typeof(Editor)).GetType("UnityEditor.InspectorWindow");
PropertyInfo propertyInfo = type.GetProperty("isLocked");
bool value = (bool)propertyInfo.GetValue(inspectorToBeLocked, null);
propertyInfo.SetValue(inspectorToBeLocked, !value, null);
inspectorToBeLocked.Repaint();
}
}
}
using System;
using System.Reflection;
using UnityEditor;
namespace EditorImprovements
{
public class EditorUtilities
{
[MenuItem("Tools/Clear Console &c")]
static void ClearConsole()
{
// This simply does "LogEntries.Clear()" the long way:
var logEntries = Type.GetType("UnityEditor.LogEntries,UnityEditor.dll");
var clearMethod = logEntries.GetMethod("Clear", BindingFlags.Static | BindingFlags.Public);
clearMethod.Invoke(null,null);
}
[MenuItem("Tools/Toggle Inspector Lock (shortcut) &e")]
static void SelectLockableInspector()
{
EditorWindow inspectorToBeLocked = EditorWindow.mouseOverWindow; // "EditorWindow.focusedWindow" can be used instead
if (inspectorToBeLocked != null && inspectorToBeLocked.GetType().Name == "InspectorWindow")
{
Type type = Assembly.GetAssembly(typeof(UnityEditor.Editor)).GetType("UnityEditor.InspectorWindow");
PropertyInfo propertyInfo = type.GetProperty("isLocked");
bool value = (bool)propertyInfo.GetValue(inspectorToBeLocked, null);
propertyInfo.SetValue(inspectorToBeLocked, !value, null);
inspectorToBeLocked.Repaint();
}
}
[MenuItem("Tools/Toggle Inspector Mode &d")]//Change the shortcut here
static void ToggleInspectorDebug()
{
EditorWindow targetInspector = EditorWindow.mouseOverWindow; // "EditorWindow.focusedWindow" can be used instead
if (targetInspector != null && targetInspector.GetType().Name == "InspectorWindow")
{
Type type = Assembly.GetAssembly(typeof(UnityEditor.Editor)).GetType("UnityEditor.InspectorWindow"); //Get the type of the inspector window to find out the variable/method from
FieldInfo field = type.GetField("m_InspectorMode", BindingFlags.NonPublic | BindingFlags.Instance); //get the field we want to read, for the type (not our instance)
InspectorMode mode = (InspectorMode)field.GetValue(targetInspector); //read the value for our target inspector
mode = (mode == InspectorMode.Normal ? InspectorMode.Debug : InspectorMode.Normal); //toggle the value
//Debug.Log("New Inspector Mode: " + mode.ToString());
MethodInfo method = type.GetMethod("SetMode", BindingFlags.NonPublic | BindingFlags.Instance); //Find the method to change the mode for the type
method.Invoke(targetInspector, new object[] {mode}); //Call the function on our targetInspector, with the new mode as an object[]
targetInspector.Repaint(); //refresh inspector
}
}
}
}