Created
June 24, 2020 12:47
-
-
Save CapitanLiteral/02441fe7fd0be7858a63e1b83ee81cff to your computer and use it in GitHub Desktop.
Inspector lock toggle + Inspector rename
This file contains 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 characters
public static class Inspector | |
{ | |
public static void InspectorRename(bool inspector = false) | |
{ | |
EditorWindow windowToBeLocked = EditorWindow.mouseOverWindow; | |
if (windowToBeLocked.GetType().ToString().Equals("UnityEditor.InspectorWindow")) | |
{ | |
if (inspector) | |
{ | |
Texture tex = windowToBeLocked.titleContent.image; | |
windowToBeLocked.title = "Inspector"; | |
windowToBeLocked.titleContent.image = tex; | |
} | |
else | |
{ | |
Texture tex = windowToBeLocked.titleContent.image; | |
MethodInfo dynMethod = windowToBeLocked.GetType() | |
.GetMethod("GetInspectedObject", BindingFlags.NonPublic | BindingFlags.Instance); | |
var inspectedObject = dynMethod.Invoke(windowToBeLocked, null); | |
windowToBeLocked.title = ((GameObject) inspectedObject).name; | |
windowToBeLocked.titleContent.image = tex; | |
} | |
windowToBeLocked.Repaint(); | |
} | |
} | |
[MenuItem("Tools/Inspector rename &r")] | |
public static void InspectorSwitchName() | |
{ | |
EditorWindow windowToBeLocked = EditorWindow.mouseOverWindow; | |
if (windowToBeLocked.GetType().ToString().Equals("UnityEditor.InspectorWindow")) | |
{ | |
if (windowToBeLocked.title != "Inspector") | |
{ | |
Texture tex = windowToBeLocked.titleContent.image; | |
windowToBeLocked.title = "Inspector"; | |
windowToBeLocked.titleContent.image = tex; | |
} | |
else | |
{ | |
Texture tex = windowToBeLocked.titleContent.image; | |
MethodInfo dynMethod = windowToBeLocked.GetType() | |
.GetMethod("GetInspectedObject", BindingFlags.NonPublic | BindingFlags.Instance); | |
var inspectedObject = dynMethod.Invoke(windowToBeLocked, null); | |
windowToBeLocked.title = ((GameObject) inspectedObject).name; | |
windowToBeLocked.titleContent.image = tex; | |
} | |
windowToBeLocked.Repaint(); | |
} | |
} | |
} |
This file contains 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 characters
public static class InspectorLockToggle | |
{ | |
[MenuItem("Tools/Toggle Lock &q")] | |
static void ToggleWindowLock() // Inspector must be inspecting something to be locked | |
{ | |
EditorWindow windowToBeLocked = EditorWindow.mouseOverWindow; // "EditorWindow.focusedWindow" can be used instead | |
if (windowToBeLocked != null && windowToBeLocked.GetType().Name == "InspectorWindow") | |
{ | |
Type type = Assembly.GetAssembly(typeof(UnityEditor.Editor)).GetType("UnityEditor.InspectorWindow"); | |
PropertyInfo propertyInfo = type.GetProperty("isLocked"); | |
bool value = (bool)propertyInfo.GetValue(windowToBeLocked, null); | |
propertyInfo.SetValue(windowToBeLocked, !value, null); | |
windowToBeLocked.Repaint(); | |
if (!value) | |
{ | |
Inspector.InspectorRename(false); | |
} | |
else | |
{ | |
Inspector.InspectorRename(true); | |
} | |
} | |
else if (windowToBeLocked != null && windowToBeLocked.GetType().Name == "ProjectBrowser") | |
{ | |
Type type = Assembly.GetAssembly(typeof(UnityEditor.Editor)).GetType("UnityEditor.ProjectBrowser"); | |
PropertyInfo propertyInfo = type.GetProperty("isLocked", BindingFlags.NonPublic | BindingFlags.Public |BindingFlags.Instance); | |
bool value = (bool)propertyInfo.GetValue(windowToBeLocked, null); | |
propertyInfo.SetValue(windowToBeLocked, !value, null); | |
windowToBeLocked.Repaint(); | |
} | |
else if (windowToBeLocked != null && windowToBeLocked.GetType().Name == "SceneHierarchyWindow") | |
{ | |
Type type = Assembly.GetAssembly(typeof(UnityEditor.Editor)).GetType("UnityEditor.SceneHierarchyWindow"); | |
FieldInfo fieldInfo = type.GetField("m_SceneHierarchy", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); | |
PropertyInfo propertyInfo = fieldInfo.FieldType.GetProperty("isLocked", | |
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); | |
object value = fieldInfo.GetValue(windowToBeLocked); | |
bool value2 = (bool)propertyInfo.GetValue(value); | |
propertyInfo.SetValue(value, !value2, null); | |
windowToBeLocked.Repaint(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment