logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class UnityWaveService

    Unity MonoBehaviour implementation of IWaveService and IUnityWaveRuntime. Manages wave progression within a stage. Stores wave SO references for spawn entry access. Supports spawn-point resolution via ISpawnPointResolver (hybrid prefab authoring). Delegates actor spawning/pooling to ICharacterSpawnService: each spawn entry spawns the registered character it names, one cadence apart, through Serenity.Wave.Infrastructure.Services.WaveSpawnScheduler.

    Inheritance
    object
    UnityWaveService
    Implements
    IWaveService
    IService
    IFoundationSettings
    IUnityWaveRuntime
    Namespace: Serenity.Wave.Infrastructure.Services
    Assembly: Serenity.UnityWave.Infrastructure.dll
    Syntax
    public class UnityWaveService : MonoBehaviour, IWaveService, IService, IFoundationSettings, IUnityWaveRuntime
    Remarks

    A wave clears on the actors it actually spawned: an entry that cannot spawn some or all of its actors forfeits them once its scheduling is over, so a wave whose entries all fail clears at once instead of waiting for actors that never existed. Each cause is told to the author once, by whoever knows it: the entry's own warning names the wave and the actors it forfeits, and a refusal the character spawn service already reported is not repeated. A removal named by actor counts only against the wave that spawned that actor.

    Constructors

    UnityWaveService()

    Declaration
    public UnityWaveService()

    Fields

    LOG_CATEGORY

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

    _characterSpawnService

    Declaration
    protected ICharacterSpawnService _characterSpawnService
    Field Value
    Type Description
    ICharacterSpawnService

    _currentWaveIndex

    Declaration
    protected int _currentWaveIndex
    Field Value
    Type Description
    int

    _eventDispatcher

    Declaration
    protected IEventDispatcherService _eventDispatcher
    Field Value
    Type Description
    IEventDispatcherService

    _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

    _waveConfigSOs

    Declaration
    protected List<IWaveConfig> _waveConfigSOs
    Field Value
    Type Description
    List<IWaveConfig>

    _waves

    Declaration
    protected List<WaveState> _waves
    Field Value
    Type Description
    List<WaveState>

    Properties

    AllWavesCleared

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

    CurrentWaveIndex

    Declaration
    public int CurrentWaveIndex { get; }
    Property Value
    Type Description
    int

    Guid

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

    Id

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

    LogService

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

    TotalWaves

    Declaration
    public int TotalWaves { get; }
    Property Value
    Type Description
    int

    Methods

    ConfigureFromWaveSet(IWaveSet)

    Configures waves from a UnityWaveSetSO. Stores SO references for spawn entry access.

    Declaration
    public virtual void ConfigureFromWaveSet(IWaveSet waveSetSO)
    Parameters
    Type Name Description
    IWaveSet waveSetSO

    The wave set to configure from.

    ConfigureWaves(WaveConfig[])

    Declaration
    public virtual void ConfigureWaves(WaveConfig[] configs)
    Parameters
    Type Name Description
    WaveConfig[] configs

    ConfigureWaves(int, int[])

    Declaration
    public virtual void ConfigureWaves(int totalWaves, int[] actorsPerWave)
    Parameters
    Type Name Description
    int totalWaves
    int[] actorsPerWave

    Editor_ForceAdvanceToNextWave()

    Editor-only: force-clears the current wave and starts the next one. Calls RecordActorRemoved() until the wave is cleared, then calls StartNextWave(). Safe to call only in Play mode.

    Declaration
    public void Editor_ForceAdvanceToNextWave()

    Editor_GetWaves()

    Editor-only: returns the internal wave state list for inspector display.

    Declaration
    public IReadOnlyList<WaveState> Editor_GetWaves()
    Returns
    Type Description
    IReadOnlyList<WaveState>

    GetCurrentWaveSnapshot()

    Declaration
    public virtual WaveSnapshot GetCurrentWaveSnapshot()
    Returns
    Type Description
    WaveSnapshot

    IEditor_GetWaveConfigs()

    Editor-only: returns the wave config SO list for inspector display.

    Declaration
    public IReadOnlyList<IWaveConfig> IEditor_GetWaveConfigs()
    Returns
    Type Description
    IReadOnlyList<IWaveConfig>

    InitializeService(ILogService)

    Initializes the service with required dependencies.

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

    The logging service for diagnostic output.

    OnAllWavesCleared(EventDispatcherSignal)

    Declaration
    protected void OnAllWavesCleared(EventDispatcherSignal signal)
    Parameters
    Type Name Description
    EventDispatcherSignal signal

    OnDestroy()

    Declaration
    protected void OnDestroy()

    OnWaveCleared(EventDispatcherSignal)

    Declaration
    protected void OnWaveCleared(EventDispatcherSignal signal)
    Parameters
    Type Name Description
    EventDispatcherSignal signal

    RecordActorRemoved()

    Declaration
    public virtual void RecordActorRemoved()

    RecordActorRemoved(string)

    Declaration
    public virtual void RecordActorRemoved(string actorId)
    Parameters
    Type Name Description
    string actorId

    RecordSpawnedActor(CharacterId)

    Records an actor spawned by this wave service (or a subclass override) so ReleaseCurrentWaveActors() only ever releases its own actors, and so a removal named by that actor counts against the current wave.

    Declaration
    protected void RecordSpawnedActor(CharacterId characterId)
    Parameters
    Type Name Description
    CharacterId characterId

    The spawned actor's identity.

    ReleaseCurrentWaveActors()

    Releases the actors THIS service spawned and stops all active spawn coroutines to prevent late spawns from a previous wave. Actors owned by other systems sharing the same spawn pool are deliberately left untouched (Release(CharacterId) no-ops for ids that were already released, e.g. actors that died and were reclaimed).

    Declaration
    protected void ReleaseCurrentWaveActors()

    ScheduleCurrentWaveSpawns()

    Reads the current wave's IWaveConfig and starts a coroutine for each SpawnEntry, honouring SpawnDelay and Count. Must be called after IWaveService.StartNextWave.

    Declaration
    public virtual void ScheduleCurrentWaveSpawns()
    Remarks

    Every entry is scheduled before the wave may clear: an entry that forfeits its actors while the wave is still being scheduled only takes effect once every entry has started, so a wave whose entries all fail clears exactly once, after the last one.

    SetSpawnDependencies(IEventDispatcherService, ICharacterSpawnService)

    Injects the event dispatcher and character spawn service required for spawn scheduling and wave-cleared event handling. Called once by the installer after service creation.

    Declaration
    public void SetSpawnDependencies(IEventDispatcherService eventDispatcher, ICharacterSpawnService characterSpawnService)
    Parameters
    Type Name Description
    IEventDispatcherService eventDispatcher
    ICharacterSpawnService characterSpawnService
    Remarks

    A spawn entry names the character it spawns, and the spawn service learns its characters by key, so the spawn service must also be an ICharacterKeyResolver to turn what the entry names into the registered character's key. The shipped one is; with one that is not, every entry warns, spawns nothing and forfeits its actors.

    SetSpawnPointResolver(ISpawnPointResolver)

    Sets the spawn point resolver used to map spawn-entry IDs to world poses. Typically provided by UnityStageService after instantiating the stage prefab.

    Declaration
    public virtual void SetSpawnPointResolver(ISpawnPointResolver resolver)
    Parameters
    Type Name Description
    ISpawnPointResolver resolver

    The resolver extracted from the stage prefab, or null to clear.

    SpawnEntryCoroutine(SpawnEntry)

    The coroutine that spawns one entry of the current wave: it waits for SpawnDelay seconds, then spawns Count actors at the designated spawn point, one Cadence apart (a cadence of 0 spawns them all at once). Each actor is the registered character the entry names, spawned through ICharacterSpawnService. Whatever the entry could not spawn — all of it when no registered character matches, which it warns about naming the entry — is forfeited from the wave once the entry's scheduling is over.

    Declaration
    protected virtual IEnumerator SpawnEntryCoroutine(SpawnEntry entry)
    Parameters
    Type Name Description
    SpawnEntry entry
    Returns
    Type Description
    IEnumerator

    StartNextWave()

    Declaration
    public virtual void StartNextWave()

    TryGetCurrentWaveSO(out IWaveConfig)

    Gets the wave SO for the current wave index. Provides access to spawn entries and other Unity-only authoring data.

    Declaration
    public virtual bool TryGetCurrentWaveSO(out IWaveConfig waveSO)
    Parameters
    Type Name Description
    IWaveConfig waveSO

    The current wave's ScriptableObject if available.

    Returns
    Type Description
    bool

    True if a wave SO is available for the current index.

    TryResolveSpawnPose(string, out SpawnPose)

    Resolves a spawn-entry's string-based spawn-point ID to a world SpawnPose. Returns false if the resolver is not set or the ID is unknown.

    Declaration
    public virtual bool TryResolveSpawnPose(string spawnPointId, out SpawnPose pose)
    Parameters
    Type Name Description
    string spawnPointId

    The string identifier authored in the SpawnEntry.

    SpawnPose pose

    The resolved pose, or default if not found.

    Returns
    Type Description
    bool

    True if the spawn point was resolved; false otherwise.

    Implements

    IWaveService
    IService
    IFoundationSettings
    IUnityWaveRuntime
    In this article
    © 2026 Serenity. All Rights Reserved