Skip to main content

InitializeApplicationState

The InitializeApplicationState class is an entry-point state in the game flow that handles early bootstrapping for both client and server instances. It performs service initialization (Unity, Firebase, Vivox), splash UI loading, dependency injection, and transitions into the first functional menu state once all setup completes.


๐Ÿงฉ Overviewโ€‹

public class InitializeApplicationState : GameBaseState, IInjectorReceivable

Implements the base game state flow and is injectable via dependency injection.


โš™๏ธ Initialization Flowโ€‹

EnterState()โ€‹

Begins the initialization process:

  • For servers: runs InitializeServer() (minimal/no-op).
  • For clients: starts splash UI and InitializeClient() process.
  • Starts PrewarmUI() to asynchronously warm up the next state's UI components.

๐Ÿ–ฅ Client Setup Logicโ€‹

InitializeClient()โ€‹

Bootstraps Unity services, auth, and analytics:

  1. Starts fill animation for splash progress bar.
  2. Ensures internet connectivity.
  3. Initializes Unity Services with environment and Vivox credentials.
  4. Authenticates anonymously if not already signed in.
  5. Starts Unity Analytics collection.
  6. Starts AppsFlyer (or shows tracking consent for iOS).
  7. Initializes orchestrator and user profile via GetGameOrchestrator().
  8. Flags initialization complete and transitions to the next state.

๐Ÿงช Server Setupโ€‹

InitializeServer()โ€‹

Currently minimal; immediately transitions to next state.


๐ŸŽจ Splash UI Handlingโ€‹

  • splashLoadingScreen: GameObject shown during initialization.
  • splashLoadingFill: MPUIKIT image with animated fill progress.
  • fillProgressRoutine: Coroutine that updates fill amount visually.

Fill amount is incrementally updated to simulate progress:

IEnumerator FillProgress()

๐Ÿ”„ State Transition Logicโ€‹

ContinueToNextState()โ€‹

Checks that both initializationComplete and injectionsComplete are true, then requests the next state using:

await _manager.RequestState(NextState);

๐Ÿงฌ Injection & Orchestrationโ€‹

InjectionCompleted()โ€‹

Called when all required dependencies are injected. Sets injectionsComplete = true, bumps splash fill, and reinvokes orchestrator initialization.


โœ… Can Exitโ€‹

Only when both initialization and injection are complete:

public override bool CanExitState() => initializationComplete && injectionsComplete;

๐Ÿง  Summaryโ€‹

InitializeApplicationState is the gateway into the m00m runtime. It ensures that all platform services are ready, UI is staged, and orchestration is aligned before allowing the player to progress. This design guarantees robust first-time setup across both client and server builds.