Class UnitySpawnFactory
Unity implementation of ISpawnFactory using GameObjects.
Namespace: Serenity.GameSpawner.Infrastructure.Factories
Assembly: Serenity.UnityGameSpawner.Infrastructure.dll
Syntax
public class UnitySpawnFactory : MonoBehaviour, IRecyclingSpawnFactory, ISpawnFactory
Remarks
The default factory creates an empty container; override it to instantiate your actor. Every Create(SpawnType) makes an empty GameObject named after the spawn type, and nothing reads a prefab. It serves game code that spawns through the game spawner service directly: waves and characters never spawn through it (they go through the character spawn service), so overriding it changes nothing a wave spawns. Implements IRecyclingSpawnFactory so the spawner service can park and resume instances by toggling UnityEngine.GameObject.SetActive(System.Boolean) instead of destroying and recreating them. Game-specific implementations can override this factory to use prefabs, object pools, or other instantiation strategies.
Constructors
UnitySpawnFactory()
Declaration
public UnitySpawnFactory()
Fields
_instances
Declaration
protected readonly Dictionary<SpawnHandle, GameObject> _instances
Field Value
| Type | Description |
|---|---|
| Dictionary<SpawnHandle, GameObject> |
Methods
Create(SpawnType)
Declaration
public virtual SpawnHandle Create(SpawnType type)
Parameters
| Type | Name | Description |
|---|---|---|
| SpawnType | type |
Returns
| Type | Description |
|---|---|
| SpawnHandle |
Deactivate(SpawnHandle)
Declaration
public virtual bool Deactivate(SpawnHandle handle)
Parameters
| Type | Name | Description |
|---|---|---|
| SpawnHandle | handle |
Returns
| Type | Description |
|---|---|
| bool |
Destroy(SpawnHandle)
Declaration
public virtual void Destroy(SpawnHandle handle)
Parameters
| Type | Name | Description |
|---|---|---|
| SpawnHandle | handle |
DestroyAll(SpawnType)
Declaration
public virtual void DestroyAll(SpawnType type)
Parameters
| Type | Name | Description |
|---|---|---|
| SpawnType | type |
Reactivate(SpawnHandle)
Declaration
public virtual bool Reactivate(SpawnHandle handle)
Parameters
| Type | Name | Description |
|---|---|---|
| SpawnHandle | handle |
Returns
| Type | Description |
|---|---|
| bool |