Runtime Spawner 1.2.5
Generic Runtime spawn and instance pooling system for spawning random AI agents around a map. Works with ANY AI system easily.
Loading...
Searching...
No Matches
MegaCrush.Spawner.SpecialEncounterManager Class Referencesealed

Manages opportunistic “special” encounters driven by a SpecialProfile. Evaluates rules on an interval and, when conditions are met, spawns via the bound RuntimeSpawner using either tagged WaveSpawnPoint anchors or a radial fallback resolved by the Locator. More...

Inheritance diagram for MegaCrush.Spawner.SpecialEncounterManager:

Public Member Functions

void SetTelemetryProvider (ISpecialsTelemetry provider)
 Allow code-based injection if teams prefer services over assets.
 
void SetRunning (bool run)
 Starts or stops the specials scheduler without enabling/disabling this component. When started, the manager ensures it has been initialized and dependencies are present.
 
bool RequestImmediateForRule (string ruleName)
 
void RequestImmediateRoll ()
 Makes all rules eligible to evaluate immediately (runtime-safe).
 
bool RequestImmediateForTag (string spawnTag)
 Convenience: request by spawnTag instead of rule name. Returns true if any matching rule was nudged.
 
void Init (RuntimeSpawner spawner)
 Binds to the owning RuntimeSpawner and hooks director/population events. Call once the spawner exists (typically during RuntimeSpawner.Init).
 
void Begin ()
 Resets rule state, hooks population events, and starts the evaluation loop. Idempotent: if already running, does nothing.
 
void Stop ()
 Stops evaluation and unhooks population events. Idempotent.
 

Static Public Member Functions

static void RefreshAnchors ()
 Clears the cached anchor list; next query will rescan the scene.
 

Properties

SpecialProfile Profile [get, set]
 The active special-encounter profile containing evaluated rules.
 
float NextSpawnAt = -1f [get, private set]
 Absolute Time.time when the next eligible evaluation is planned across all rules; -1 if unscheduled.
 
float LastSpawnAt = -1f [get, private set]
 Absolute Time.time when the last special actually spawned; -1 if never.
 
string NextPlannedTag [get, private set]
 Optional hint of the next tag/rule selected for the upcoming spawn (best-effort debug only).
 
bool IsRunning [get]
 True while the scheduler is active (EvalLoop running). Use SetRunning(bool) to change.
 

Events

Action OnScheduleChanged
 Fired when the next evaluation/roll time changes (for HUD timing and inspectors).
 
Action< string > OnSpecialSpawned
 Fired when a special actually spawns (param: rule/spawn tag for HUD logs).
 

Private Member Functions

void ForceRollNow_EditorOnly ()
 Force all rules to be eligible immediately (editor-only test helper).
 
void OnDisable ()
 
void HandleStepChanged (int _)
 Forces all rules to be eligible next frame when step changes (so the new step can immediately allow specials without waiting for their full eval interval).
 
void OnSpawnedWithMeta (GameObject go, SpawnMeta meta)
 Tracks current alive count per rule using spawn metadata.
 
void OnDespawned (GameObject go, SpawnMeta meta)
 Decrements alive count per rule when a special-spawned object despawns.
 
IEnumerator EvalLoop ()
 Periodically evaluates rules and spawns when conditions pass. Runs only while IsRunning is true.
 
bool Bump (SpecialRule r, float now, float delay)
 Returns true if schedule for r was bumped and next ETA changed.
 
bool SetCooldown (SpecialRule r, float now, float seconds)
 Returns true if cooldown applied and next ETA changed.
 
void RecomputeNextSpawnAt ()
 Recomputes the next global evaluation time across rules (for HUD/inspectors). Only considers rules eligible for the current director step.
 
bool StepAllowed (SpecialRule r)
 Checks if the current intensity step allows this rule.
 
bool ConditionsPass (SpecialRule r)
 Checks additional rule conditions (pressure, average player HP, etc.) via the configured telemetry provider. If a rule requires telemetry and no provider is available, the condition fails (safe default).
 
WaveSpawnPoint[] GetAnchors ()
 Returns cached (or freshly discovered) WaveSpawnPoints.
 
bool TryPickAnchor (SpecialRule r, Vector3 playerPos, out WaveSpawnPoint anchor)
 Attempts to find a valid anchor that matches the rule’s distance/tag requirements (and LOS requirement, if enabled). Returns true and an anchor if found.
 

Static Private Member Functions

static bool AnchorMatchesTag (WaveSpawnPoint sp, string wanted)
 Returns whether a WaveSpawnPoint matches a desired tag, checking both its custom AnchorTags and the GameObject tag.
 

Private Attributes

SpecialProfile profile
 
LayerMask occluderMask = ~0
 
SpecialsTelemetryProvider telemetryProvider
 
RuntimeSpawner _spawner
 
SpawnDirector _director
 
ISpawnExecutor _exec
 
ISpawnLocator _locator
 
PopulationTracker _pop
 
readonly Dictionary< SpecialRule, float > _nextEvalAt = new()
 
readonly Dictionary< SpecialRule, int > _alivePerRule = new()
 
readonly Dictionary< string, SpecialRule_ruleByName = new()
 
float _lastSpecialTime
 
Transform _player
 
Coroutine _loop
 
bool _running
 
ISpecialsTelemetry _telemetry
 

Static Private Attributes

static WaveSpawnPoint[] _cachedAnchors
 

Detailed Description

Manages opportunistic “special” encounters driven by a SpecialProfile. Evaluates rules on an interval and, when conditions are met, spawns via the bound RuntimeSpawner using either tagged WaveSpawnPoint anchors or a radial fallback resolved by the Locator.

Lifecycle:

  • Call Init(RuntimeSpawner) once the spawner is available.
  • Use SetRunning(bool) to start/stop the scheduler without disabling the component. (Internally this starts/stops the evaluation coroutine.)

Member Function Documentation

◆ AnchorMatchesTag()

static bool MegaCrush.Spawner.SpecialEncounterManager.AnchorMatchesTag ( WaveSpawnPoint sp,
string wanted )
staticprivate

Returns whether a WaveSpawnPoint matches a desired tag, checking both its custom AnchorTags and the GameObject tag.

◆ Begin()

void MegaCrush.Spawner.SpecialEncounterManager.Begin ( )

Resets rule state, hooks population events, and starts the evaluation loop. Idempotent: if already running, does nothing.

◆ Bump()

bool MegaCrush.Spawner.SpecialEncounterManager.Bump ( SpecialRule r,
float now,
float delay )
private

Returns true if schedule for r was bumped and next ETA changed.

◆ ConditionsPass()

bool MegaCrush.Spawner.SpecialEncounterManager.ConditionsPass ( SpecialRule r)
private

Checks additional rule conditions (pressure, average player HP, etc.) via the configured telemetry provider. If a rule requires telemetry and no provider is available, the condition fails (safe default).

◆ EvalLoop()

IEnumerator MegaCrush.Spawner.SpecialEncounterManager.EvalLoop ( )
private

Periodically evaluates rules and spawns when conditions pass. Runs only while IsRunning is true.

◆ ForceRollNow_EditorOnly()

void MegaCrush.Spawner.SpecialEncounterManager.ForceRollNow_EditorOnly ( )
private

Force all rules to be eligible immediately (editor-only test helper).

◆ GetAnchors()

WaveSpawnPoint[] MegaCrush.Spawner.SpecialEncounterManager.GetAnchors ( )
private

Returns cached (or freshly discovered) WaveSpawnPoints.

◆ HandleStepChanged()

void MegaCrush.Spawner.SpecialEncounterManager.HandleStepChanged ( int _)
private

Forces all rules to be eligible next frame when step changes (so the new step can immediately allow specials without waiting for their full eval interval).

◆ Init()

void MegaCrush.Spawner.SpecialEncounterManager.Init ( RuntimeSpawner spawner)

Binds to the owning RuntimeSpawner and hooks director/population events. Call once the spawner exists (typically during RuntimeSpawner.Init).

◆ OnDespawned()

void MegaCrush.Spawner.SpecialEncounterManager.OnDespawned ( GameObject go,
SpawnMeta meta )
private

Decrements alive count per rule when a special-spawned object despawns.

◆ OnDisable()

void MegaCrush.Spawner.SpecialEncounterManager.OnDisable ( )
private

◆ OnSpawnedWithMeta()

void MegaCrush.Spawner.SpecialEncounterManager.OnSpawnedWithMeta ( GameObject go,
SpawnMeta meta )
private

Tracks current alive count per rule using spawn metadata.

◆ RecomputeNextSpawnAt()

void MegaCrush.Spawner.SpecialEncounterManager.RecomputeNextSpawnAt ( )
private

Recomputes the next global evaluation time across rules (for HUD/inspectors). Only considers rules eligible for the current director step.

◆ RefreshAnchors()

static void MegaCrush.Spawner.SpecialEncounterManager.RefreshAnchors ( )
static

Clears the cached anchor list; next query will rescan the scene.

◆ RequestImmediateForRule()

bool MegaCrush.Spawner.SpecialEncounterManager.RequestImmediateForRule ( string ruleName)

◆ RequestImmediateForTag()

bool MegaCrush.Spawner.SpecialEncounterManager.RequestImmediateForTag ( string spawnTag)

Convenience: request by spawnTag instead of rule name. Returns true if any matching rule was nudged.

◆ RequestImmediateRoll()

void MegaCrush.Spawner.SpecialEncounterManager.RequestImmediateRoll ( )

Makes all rules eligible to evaluate immediately (runtime-safe).

◆ SetCooldown()

bool MegaCrush.Spawner.SpecialEncounterManager.SetCooldown ( SpecialRule r,
float now,
float seconds )
private

Returns true if cooldown applied and next ETA changed.

◆ SetRunning()

void MegaCrush.Spawner.SpecialEncounterManager.SetRunning ( bool run)

Starts or stops the specials scheduler without enabling/disabling this component. When started, the manager ensures it has been initialized and dependencies are present.

Parameters
runTrue to start, false to stop.

◆ SetTelemetryProvider()

void MegaCrush.Spawner.SpecialEncounterManager.SetTelemetryProvider ( ISpecialsTelemetry provider)

Allow code-based injection if teams prefer services over assets.

◆ StepAllowed()

bool MegaCrush.Spawner.SpecialEncounterManager.StepAllowed ( SpecialRule r)
private

Checks if the current intensity step allows this rule.

◆ Stop()

void MegaCrush.Spawner.SpecialEncounterManager.Stop ( )

Stops evaluation and unhooks population events. Idempotent.

◆ TryPickAnchor()

bool MegaCrush.Spawner.SpecialEncounterManager.TryPickAnchor ( SpecialRule r,
Vector3 playerPos,
out WaveSpawnPoint anchor )
private

Attempts to find a valid anchor that matches the rule’s distance/tag requirements (and LOS requirement, if enabled). Returns true and an anchor if found.

Member Data Documentation

◆ _alivePerRule

readonly Dictionary<SpecialRule, int> MegaCrush.Spawner.SpecialEncounterManager._alivePerRule = new()
private

◆ _cachedAnchors

WaveSpawnPoint [] MegaCrush.Spawner.SpecialEncounterManager._cachedAnchors
staticprivate

◆ _director

SpawnDirector MegaCrush.Spawner.SpecialEncounterManager._director
private

◆ _exec

ISpawnExecutor MegaCrush.Spawner.SpecialEncounterManager._exec
private

◆ _lastSpecialTime

float MegaCrush.Spawner.SpecialEncounterManager._lastSpecialTime
private

◆ _locator

ISpawnLocator MegaCrush.Spawner.SpecialEncounterManager._locator
private

◆ _loop

Coroutine MegaCrush.Spawner.SpecialEncounterManager._loop
private

◆ _nextEvalAt

readonly Dictionary<SpecialRule, float> MegaCrush.Spawner.SpecialEncounterManager._nextEvalAt = new()
private

◆ _player

Transform MegaCrush.Spawner.SpecialEncounterManager._player
private

◆ _pop

PopulationTracker MegaCrush.Spawner.SpecialEncounterManager._pop
private

◆ _ruleByName

readonly Dictionary<string, SpecialRule> MegaCrush.Spawner.SpecialEncounterManager._ruleByName = new()
private

◆ _running

bool MegaCrush.Spawner.SpecialEncounterManager._running
private

◆ _spawner

RuntimeSpawner MegaCrush.Spawner.SpecialEncounterManager._spawner
private

◆ _telemetry

ISpecialsTelemetry MegaCrush.Spawner.SpecialEncounterManager._telemetry
private

◆ occluderMask

LayerMask MegaCrush.Spawner.SpecialEncounterManager.occluderMask = ~0
private

◆ profile

SpecialProfile MegaCrush.Spawner.SpecialEncounterManager.profile
private

◆ telemetryProvider

SpecialsTelemetryProvider MegaCrush.Spawner.SpecialEncounterManager.telemetryProvider
private

Property Documentation

◆ IsRunning

bool MegaCrush.Spawner.SpecialEncounterManager.IsRunning
get

True while the scheduler is active (EvalLoop running). Use SetRunning(bool) to change.

◆ LastSpawnAt

float MegaCrush.Spawner.SpecialEncounterManager.LastSpawnAt = -1f
getprivate set

Absolute Time.time when the last special actually spawned; -1 if never.

◆ NextPlannedTag

string MegaCrush.Spawner.SpecialEncounterManager.NextPlannedTag
getprivate set

Optional hint of the next tag/rule selected for the upcoming spawn (best-effort debug only).

◆ NextSpawnAt

float MegaCrush.Spawner.SpecialEncounterManager.NextSpawnAt = -1f
getprivate set

Absolute Time.time when the next eligible evaluation is planned across all rules; -1 if unscheduled.

◆ Profile

SpecialProfile MegaCrush.Spawner.SpecialEncounterManager.Profile
getset

The active special-encounter profile containing evaluated rules.

Event Documentation

◆ OnScheduleChanged

Action MegaCrush.Spawner.SpecialEncounterManager.OnScheduleChanged

Fired when the next evaluation/roll time changes (for HUD timing and inspectors).

◆ OnSpecialSpawned

Action<string> MegaCrush.Spawner.SpecialEncounterManager.OnSpecialSpawned

Fired when a special actually spawns (param: rule/spawn tag for HUD logs).


The documentation for this class was generated from the following file: