GameStateManager
Central controller for game flow, responsible for managing transitions between initialization, login UI states, and various minigame modes. It serves as a hub that integrates services like multiplayer, orchestration, audio configuration, analytics, and scene management.
public class GameStateManager : MonoBehaviour, INetworkRunnerCallbacks, IInjectorReceivable
Overview
The GameStateManager acts as a state machine manager for all client and server gameplay flows. It coordinates between multiple subsystems using dependency injection ([Inject]) and provides access to services via [Provide] properties (see: Dependency Injection).
It transitions between game states, handles user profile updates, manages reconnection flows, and configures visual/audio preferences.
Key Properties
states
Type: List<GameBaseState>
Description: All potential game states managed by this class.
currentState
Type: GameBaseState
Description: The active game state at runtime.
GameOrchestrator
Type: GameOrchestrator
Description: Provided via [Inject]—central handler for orchestrated game logic.
MultiplayerService
Type: MultiplayerService
Description: Provided via [Inject]—networking interface used for player sessions and server communications.
Scene and Transition Utilities
GetDefaultState()– returns the designated default state.GetStateByServerScene(scene)– finds state matching a scene's matchmaking queue.RequestState<T>()– changes the current state to a specificGameBaseState.RequestServer(scene)– initiates server connection and local player start.LoadBuildSpace(scene)– transitions into a builder-focused state.LoadPublicGameSpace(scene)– placeholder for entering public/shared environments.
Audio & Graphics Settings (Loaders)
These are currently stubbed out and read from
SaveLoadSystem.
LoadRenderScale()LoadQualityLevel()LoadScreenResolution()LoadTextureSize()LoadFPSCap()LoadSoundSettings()
Push Notification Scheduling
Preconfigured retention notifications (_3day_retention, _5day_retention, _7day_retention) with randomized titles and bodies to encourage user return.
RetentionRandomPushTitleRetentionRandomPushBody
Unity Lifecycle Hooks
Awake(),Start(),Update(),FixedUpdate(),OnDestroy(),OnApplicationFocus(),OnApplicationQuit()
NetworkRunner Callback Implementation
Implements full INetworkRunnerCallbacks to comply with Fusion networking:
OnPlayerJoined,OnShutdown,OnConnectFailed,OnDisconnectedFromServer, etc.
Dependency Injection
This component makes use of
[Inject]fields and[Provide]properties—see Inject and Provide for a complete breakdown of usage and lifecycle.
Usage Example
await GameStateManager.Local.RequestState<OpenLobbyState>();