Skip to main content

GameBaseState

Abstract base class for defining modular game states in the m00m state machine system. Intended to be inherited by all concrete state implementations within the GameStateManager.

public abstract class GameBaseState : MonoBehaviour

Purpose

  • Provides a consistent interface and lifecycle for gameplay, menu, and server states
  • Manages enter/exit transitions with priority and condition checks
  • Integrates with Firebase auth updates via overridable hooks

Core Properties

bool IsDefaultState

Indicates whether this state should be treated as the default during initialization.

int priority

Used internally or by extensions to weight transition or execution order.

GameStateManager _manager

Reference to the managing GameStateManager.


Key Methods

abstract bool CanExitState()

Determines if this state is currently eligible to be exited. Must be implemented by subclasses.

virtual void EnterState()

Called when this state becomes active. Override to implement entry logic.

virtual async Task ExitState(bool allowRejoin = false)

Called when this state is being exited. Supports optional rejoin behavior.

virtual void UpdateFromState()

Frame-update hook while this state is active.

virtual void ApplicationFocusChanged(bool hasFocus)

Optional hook for app focus gain/loss handling.

virtual void UserUpdated(FirebaseUser user)

Hook to receive updates from Firebase user session changes.

virtual void ProfileUpdated(FireAuth.m00mUser user)

Hook to receive changes in the in-game player profile.

virtual bool CanEnterState()

Optional override to gate whether this state can be entered from another state.


Transitions

Each GameBaseState can have conditional transitions to other states:

public Dictionary<GameBaseState, FuncPredicate> transitions

void AddTransition(GameBaseState targetState, FuncPredicate predicate)

Registers a conditional transition to another state.

GameBaseState CheckTransitions()

Evaluates all transitions and returns a valid next state if one passes.


Usage Example

public class OpenLobbyState : GameBaseState
{
public override bool CanExitState() => AllPlayersReady;

public override void EnterState()
{
ShowLobbyUI();
}

public override async Task ExitState(bool allowRejoin = false)
{
await SaveLobbyStateAsync();
}
}

Registered into a GameStateManager like:

_downloadAssetsState.AddTransition(_openLobby, new FuncPredicate(() => assetsReady));

This base class enables a composable, event-aware approach to gameplay state management that cleanly separates behavior logic from flow control.