EditorGameFocus
Internal utility that tracks editor window focus and provides an Escape key shortcut to return focus from the Game View back to the last focused editor window (typically the Scene View).
Definition
Namespace: Paragon.Editor Assembly: Paragon.Editor.dll
[InitializeOnLoad]
internal static class EditorGameFocusAttributes: [InitializeOnLoad] — initializes via static constructor on editor load.
Remarks
When testing in Play Mode, clicking the Game View captures focus and keyboard input. This utility provides a way to escape back to the editor by pressing the Escape key while the Game View is focused.
Dual Initialization
The class initializes in two phases:
Editor phase (
[InitializeOnLoad]static constructor):Resolves the
UnityEditor.GameViewtype via reflectionSubscribes to
EditorWindow.windowFocusChangedto track the last non-GameView window
Runtime phase (
[RuntimeInitializeOnLoadMethod]):Injects a
PlayerLoopSystematPOST_LATE_UPDATE(prepended) to poll for Escape key inputThis runs every frame during Play Mode
Focus Tracking
Every time a window gains focus, OnWindowFocusChanged checks if it is NOT a Game View window. If so, it stores the reference as lastFocusedWindow. This means pressing Escape will always return to the last non-Game window the user was using.
Escape Key Handling
The HandleEscapeInput method runs every frame via the PlayerLoop. When Application.isFocused is true and Input.GetKeyDown(KeyCode.Escape) is detected:
If
lastFocusedWindowexists → focuses that windowOtherwise → falls back to
SceneView
Quick Lookup
Return to editor from Game View
Press Escape while Game View is focused
Fallback window
SceneView (if no previous window was tracked)
PlayerLoop injection point
POST_LATE_UPDATE (prepended)
Fields
gameViewType
Type
private static readonly
Reflected UnityEditor.GameView type for filtering
lastFocusedWindow
EditorWindow
private static
The last non-GameView window that had focus
Methods
Initialize (private static)
Injects the HandleEscapeInput method into the PlayerLoop at POST_LATE_UPDATE.
HandleEscapeInput (private static)
Checks for Escape key press when the application is focused. Returns focus to the last tracked editor window or the Scene View.
OnWindowFocusChanged (private static)
Callback for EditorWindow.windowFocusChanged. Stores the focused window if it is not a Game View.
Common Pitfalls
Internal class — not accessible externally EditorGameFocus is internal static and cannot be accessed or configured from outside the Paragon.Editor assembly. The Escape key behavior is always active during Play Mode.
Escape key may conflict with game input If the game uses the Escape key for its own purposes (e.g., pause menu), this utility will also trigger focus change. The game will still receive the key event, but the Game View will lose focus on the same frame.
PlayerLoop injection requires Play Mode The HandleEscapeInput loop is only active during Play Mode. In Edit Mode, only the window focus tracking is active.
See Also
Utility Overview — utility subsystem
SceneGameView — related Game View feature
PlayerLoopInjector — used for PlayerLoop injection
Last updated