Skip to main content

DynamicInteriorState

A networked game state for dynamically-loaded interiors. Supports flexible session joining, dynamic spawn point logic, and interior-specific UI rendering.

public class DynamicInteriorState : GameStateWithPlayer

Purpose​

  • Loads a specific interior space on demand
  • Interfaces with a DynamicInteriorController to handle player spawn positioning
  • Manages focus-based state transitions and reconnects
  • Handles server session bootstrapping based on the interior ID

Constructor​

public DynamicInteriorState(ServerScene _scn, GameStateManager manager)

Initializes with a scene reference and state manager, passed down to GameStateWithPlayer.


Fields​

string requestedInteriorID​

ID of the target interior to load. Set via RequestInterior().

AssetReferenceGameObject _sceneUI​

Addressable prefab for the scene-specific UI overlay.

GameObject LoadingUI​

Prefab for displaying a loading indicator or screen.

GameObject _sceneUIInstance​

Live instance of the UI prefab.

DynamicInteriorController cachedInteriorController​

Optional scene-level controller for retrieving spawn transforms.

bool lostFocus​

Tracks app focus loss to determine if a reconnect is needed.


Key Methods​

void RequestInterior(string interiorID)​

Defines the target interior session that this state will manage.


Lifecycle Overrides​

void EnterState()​

  • Sets frame rate
  • Shows loading UI
  • Instantiates _sceneUI
  • Connects to multiplayer session using requestedInteriorID

Task ExitState(bool allowRejoin = false)​

  • Releases UI
  • Disconnects from the session
  • Optionally allows rejoin logic

Player Spawn Logic​

GetPlayerSpawnPosition(PlayerConnectionHost player)​

Delegates spawn location to DynamicInteriorController if available.

GetPlayerSpawnRotation(PlayerConnectionHost player)​

Delegates rotation to DynamicInteriorController if available.


Scene Load Handling​

void SceneLoaded()​

Callback to hide LoadingUI once interior is loaded.


Focus Handling​

void ApplicationFocusChanged(bool hasFocus)​

On focus loss: Exits state and flags for reconnect.
On focus regain: Re-enters state if lostFocus was true.


Networking​

JoinOrCreateSession()​

Initiates a multiplayer session using the scene reference and requested interior ID.


Example Usage​

var state = new DynamicInteriorState(someScene, GameStateManager.Local);
state.RequestInterior("apt_01");
GameStateManager.Local.RequestState(state);

This class is ideal for handling private or instanced play areas such as apartments, rooms, or build zones.