|
Runtime Spawner 1.3.0
Generic Runtime spawn and instance pooling system for spawning random AI agents around a map. Works with ANY AI system easily.
|
Lightweight spatial index for EnemySpawnHintPoint. More...
Static Public Member Functions | |
| static void | Configure (float cellSize) |
| Configures the spatial grid cell size and rebuilds the internal buckets without losing current registrations. | |
| static void | Register (EnemySpawnHintPoint h) |
| Registers a hint with the registry and inserts it into the appropriate grid bucket. | |
| static void | Unregister (EnemySpawnHintPoint h) |
| Unregisters a hint from the registry, removes it from its grid bucket and clears any reservation. | |
| static IEnumerable< EnemySpawnHintPoint > | QueryCircle (Vector3 center, float radius) |
| Enumerates all registered hints whose positions fall within a radius of center . | |
| static bool | IsReserved (EnemySpawnHintPoint h) |
Returns true if the hint is currently soft-reserved. | |
| static bool | TryReserve (EnemySpawnHintPoint h, float seconds) |
| Attempts to soft-reserve a hint for a duration. | |
| static int | DebugCountAll () |
| Returns the number of currently registered hints. | |
| static void | ScanSceneForHints () |
| Clears and repopulates the registry by scanning the open scene(s) for EnemySpawnHintPoint. | |
Static Private Member Functions | |
| static void | Rebuild () |
| Rebuilds all grid buckets from the current s_All set using the active s_Cell size. | |
| static void | AddToGrid (EnemySpawnHintPoint h) |
| Adds a hint to the grid bucket for its world position. | |
| static void | RemoveFromGrid (EnemySpawnHintPoint h) |
| Removes a hint from the grid bucket matching its world position. | |
| static Vector2Int | WorldToCell (Vector3 p) |
| Converts a world position to a grid cell coordinate using the active cell size on X/Z. | |
Static Private Attributes | |
| static float | s_Cell = 16f |
| Current grid cell size (in meters). Hints are bucketed by this size in X/Z. | |
| static readonly HashSet< EnemySpawnHintPoint > | s_All = new() |
| Master set of all registered hints (alive & valid). | |
| static readonly Dictionary< Vector2Int, List< EnemySpawnHintPoint > > | s_Grid = new() |
| Grid buckets mapping cell coords to hint lists. Keys are discretized X/Z cells via WorldToCell(Vector3). | |
| static readonly Dictionary< EnemySpawnHintPoint, float > | s_ReservedUntil = new() |
Soft reservation expiry times per hint (in Time.time seconds). Hints are considered reserved while now <= until. | |
Lightweight spatial index for EnemySpawnHintPoint.
This registry keeps a grid-bucketed lookup of all registered hint points so spawn systems can query nearby hints efficiently at spawn time. It performs no per-frame work; all operations are explicit (register/unregister/query).
The registry is intended for main-thread usage only (Unity API calls).
|
staticprivate |
Adds a hint to the grid bucket for its world position.
| h | Hint to bucket. |
|
static |
Configures the spatial grid cell size and rebuilds the internal buckets without losing current registrations.
| cellSize | Cell size in meters; clamped to ≥ 2. |
Calling this at runtime is safe; the registry will re-bucket existing hints based on the new size.
|
static |
Returns the number of currently registered hints.
|
static |
Returns true if the hint is currently soft-reserved.
| h | Hint to check. |
true if reserved and the reservation has not yet expired; otherwise false.
|
static |
Enumerates all registered hints whose positions fall within a radius of center .
| center | Query center (world space). |
| radius | Query radius in meters. |
The query first bounds grid iteration to cells overlapping the circle’s AABB, then filters by exact circle distance.
|
staticprivate |
Rebuilds all grid buckets from the current s_All set using the active s_Cell size.
|
static |
Registers a hint with the registry and inserts it into the appropriate grid bucket.
| h | Hint to register (ignored if null). |
Typically called from EnemySpawnHintPoint.OnEnable().
|
staticprivate |
Removes a hint from the grid bucket matching its world position.
| h | Hint to remove. |
|
static |
Clears and repopulates the registry by scanning the open scene(s) for EnemySpawnHintPoint.
Intended for editor-time utilities and diagnostics. Uses Object.FindObjectsByType<T>(FindObjectsSortMode).
|
static |
Attempts to soft-reserve a hint for a duration.
| h | Hint to reserve. |
| seconds | Reservation duration in seconds. Values ≤ 0 will expire immediately (effectively no reservation). |
true if the hint was not already reserved and is now reserved; otherwise false.Reservations are advisory and only affect systems that consult the registry (e.g., spawn placement heuristics).
|
static |
Unregisters a hint from the registry, removes it from its grid bucket and clears any reservation.
| h | Hint to unregister (ignored if null). |
Typically called from EnemySpawnHintPoint.OnDisable().
|
staticprivate |
Converts a world position to a grid cell coordinate using the active cell size on X/Z.
| p | World position. |
|
staticprivate |
Master set of all registered hints (alive & valid).
|
staticprivate |
Current grid cell size (in meters). Hints are bucketed by this size in X/Z.
|
staticprivate |
Grid buckets mapping cell coords to hint lists. Keys are discretized X/Z cells via WorldToCell(Vector3).
|
staticprivate |
Soft reservation expiry times per hint (in Time.time seconds). Hints are considered reserved while now <= until.