Last active
August 18, 2021 15:43
-
-
Save Valeour/967f022d0d354eb0f0ef0f3bf804f54a to your computer and use it in GitHub Desktop.
Toggle Unity Inspector between Debug and Normal.
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 characters
/// Debug Toggle by Chance Millar 18/11/18 | |
using System; | |
using System.Reflection; | |
using UnityEditor; | |
// Used to provide a shortcut for toggling Unity's Debug/Normal mode on the inspector. | |
// Place inside a folder named "Editor" for Unity to compile correctly. | |
// Will only work on a single inspector window, not all of them. | |
// Use Ctrl/Cmd+G to activate. Refer to the Shortcut manager to change the shortcut. | |
// Will break if Unity changes their API. | |
public class DebugToggle | |
{ | |
private static readonly Assembly kAssembly = Assembly.GetAssembly( typeof(EditorWindow) ); | |
private static readonly Type kInspectorWindow = kAssembly.GetType( "UnityEditor.InspectorWindow" ); | |
private static readonly PropertyInfo kInspectorMode = kInspectorWindow.GetProperty("inspectorMode"); | |
private static readonly MethodInfo kInspectorModeSet = kInspectorMode.GetSetMethod(); | |
private static readonly MethodInfo kInspectorModeGet = kInspectorMode.GetGetMethod(); | |
[MenuItem("Edit/Toggle Debug %g")] | |
public static void ToggleInspectorDebug() | |
{ | |
EditorWindow window = EditorWindow.GetWindow( kInspectorWindow ); | |
InspectorMode mode = (InspectorMode)kInspectorModeGet.Invoke(window, null); | |
InspectorMode swap = (InspectorMode)(1-(int)mode); | |
kInspectorModeSet.Invoke( window, new object[] { swap } ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment