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.
Loading...
Searching...
No Matches
MegaCrush.Spawner.SpawnLocator Class Referencesealed

Default spawn locator that performs physics raycasts and NavMesh sampling to produce valid placement positions for spawned objects. More...

Inheritance diagram for MegaCrush.Spawner.SpawnLocator:
MegaCrush.Spawner.ISpawnLocator

Public Member Functions

void Configure (LayerMask mask, float minSpawnRange, float cullDistance, string[] navmeshAreas)
 Configures sampling parameters and NavMesh area mask.
Parameters
maskPhysics layers considered as ground when raycasting down.
minSpawnRangeMinimum allowed distance from the player.
cullDistanceMax search radius around the player for global placement.
navmeshAreasOptional NavMesh area names to restrict placement.

 
void ConfigureHints (bool enabled, SpawnHintSettings settings)
 Enables/disables the hint system and supplies settings.
Parameters
enabledWhether hint lookups should be attempted.
settingsHint parameters asset (cell size, LOS mask, etc.).

 
Vector3 FindForGlobal (Vector3 playerPos)
 Finds a NavMesh-valid position for global spawning around the player.
Parameters
playerPosWorld position of the player.

 
Vector3 FindNearParent (Vector3 parentPos, Vector3 playerPos)
 Finds a NavMesh-valid position near a group parent (for clustered spawns).
Parameters
parentPosWorld position of the group parent.
playerPosWorld position of the player.

 
Vector3 FindForRegion (Bounds bounds, float regionHeight, Vector3 playerPos)
 Finds a NavMesh-valid position inside a region’s bounds.
Parameters
regionBoundsRegion world-space AABB.
regionHeightY height to apply after placement (for visual consistency).
playerPosWorld position of the player.

 
Vector3 FindForWave (Transform point, float range, Vector3 playerPos, string[] hintTags=null)
 Finds a NavMesh-valid position near a specific wave/special anchor point.
Parameters
spawnPointAnchor transform.
spawnRangeRadius to sample around the anchor.
playerPosWorld position of the player.
hintTagsOptional tag filter coming from WaveSpawnPoint.AnchorTags.

 

Static Public Member Functions

static bool IsInvalid (Vector3 v)
 Checks whether a vector is the sentinel invalid position.
 

Private Member Functions

bool TryFromHints (Vector3 center, float searchRadius, Vector3 playerPos, out Vector3 posOut, string[] requestTags=null)
 Tries to choose a position from EnemySpawnHintPoint around center . If requestTags is provided, the first pass prefers hints that match at least one tag. If none qualify, a second pass accepts any eligible hint. Returns false if no hint passes checks.
 
bool HasPlayerLOS (Vector3 playerPos, Vector3 candidate)
 Returns true if there is no blocking collider between player and candidate (i.e., player can see it).
 
Vector3 RaycastDown (Vector3 pos)
 Raycasts downward to find ground on the configured physics layers. Returns the hit point if found, otherwise the input position.
 
bool ValidVsPlayer (Vector3 pos, Vector3 playerPos)
 Ensures pos is at least _minRange away from the player.
 
bool NavSample (ref Vector3 pos, float maxDist)
 Samples the NavMesh near pos restricted to _areaMask. On success, updates pos to the sampled position.
 
Vector3 Fallback (Vector3 around)
 Best-effort fallback using NavMesh.FindClosestEdge; returns the input position if none found.
 

Static Private Member Functions

static bool TagsMatch (string[] requested, string[] candidate)
 Returns true if any non-empty requested tag appears in candidate .
 
static int BuildAreaMask (string[] names)
 Builds a NavMesh area bitmask from area names; returns NavMesh.AllAreas if none or not found.
 

Private Attributes

LayerMask _mask
 
float _minRange
 
float _cullDistance
 
int _areaMask
 
bool _useHints
 
SpawnHintSettings _hints
 

Static Private Attributes

static readonly Vector3 InvalidPos = new Vector3(float.NaN, float.NaN, float.NaN)
 Sentinel returned when Hint-Only is on and no hint qualifies.
 
static readonly HashSet< EnemySpawnHintPoints_WarnedRangeClash = new()
 
static readonly HashSet< EnemySpawnHintPoints_WarnedInvalidWindow = new()
 

Detailed Description

Default spawn locator that performs physics raycasts and NavMesh sampling to produce valid placement positions for spawned objects.

Member Function Documentation

◆ BuildAreaMask()

static int MegaCrush.Spawner.SpawnLocator.BuildAreaMask ( string[] names)
staticprivate

Builds a NavMesh area bitmask from area names; returns NavMesh.AllAreas if none or not found.

◆ Configure()

void MegaCrush.Spawner.SpawnLocator.Configure ( LayerMask mask,
float minSpawnRange,
float cullDistance,
string[] navmeshAreas )

Configures sampling parameters and NavMesh area mask.

Parameters
maskPhysics layers considered as ground when raycasting down.
minSpawnRangeMinimum allowed distance from the player.
cullDistanceMax search radius around the player for global placement.
navmeshAreasOptional NavMesh area names to restrict placement.

Implements MegaCrush.Spawner.ISpawnLocator.

◆ ConfigureHints()

void MegaCrush.Spawner.SpawnLocator.ConfigureHints ( bool enabled,
SpawnHintSettings settings )

Enables/disables the hint system and supplies settings.

Parameters
enabledWhether hint lookups should be attempted.
settingsHint parameters asset (cell size, LOS mask, etc.).

Implements MegaCrush.Spawner.ISpawnLocator.

◆ Fallback()

Vector3 MegaCrush.Spawner.SpawnLocator.Fallback ( Vector3 around)
private

Best-effort fallback using NavMesh.FindClosestEdge; returns the input position if none found.

◆ FindForGlobal()

Vector3 MegaCrush.Spawner.SpawnLocator.FindForGlobal ( Vector3 playerPos)

Finds a NavMesh-valid position for global spawning around the player.

Parameters
playerPosWorld position of the player.

Implements MegaCrush.Spawner.ISpawnLocator.

◆ FindForRegion()

Vector3 MegaCrush.Spawner.SpawnLocator.FindForRegion ( Bounds bounds,
float regionHeight,
Vector3 playerPos )

Finds a NavMesh-valid position inside a region’s bounds.

Parameters
regionBoundsRegion world-space AABB.
regionHeightY height to apply after placement (for visual consistency).
playerPosWorld position of the player.

Implements MegaCrush.Spawner.ISpawnLocator.

◆ FindForWave()

Vector3 MegaCrush.Spawner.SpawnLocator.FindForWave ( Transform point,
float range,
Vector3 playerPos,
string[] hintTags = null )

Finds a NavMesh-valid position near a specific wave/special anchor point.

Parameters
spawnPointAnchor transform.
spawnRangeRadius to sample around the anchor.
playerPosWorld position of the player.
hintTagsOptional tag filter coming from WaveSpawnPoint.AnchorTags.

Implements MegaCrush.Spawner.ISpawnLocator.

◆ FindNearParent()

Vector3 MegaCrush.Spawner.SpawnLocator.FindNearParent ( Vector3 parentPos,
Vector3 playerPos )

Finds a NavMesh-valid position near a group parent (for clustered spawns).

Parameters
parentPosWorld position of the group parent.
playerPosWorld position of the player.

Implements MegaCrush.Spawner.ISpawnLocator.

◆ HasPlayerLOS()

bool MegaCrush.Spawner.SpawnLocator.HasPlayerLOS ( Vector3 playerPos,
Vector3 candidate )
private

Returns true if there is no blocking collider between player and candidate (i.e., player can see it).

◆ IsInvalid()

static bool MegaCrush.Spawner.SpawnLocator.IsInvalid ( Vector3 v)
static

Checks whether a vector is the sentinel invalid position.

◆ NavSample()

bool MegaCrush.Spawner.SpawnLocator.NavSample ( ref Vector3 pos,
float maxDist )
private

Samples the NavMesh near pos restricted to _areaMask. On success, updates pos to the sampled position.

◆ RaycastDown()

Vector3 MegaCrush.Spawner.SpawnLocator.RaycastDown ( Vector3 pos)
private

Raycasts downward to find ground on the configured physics layers. Returns the hit point if found, otherwise the input position.

◆ TagsMatch()

static bool MegaCrush.Spawner.SpawnLocator.TagsMatch ( string[] requested,
string[] candidate )
staticprivate

Returns true if any non-empty requested tag appears in candidate .

◆ TryFromHints()

bool MegaCrush.Spawner.SpawnLocator.TryFromHints ( Vector3 center,
float searchRadius,
Vector3 playerPos,
out Vector3 posOut,
string[] requestTags = null )
private

Tries to choose a position from EnemySpawnHintPoint around center . If requestTags is provided, the first pass prefers hints that match at least one tag. If none qualify, a second pass accepts any eligible hint. Returns false if no hint passes checks.

◆ ValidVsPlayer()

bool MegaCrush.Spawner.SpawnLocator.ValidVsPlayer ( Vector3 pos,
Vector3 playerPos )
private

Ensures pos is at least _minRange away from the player.

Member Data Documentation

◆ _areaMask

int MegaCrush.Spawner.SpawnLocator._areaMask
private

◆ _cullDistance

float MegaCrush.Spawner.SpawnLocator._cullDistance
private

◆ _hints

SpawnHintSettings MegaCrush.Spawner.SpawnLocator._hints
private

◆ _mask

LayerMask MegaCrush.Spawner.SpawnLocator._mask
private

◆ _minRange

float MegaCrush.Spawner.SpawnLocator._minRange
private

◆ _useHints

bool MegaCrush.Spawner.SpawnLocator._useHints
private

◆ InvalidPos

readonly Vector3 MegaCrush.Spawner.SpawnLocator.InvalidPos = new Vector3(float.NaN, float.NaN, float.NaN)
staticprivate

Sentinel returned when Hint-Only is on and no hint qualifies.

◆ s_WarnedInvalidWindow

readonly HashSet<EnemySpawnHintPoint> MegaCrush.Spawner.SpawnLocator.s_WarnedInvalidWindow = new()
staticprivate

◆ s_WarnedRangeClash

readonly HashSet<EnemySpawnHintPoint> MegaCrush.Spawner.SpawnLocator.s_WarnedRangeClash = new()
staticprivate

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