Last active
May 27, 2018 10:12
-
-
Save founderio/716c0af4fe0dbc022cde55b68c240bdf to your computer and use it in GitHub Desktop.
Unity Editor global hotkeys as of 2018.1
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
[InitializeOnLoad] | |
public static class StaticEvents { | |
static StaticEvents() { | |
FieldInfo globalEventHandler = typeof(EditorApplication).GetField("globalEventHandler", BindingFlags.Static | BindingFlags.NonPublic); | |
var value = (EditorApplication.CallbackFunction)globalEventHandler.GetValue(null); | |
value += () => { | |
// Triggers for EVERYTHING | |
var e = Event.current; | |
if (e.type == EventType.KeyDown) { | |
if (e.keyCode == KeyCode.LeftShift || e.keyCode == KeyCode.RightShift) { | |
Debug.Log("SHIFT DOWN EVERYBODY!! - globalEventHandler"); | |
} | |
} | |
}; | |
globalEventHandler.SetValue(null, value); | |
} | |
} |
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
[InitializeOnLoad] | |
public static class StaticEvents { | |
static StaticEvents() { | |
EditorApplication.hierarchyWindowItemOnGUI += (int instanceID, Rect selectionRect) => { | |
// Triggered only when a hierarchy item is selected + the hierarchy is focused | |
if (instanceID == Selection.activeInstanceID) { | |
var e = Event.current; | |
if (e.type == EventType.KeyDown) { | |
if (e.keyCode == KeyCode.LeftShift) { | |
Debug.Log("SHIFT DOWN EVERYBODY!! - hierarchyWindowItemOnGUI"); | |
} | |
} | |
} | |
}; | |
} | |
} |
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
[InitializeOnLoad] | |
public static class StaticEvents { | |
static StaticEvents() { | |
EditorApplication.modifierKeysChanged += () => { | |
// No events, only "something" changed | |
}; | |
} | |
} |
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
[InitializeOnLoad] | |
public static class StaticEvents { | |
static StaticEvents() { | |
SceneView.onSceneGUIDelegate += view => { | |
// Mentioned in one thread: Get a control ID to not mess with other controls | |
// Does not seem to actually work in Unity 2018.1 on Linux - but theoretically should work | |
int controlID = GUIUtility.GetControlID(FocusType.Keyboard); | |
if (Event.current.GetTypeForControl(controlID) == EventType.KeyDown) { | |
if (Event.current.shift) { | |
Debug.Log("SHIFT DOWN EVERYBODY!! - onSceneGUIDelegate with Control ID A"); | |
// Causes repaint & accepts event has been handled | |
Event.current.Use(); | |
} | |
if (Event.current.keyCode == KeyCode.LeftShift) { | |
Debug.Log("SHIFT DOWN EVERYBODY!! - onSceneGUIDelegate with Control ID B"); | |
// Causes repaint & accepts event has been handled | |
Event.current.Use(); | |
} | |
} | |
}; | |
} | |
} |
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
[InitializeOnLoad] | |
public static class StaticEvents { | |
static StaticEvents() { | |
SceneView.onSceneGUIDelegate += view => { | |
// Same thing as variantA, but just directly process the event and not use it (watch only) | |
// Does not seem to actually work in Unity 2018.1 on Linux - but theoretically should work | |
var e = Event.current; | |
if (e == null) { | |
return; | |
} | |
if (e.type == EventType.KeyDown) { | |
if (e.keyCode == KeyCode.LeftShift) { | |
Debug.Log("SHIFT DOWN EVERYBODY!! - onSceneGUIDelegate"); | |
} | |
} | |
if (e.modifiers.HasFlag(EventModifiers.Shift)) { | |
if (e.keyCode == KeyCode.LeftShift) { | |
Debug.Log("SHIFT DOWN EVERYBODY!! - onSceneGUIDelegate as Modifier"); | |
} | |
} | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment