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 EditorGameFocus

Attributes: [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:

  1. Editor phase ([InitializeOnLoad] static constructor):

    • Resolves the UnityEditor.GameView type via reflection

    • Subscribes to EditorWindow.windowFocusChanged to track the last non-GameView window

  2. Runtime phase ([RuntimeInitializeOnLoadMethod]):

    • Injects a PlayerLoopSystem at POST_LATE_UPDATE (prepended) to poll for Escape key input

    • This 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 lastFocusedWindow exists → focuses that window

  • Otherwise → falls back to SceneView

Quick Lookup

Goal
How

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

Field
Type
Access
Description

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

circle-exclamation
circle-exclamation
circle-exclamation

See Also

Last updated