-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShortcutExtension.cs
More file actions
30 lines (28 loc) · 1.29 KB
/
ShortcutExtension.cs
File metadata and controls
30 lines (28 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#if UNITY_EDITOR
using System.Linq;
using UnityEditor;
using UnityEditor.ShortcutManagement;
using UnityEngine;
public class ShortcutExtension : MonoBehaviour
{
private const string menuPath = "Custom/ToggleInspectorDebugMode";
private static readonly string shortcutId = $"Main Menu/{menuPath}";
private const KeyCode shortcutKey = KeyCode.F12;
[InitializeOnLoadMethod]
public static void AddShortCut()
{
ShortcutManager.instance.RebindShortcut(shortcutId,new ShortcutBinding(new KeyCombination(shortcutKey)));
}
[MenuItem(menuPath)]
public static void ToggleInspectorDebugMode()
{
var inspectorWindowType = typeof(Editor).Assembly.GetType("UnityEditor.InspectorWindow");
var inspectorWindow = EditorWindow.GetWindow(inspectorWindowType);
var inspectorMode = inspectorWindowType.GetField("m_InspectorMode", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var mode = (int)inspectorMode.GetValue(inspectorWindow);
var method = inspectorWindowType.GetMethod("SetMode",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
method.Invoke(inspectorWindow, new object[] {mode == 0 ? 1 : 0});
}
}
#endif