|
Runtime Spawner 1.5.0
Generic Runtime spawn and instance pooling system for spawning random AI agents around a map. Works with ANY AI system easily.
|
Central, director-driven controller that scales per-tile LocalAreaSpawners and resolves their spawn lists from a global RegionSpawnLibrary. More...
Classes | |
| interface | IRegionTagProvider |
| Optional provider interface for region tags. Implement on any component under a region root to supply semantic tags (e.g., "industrial", "residential"). If not present, the Unity tag is used. More... | |
Public Member Functions | |
| void | SetLibrary (RegionSpawnLibrary lib) |
| Assigns the global library at runtime (optional). | |
| void | ApplyStepFromDirector (int step, int stepsCount, float localDensityOverride=-1f) |
| Applies a new step from the SpawnDirector (or a custom driver) and recomputes all region targets and spawn lists. If localDensityOverride is >= 0, it is used directly; otherwise localDensityByStep is evaluated. | |
| void | RegisterRegion (LocalAreaSpawner region) |
| Registers a region with this controller (normally handled automatically by RuntimeSpawner events). Safe to call redundantly. | |
| void | UnregisterRegion (LocalAreaSpawner region) |
| Unregisters a region from this controller (normally handled automatically by RuntimeSpawner events). | |
Public Attributes | |
| bool | autoDiscoverAtStart = false |
| float | enableThreshold = 0.40f |
| AnimationCurve | localDensityByStep = AnimationCurve.Linear(0, 0.8f, 1, 1.7f) |
| bool | useJitter = true |
| bool | logChanges = false |
Private Member Functions | |
| void | Awake () |
| void | OnEnable () |
| void | OnDisable () |
| void | OnValidate () |
| void | OnRegionRegistered (LocalAreaSpawner region) |
| Handles region registration from RuntimeSpawner. | |
| void | OnRegionUnregistered (LocalAreaSpawner region) |
| Handles region unregistration from RuntimeSpawner. | |
| void | OnDirectorStepChanged (int step) |
| Handles director step changes (if bound). | |
| void | RecomputeAll (float localDensityOverride) |
| Recomputes targets and spawn lists for all tracked regions using the current step. | |
| void | RecomputeRegion (LocalAreaSpawner region, float localDensityOverride) |
| Recomputes a single region’s enable/disable state, target min/max, and spawn list. | |
| void | RefreshRegionEntries (LocalAreaSpawner region, int step, int stepsCount) |
| Builds a region’s LocalAreaSpawner.CustomRegionSpawners from the global RegionSpawnLibrary using tags and step ranges. If no rules match, applies fallback. | |
Static Private Member Functions | |
| static string[] | GetTags (LocalAreaSpawner region) |
| Returns semantic tags for a region using IRegionTagProvider if present; otherwise falls back to the GameObject's Unity Tag (if not "Untagged"). Returns an empty array if none. | |
| static bool | TagsMatch (string[] have, string[] all, string[] any) |
| Returns true if have satisfies "all" and/or "any" tag filters. | |
| static float | Hash01 (string s) |
| Stable 0..1 hash for strings (FNV-1a based, reduced). | |
Private Attributes | |
| RuntimeSpawner | spawner |
| SpawnDirector | director |
| RegionSpawnLibrary | library |
| readonly List< LocalAreaSpawner > | _regions = new() |
| int | _step = 0 |
| int | _stepsCount = 1 |
Central, director-driven controller that scales per-tile LocalAreaSpawners and resolves their spawn lists from a global RegionSpawnLibrary.
This component is part of the Runtime Spawner package and is intended to be placed once in your gameplay scene. It listens for region lifecycle events from RuntimeSpawner and (optionally) step changes from SpawnDirector. For each active region, it:
LocalAreaSpawner.DesiredRangeOverride (non-destructive, runtime-only). Requirements:
onRegionRegistered and onRegionUnregistered events. public (int min, int max) DesiredRangeOverride { get; set; } — set to (-1,-1) to ignore. public float DensityMult { get; set; } — informational; controller bakes scaling into the override. Usage:
| void MegaCrush.Spawner.RegionPopulationController.ApplyStepFromDirector | ( | int | step, |
| int | stepsCount, | ||
| float | localDensityOverride = -1f ) |
Applies a new step from the SpawnDirector (or a custom driver) and recomputes all region targets and spawn lists. If localDensityOverride is >= 0, it is used directly; otherwise localDensityByStep is evaluated.
| step | 0-based step index to apply. |
| stepsCount | Total number of steps (≥ 1) used to normalize the curve. |
| localDensityOverride | Optional override for density multiplier; pass < 0 to use the curve. |
|
private |
|
staticprivate |
Returns semantic tags for a region using IRegionTagProvider if present; otherwise falls back to the GameObject's Unity Tag (if not "Untagged"). Returns an empty array if none.
|
staticprivate |
Stable 0..1 hash for strings (FNV-1a based, reduced).
|
private |
Handles director step changes (if bound).
|
private |
|
private |
|
private |
Handles region registration from RuntimeSpawner.
|
private |
Handles region unregistration from RuntimeSpawner.
|
private |
|
private |
Recomputes targets and spawn lists for all tracked regions using the current step.
| localDensityOverride | If >= 0, forces a fixed density multiplier for this pass. |
|
private |
Recomputes a single region’s enable/disable state, target min/max, and spawn list.
|
private |
Builds a region’s LocalAreaSpawner.CustomRegionSpawners from the global RegionSpawnLibrary using tags and step ranges. If no rules match, applies fallback.
| void MegaCrush.Spawner.RegionPopulationController.RegisterRegion | ( | LocalAreaSpawner | region | ) |
Registers a region with this controller (normally handled automatically by RuntimeSpawner events). Safe to call redundantly.
| void MegaCrush.Spawner.RegionPopulationController.SetLibrary | ( | RegionSpawnLibrary | lib | ) |
Assigns the global library at runtime (optional).
|
staticprivate |
Returns true if have satisfies "all" and/or "any" tag filters.
| void MegaCrush.Spawner.RegionPopulationController.UnregisterRegion | ( | LocalAreaSpawner | region | ) |
Unregisters a region from this controller (normally handled automatically by RuntimeSpawner events).
|
private |
|
private |
|
private |
| bool MegaCrush.Spawner.RegionPopulationController.autoDiscoverAtStart = false |
|
private |
| float MegaCrush.Spawner.RegionPopulationController.enableThreshold = 0.40f |
|
private |
| AnimationCurve MegaCrush.Spawner.RegionPopulationController.localDensityByStep = AnimationCurve.Linear(0, 0.8f, 1, 1.7f) |
| bool MegaCrush.Spawner.RegionPopulationController.logChanges = false |
|
private |
| bool MegaCrush.Spawner.RegionPopulationController.useJitter = true |