Last active
October 9, 2025 14:56
-
-
Save adammyhre/4754f731a93bf1cab0d1385ccfa23642 to your computer and use it in GitHub Desktop.
Revisions
-
adammyhre revised this gist
Jul 1, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ /// <summary> /// Toggles the Inspector lock state and the Constrain Proportions lock state. /// </summary> public static class LockInspector { static readonly MethodInfo flipLocked; static readonly PropertyInfo constrainProportions; const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance; -
adammyhre revised this gist
May 16, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,7 @@ class LockInspector : MonoBehaviour { const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance; static LockInspector() { // Cache static MethodInfo and PropertyInfo for performance #if UNITY_2023_2_OR_NEWER var editorLockTrackerType = typeof(EditorGUIUtility).Assembly.GetType("UnityEditor.EditorGUIUtility+EditorLockTracker"); flipLocked = editorLockTrackerType.GetMethod("FlipLocked", bindingFlags); -
adammyhre revised this gist
May 16, 2024 . 1 changed file with 7 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,15 +1,17 @@ using System.Reflection; using UnityEditor; using UnityEngine; /// <summary> /// Toggles the Inspector lock state and the Constrain Proportions lock state. /// </summary> class LockInspector : MonoBehaviour { static readonly MethodInfo flipLocked; static readonly PropertyInfo constrainProportions; const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance; static LockInspector() { // Cache static MethodInfo and PropertyInfo objects #if UNITY_2023_2_OR_NEWER var editorLockTrackerType = typeof(EditorGUIUtility).Assembly.GetType("UnityEditor.EditorGUIUtility+EditorLockTracker"); flipLocked = editorLockTrackerType.GetMethod("FlipLocked", bindingFlags); @@ -28,8 +30,8 @@ public static void Lock() { flipLocked?.Invoke(lockTracker, new object[] { }); } #else // Old approach for Unity versions before 2023.2 ActiveEditorTracker.sharedTracker.isLocked = !ActiveEditorTracker.sharedTracker.isLocked; #endif // Constrain Proportions lock for all versions including Unity 6 @@ -41,6 +43,7 @@ public static void Lock() { } ActiveEditorTracker.sharedTracker.ForceRebuild(); } [MenuItem("Edit/Toggle Inspector Lock %l", true)] public static bool Valid() { return ActiveEditorTracker.sharedTracker.activeEditors.Length != 0; -
adammyhre revised this gist
May 16, 2024 . 1 changed file with 21 additions and 16 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,31 @@ using System; using System.Reflection; using UnityEditor; using UnityEngine; class LockInspector : MonoBehaviour { static readonly MethodInfo flipLocked; static readonly PropertyInfo constrainProportions; const BindingFlags bindingFlags = BindingFlags.NonPublic | BindingFlags.Instance; static LockInspector() { // Cache MethodInfo and PropertyInfo objects #if UNITY_2023_2_OR_NEWER var editorLockTrackerType = typeof(EditorGUIUtility).Assembly.GetType("UnityEditor.EditorGUIUtility+EditorLockTracker"); flipLocked = editorLockTrackerType.GetMethod("FlipLocked", bindingFlags); #endif constrainProportions = typeof(Transform).GetProperty("constrainProportionsScale", bindingFlags); } [MenuItem("Edit/Toggle Inspector Lock %l")] public static void Lock() { #if UNITY_2023_2_OR_NEWER // New approach for Unity 2023.2 and above, including Unity 6 var inspectorWindowType = typeof(Editor).Assembly.GetType("UnityEditor.InspectorWindow"); foreach (var inspectorWindow in Resources.FindObjectsOfTypeAll(inspectorWindowType)) { var lockTracker = inspectorWindowType.GetField("m_LockTracker", bindingFlags)?.GetValue(inspectorWindow); flipLocked?.Invoke(lockTracker, new object[] { }); } #else // Old approach for Unity versions before 2023.2 @@ -22,20 +34,13 @@ public static void Lock() { // Constrain Proportions lock for all versions including Unity 6 foreach (var activeEditor in ActiveEditorTracker.sharedTracker.activeEditors) { if (activeEditor.target is not Transform target) continue; var currentValue = (bool) constrainProportions.GetValue(target, null); constrainProportions.SetValue(target, !currentValue, null); } ActiveEditorTracker.sharedTracker.ForceRebuild(); } [MenuItem("Edit/Toggle Inspector Lock %l", true)] public static bool Valid() { return ActiveEditorTracker.sharedTracker.activeEditors.Length != 0; -
adammyhre revised this gist
May 16, 2024 . 1 changed file with 25 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,31 +2,42 @@ using UnityEditor; using UnityEngine; class LockInspector : MonoBehaviour { [MenuItem("Edit/Toggle Inspector Lock %l")] public static void Lock() { #if UNITY_2023_2_OR_NEWER // New approach for Unity 2023.2 and above, including Unity 6 var editorLockTrackerType = typeof(EditorGUIUtility).Assembly.GetType("UnityEditor.EditorGUIUtility+EditorLockTracker"); var inspectorWindowType = typeof(Editor).Assembly.GetType("UnityEditor.InspectorWindow"); foreach (var inspectorWindow in Resources.FindObjectsOfTypeAll(inspectorWindowType)) { var lockTracker = inspectorWindowType.GetField("m_LockTracker", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(inspectorWindow); var flipLockedMethod = editorLockTrackerType.GetMethod("FlipLocked", BindingFlags.NonPublic | BindingFlags.Instance); flipLockedMethod?.Invoke(lockTracker, new object[] { }); } #else // Old approach for Unity versions before 2023.2 ActiveEditorTracker.sharedTracker.isLocked = !ActiveEditorTracker.sharedTracker.isLocked; #endif // Constrain Proportions lock for all versions including Unity 6 foreach (var activeEditor in ActiveEditorTracker.sharedTracker.activeEditors) { if (activeEditor.target is not Transform) continue; var transform = (Transform) activeEditor.target; var propInfo = transform.GetType().GetProperty("constrainProportionsScale", BindingFlags.NonPublic | BindingFlags.Instance); if (propInfo == null) continue; var currentValue = (bool) propInfo.GetValue(transform, null); propInfo.SetValue(transform, !currentValue, null); } ActiveEditorTracker.sharedTracker.ForceRebuild(); } [MenuItem("Edit/Toggle Inspector Lock %l", true)] public static bool Valid() { return ActiveEditorTracker.sharedTracker.activeEditors.Length != 0; } } -
adammyhre created this gist
Mar 12, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ using System.Reflection; using UnityEditor; using UnityEngine; public class LockInspector { [MenuItem("Edit/Lock Inspector %l")] public static void Lock () { ActiveEditorTracker.sharedTracker.isLocked = !ActiveEditorTracker.sharedTracker.isLocked; foreach (var activeEditor in ActiveEditorTracker.sharedTracker.activeEditors) { if (activeEditor.target is not Transform) continue; var transform = (Transform) activeEditor.target; var propInfo = transform.GetType().GetProperty("constrainProportionsScale", BindingFlags.NonPublic | BindingFlags.Instance); if (propInfo == null) continue; var value = (bool) propInfo.GetValue(transform, null); propInfo.SetValue(transform, !value, null); } ActiveEditorTracker.sharedTracker.ForceRebuild(); } [MenuItem("Edit/Lock Inspector %l", true)] public static bool Valid() { return ActiveEditorTracker.sharedTracker.activeEditors.Length != 0; } }