Skip to main content

OpenLobbyPlayMode

Concrete GameStateWithPlayer implementation for open lobby play mode. It manages UI loading, matchmaking connection, and playtime logging, and coordinates player entry into the shared game space.

public class OpenLobbyPlayMode : GameStateWithPlayer

Purpose

  • Represents the gameplay state when players are in the open lobby
  • Handles player joining, scene-specific UI, and reconnect logic
  • Logs playtime and manages server session lifecycle

Constructor

public OpenLobbyPlayMode(ServerScene _scn, GameStateManager manager)

Initializes the scene reference and attaches the lobby state to the GameStateManager.


Fields

PlayerSettings_SO settings

Holds player preferences, such as FPS cap (optional/unused in current version).

bool localhosted

Whether the session is running in local host mode (e.g., for debugging).

AssetReferenceGameObject _sceneUI

Addressable reference to the UI prefab specific to this scene.

GameObject _sceneUIInstance

Instantiated reference of the scene UI.


Lifecycle Methods

void EnterState()

  • Sets frame rate (target: 60fps)
  • Loads UI prefab if assigned
  • Initiates server matchmaking or local session

async Task ExitState(bool allowRejoin = false)

  • Logs playtime via FireAuth
  • Releases UI prefab instance
  • Requests player disconnect through the Spawner

Scene & Network Utilities

async void LoadSceneUI()

Instantiates _sceneUI as a prefab asynchronously, if not already spawned.

async void RequestServer()

Starts a multiplayer session using GameStateManager.RequestServer.


Input Handling

void UpdateFromState()

Listens for key input (e.g., R key for rejoin) to trigger debug reconnect logic (currently commented out).


Behavior

  • Always returns true from CanExitState(), allowing transitions out of this state.
  • Designed to support both client and server contexts (UNITY_SERVER vs non-server builds).

Example Usage

var lobbyState = new OpenLobbyPlayMode(myScene, GameStateManager.Local);
GameStateManager.Local.RequestState(lobbyState);

This class encapsulates the full lifecycle and multiplayer readiness logic for players entering the open-world lobby state.