Class LauncherWindow
Owns the launcher's window mode for the lifetime of the process: puts the window into the launcher's windowed size before the first scene loads, keeps the display's native mode for the hand-off to the game, and returns the window to the launcher's size before a clean exit so the next launch opens in it.
public static class LauncherWindow
- Inheritance
-
LauncherWindow
- Inherited Members
Remarks
Why this is not done in the launcher's Awake. A standalone player creates its
window before any script runs, in the mode Unity remembered from the previous exit. The
launcher and the game share one process and the process always exits from the game, in
fullscreen, so every launch after the first opened fullscreen, played the Unity splash
screen fullscreen, loaded two addressable scenes, and only then shrank to the launcher's
size when ClientLauncher.Awake ran (issue #221). Requesting the launcher size from a
UnityEngine.RuntimeInitializeLoadType.BeforeSceneLoad hook corrects it during the splash
screen's first frame instead, and does so whatever mode the window was created in — so it
holds after a crash, which the exit-time restore below cannot.
The exit-time restore is what makes a normal launch flash-free rather than one-frame-flash: Unity records the mode in force at a clean quit, so returning to the launcher's windowed size a frame before the process ends means the next window is created in it. A crash skips this and the boot-time correction above carries that launch.
Standalone builds only. The editor and WebGL boot straight into the post-boot scene, so there is no launcher to size for; a headless server has no window at all. On those paths IsActive stays false and the saved game display mode is applied at boot as before.
Fields
DefaultHeight
Launcher window height the first time it opens on a machine.
public const int DefaultHeight = 768
Field Value
DefaultWidth
Launcher window width the first time it opens on a machine.
public const int DefaultWidth = 1024
Field Value
Remarks
Matches the Player Settings default window so a fresh install's first window, splash screen included, is already the launcher's size.
MinHeight
public const int MinHeight = 360
Field Value
MinWidth
Smallest window the launcher layout stays usable at. Mirrors the min-width and min-height in UILauncher.uss — below this the footer buttons start to be squeezed.
public const int MinWidth = 480
Field Value
Properties
IsActive
True when this process booted through the launcher and this class has sized the window for it. False in the editor, on WebGL and on a server.
public static bool IsActive { get; }
Property Value
NativeModeCaptured
True when the display's own mode was read successfully at boot.
public static bool NativeModeCaptured { get; }
Property Value
NativeRefreshRate
The display's refresh rate as reported before the window was first resized.
public static RefreshRate NativeRefreshRate { get; }
Property Value
- RefreshRate
NativeSize
The display's resolution as reported before the window was first resized.
public static Vector2Int NativeSize { get; }
Property Value
- Vector2Int
Methods
ApplyLauncherMode()
Puts the window into the launcher's windowed size, unless it is already there.
public static void ApplyLauncherMode()
Remarks
Idempotent so it can be requested at boot and again from the launcher's Awake as a fallback: the second call finds the mode already in force and issues nothing, so the player never sees a second resize.
ResolveWindowSize()
The size the launcher window should open at: the size the player last used, or the default the first time.
public static Vector2Int ResolveWindowSize()
Returns
- Vector2Int
Remarks
The window is resizable, so pinning it to a fixed size on every launch would undo the player's choice each time. The stored size is clamped against the current display by GetWindowSize(int, int), which matters when a window saved on a larger monitor is restored on a smaller one.
SetScreenResolution(int, int, FullScreenMode, RefreshRate)
Applies a display mode, tolerating a refresh rate this display will not accept.
public static void SetScreenResolution(int width, int height, FullScreenMode mode, RefreshRate rate)
Parameters
Remarks
Some display configurations report a refresh rate Screen.SetResolution then
rejects. The resolution and mode are what matter here, so a rejected rate falls back
to 60 Hz rather than leaving the window at whatever it happened to be.