logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityStageService

    Unity MonoBehaviour implementation of IStageService. Supports a hybrid authoring model: Stage Prefab (spatial) + ScriptableObjects (tuning). After instantiation, extracts IStageRoot, IRailPathAuthoring, and ISpawnPointResolver from the prefab hierarchy.

    Inheritance
    object
    UnityStageService
    Implements
    IStageService
    IService
    IFoundationSettings
    IUnityStageRuntime
    IUnityStageRuntimeAsync
    Namespace: Serenity.Stage.Infrastructure.Services
    Assembly: Serenity.UnityStage.Infrastructure.dll
    Syntax
    public class UnityStageService : MonoBehaviour, IStageService, IService, IFoundationSettings, IUnityStageRuntime, IUnityStageRuntimeAsync

    Constructors

    UnityStageService()

    Declaration
    public UnityStageService()

    Fields

    LOG_CATEGORY

    Declaration
    protected const string LOG_CATEGORY = "StageService"
    Field Value
    Type Description
    string

    _gameWrapper

    Declaration
    protected GameObject _gameWrapper
    Field Value
    Type Description
    GameObject

    _guid

    Declaration
    protected string _guid
    Field Value
    Type Description
    string

    _id

    Declaration
    protected string _id
    Field Value
    Type Description
    string

    _logService

    Declaration
    protected ILogService _logService
    Field Value
    Type Description
    ILogService

    _spawnPointResolver

    Declaration
    protected ISpawnPointResolver _spawnPointResolver
    Field Value
    Type Description
    ISpawnPointResolver

    _stageInstance

    Declaration
    protected GameObject _stageInstance
    Field Value
    Type Description
    GameObject

    _stageRoot

    Declaration
    protected StageRoot _stageRoot
    Field Value
    Type Description
    StageRoot

    _state

    Declaration
    protected StageState _state
    Field Value
    Type Description
    StageState

    Properties

    Guid

    Declaration
    public string Guid { get; set; }
    Property Value
    Type Description
    string

    HasPreparedStage

    True when a prepared stage is built and waiting for CommitPreparedStage().

    Declaration
    public bool HasPreparedStage { get; }
    Property Value
    Type Description
    bool

    Id

    Declaration
    public string Id { get; set; }
    Property Value
    Type Description
    string

    IsPreparingStage

    True while a preparation started by BeginPrepareStagePrefab(GameObject) is still running.

    Declaration
    public bool IsPreparingStage { get; }
    Property Value
    Type Description
    bool

    LogService

    Declaration
    public ILogService LogService { get; set; }
    Property Value
    Type Description
    ILogService

    SpawnPointResolver

    The spawn point resolver extracted from the instantiated prefab, or null.

    Declaration
    public ISpawnPointResolver SpawnPointResolver { get; }
    Property Value
    Type Description
    ISpawnPointResolver

    StageRoot

    The stage root extracted from the instantiated prefab, or null.

    Declaration
    public IStageRoot StageRoot { get; }
    Property Value
    Type Description
    IStageRoot

    Methods

    BeginPrepareStagePrefab(GameObject)

    Starts building stagePrefab in the background. Replaces any previous preparation, cancelling and discarding it first. A null prefab clears the preparation and does nothing else.

    Declaration
    public virtual void BeginPrepareStagePrefab(GameObject stagePrefab)
    Parameters
    Type Name Description
    GameObject stagePrefab

    CancelPreparedStage()

    Abandons any in-flight or completed preparation and destroys whatever it produced. Idempotent, and safe to call when nothing is prepared.

    Declaration
    public virtual void CancelPreparedStage()

    CommitPreparedStage()

    Activates the prepared stage, moves it into the live hierarchy, extracts its authoring components and adopts it as the current stage.

    Declaration
    public virtual GameObject CommitPreparedStage()
    Returns
    Type Description
    GameObject

    The committed stage GameObject, or null when nothing was prepared or the preparation is still running — callers should fall back to the synchronous path on null.

    CompleteStage()

    Declaration
    public virtual void CompleteStage()

    ExtractAuthoringComponents()

    Reads the authoring components out of _stageInstance into this service's slots. Extracted from InstantiateStagePrefab(GameObject) so the asynchronous path can run the very same extraction at commit time rather than duplicating it — and so a subclass adds its own extras by overriding one method instead of re-implementing instantiation.

    Declaration
    protected virtual void ExtractAuthoringComponents()
    Remarks

    Deliberately not called until the instance is the one being adopted: these are single-slot fields, so extracting from a stage that is merely being prepared would overwrite the wiring of the stage still being played.

    FailStage()

    Declaration
    public virtual void FailStage()

    GetSnapshot()

    Declaration
    public virtual StageSnapshot GetSnapshot()
    Returns
    Type Description
    StageSnapshot

    InitializeService(IFoundationViewElement, ILogService)

    Initializes the service with required dependencies.

    Declaration
    public virtual void InitializeService(IFoundationViewElement GameWrapper, ILogService logService)
    Parameters
    Type Name Description
    IFoundationViewElement GameWrapper
    ILogService logService

    InstantiateStagePrefab(GameObject)

    Instantiates the given stage prefab and extracts authoring components: StageRoot, RailPathAuthoring, SpawnPointRegistry.

    Declaration
    public virtual GameObject InstantiateStagePrefab(GameObject stagePrefab)
    Parameters
    Type Name Description
    GameObject stagePrefab

    The stage prefab to instantiate.

    Returns
    Type Description
    GameObject

    The instantiated stage GameObject, or null if the prefab is null.

    OnDestroy()

    Declaration
    protected virtual void OnDestroy()

    StartStage(StageId)

    Starts the stage with the given identity.

    Declaration
    public virtual void StartStage(StageId stageId)
    Parameters
    Type Name Description
    StageId stageId

    The stage identity.

    Implements

    IStageService
    IService
    IFoundationSettings
    IUnityStageRuntime
    IUnityStageRuntimeAsync
    In this article
    © 2026 Serenity. All Rights Reserved