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.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.

 
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)
 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.

 

Private Member Functions

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 the position 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 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
 

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.

◆ 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 )

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.

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.

◆ 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.

◆ ValidVsPlayer()

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

Ensures the position 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

◆ _mask

LayerMask MegaCrush.Spawner.SpawnLocator._mask
private

◆ _minRange

float MegaCrush.Spawner.SpawnLocator._minRange
private

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