SpawnerBase
An abstract class in Root.Township, the global namespace.
Base for networked spawners that spawn a prefab at themselves, at random or sequential spawn points, or at a forced position, with optional attribute overrides and material. Server side.
- Listed in Global namespace: S
- Inherits or implements
NetworkEntityBehaviour,ISpawner - Derived types
MultiSpawner,PouchSpawner,Spawner
Constructors
| Member | What it is |
|---|---|
protected SpawnerBase() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
14 private and internal fields
| Member | What it is |
|---|---|
private AttributeSingleValue[] attributes | Attribute overrides written into the spawn data for every spawned entity. |
private bool isActive | Backing field for IsActive. While false, spawning does nothing. |
private bool isChildingSpawned | Spawns entities as saved children parented to this spawner instead of into its chunk. |
private bool isRotationRandom | Gives spawned entities a random rotation instead of the spawn point's. |
private bool isRotationRandomYOnly | Limits random rotation to a turn about Y. |
private PhysicalMaterialPart materialPart | Physical material copied onto spawned entities that have a PhysicalMaterialPart. |
private SpawnMethod method | How spawn points are chosen: sequence, random, or the spawner itself. |
private int nextId | Index of the last spawn point used in sequence mode. |
private Vector3 nextPosition | Position chosen for the entity being spawned. |
private Quaternion nextRotation | Rotation chosen for the entity being spawned. |
private Vector3 positionCache | Spawner position captured at the start of a spawn when there are no spawn points. |
private float radius | Random scatter radius around the spawner when there are no spawn points. |
private Quaternion rotationCache | Spawner rotation captured with positionCache. |
private Transform[] spawnPoints | Optional transforms to spawn at. |
Properties
| Member | What it is |
|---|---|
Vector3? ForcePosition { get; private set; } | A one-time position set by SpawnAt, used for the next spawn then cleared. |
bool IsActive { get; set; } | When false, spawning does nothing. |
NetworkEntity LastSpawned { get; private set; } | The most recently spawned entity. |
1 private and internal property
Methods
| Member | What it is |
|---|---|
abstract void Spawn() | Spawns the subclass's item. The protected overload spawns count copies of a prefab into the spawner's chunk, or as saved children if set to child them. |
void SpawnAt(Vector3 location) | Spawns once at a given position, with a random rotation. |
protected virtual void OnSpawn(NetworkEntity spawned) | Called after each entity spawns. Empty by default. |
protected void Spawn(NetworkPrefab prefab, int count) | Spawns the subclass's item. The protected overload spawns count copies of a prefab into the spawner's chunk, or as saved children if set to child them. |
5 private and internal methods
| Member | What it is |
|---|---|
private void EvaluatePosition() | Picks the next spawn position and rotation: a forced position, a random spot within radius, or the next spawn point. |
private void OnDrawGizmosSelected() | Draws the spawn radius as a faint sphere. |
private void Position(NetworkEntity entity) | Spawn callback that places the new entity at the chosen position and rotation. |
private void PreChunk(NetworkEntity entity) | Spawn callback that applies materialPart's physical material to the new entity, if set. |
private Quaternion RandomRotation() | A random rotation, or a random turn about Y only if isRotationRandomYOnly. |