Runtime Spawner 1.5.1
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.SinglePlayerPoolFactory Class Referencesealed

Simple factory implementation for single-player or offline projects. More...

Inheritance diagram for MegaCrush.Spawner.SinglePlayerPoolFactory:
MegaCrush.Spawner.IObjectFactory MegaCrush.Spawner.IPrewarmableFactory

Public Member Functions

 SinglePlayerPoolFactory (IPoolAdapter pool)
 Creates a new SinglePlayerPoolFactory bound to the specified object pool.
 
ISpawnHandle Spawn (SpawnRequest r)
 Spawns a new object using the configured pool.
 
Task< ISpawnHandleSpawnAsync (SpawnRequest r)
 Asynchronously spawns an object using the same logic as Spawn(SpawnRequest).
 
void Prewarm (SpawnEntry entry, int count)
 Prewarms the pool with instances of the specified prefab.
 

Private Attributes

readonly IPoolAdapter _pool
 

Detailed Description

Simple factory implementation for single-player or offline projects.

Uses a project-wide IPoolAdapter to spawn and recycle objects efficiently without network dependencies. This factory is ideal for local gameplay, simulation, or offline testing environments where networked synchronization is not required.

When a SpawnRequest is received, the factory retrieves an instance of the requested prefab from the pool (via IPoolAdapter.Get), and returns a BasicSpawnHandle that automatically returns the object to the pool when ISpawnHandle.Despawn is called.

This implementation also supports prewarming via IPrewarmableFactory, ensuring that frequently used prefabs can be instantiated ahead of time to minimize runtime allocation and instantiation costs.

Constructor & Destructor Documentation

◆ SinglePlayerPoolFactory()

MegaCrush.Spawner.SinglePlayerPoolFactory.SinglePlayerPoolFactory ( IPoolAdapter pool)

Creates a new SinglePlayerPoolFactory bound to the specified object pool.

Parameters
poolThe project-wide IPoolAdapter responsible for retrieving and returning instances.

Member Function Documentation

◆ Prewarm()

void MegaCrush.Spawner.SinglePlayerPoolFactory.Prewarm ( SpawnEntry entry,
int count )

Prewarms the pool with instances of the specified prefab.

Parameters
entryThe SpawnEntry to prewarm (must have a valid prefab).
countNumber of instances to allocate or prepare for reuse.

This method forwards to IPoolAdapter.EnsurePool, creating or resizing the pool for the specified prefab. If count is less than or equal to zero, this call is ignored.

Implements MegaCrush.Spawner.IPrewarmableFactory.

◆ Spawn()

ISpawnHandle MegaCrush.Spawner.SinglePlayerPoolFactory.Spawn ( SpawnRequest r)

Spawns a new object using the configured pool.

Parameters
rThe SpawnRequest defining prefab, position, and context data.
Returns
A BasicSpawnHandle that wraps the spawned GameObject instance, or null if the prefab was not provided or the pool failed to return an instance.

This factory does not perform network synchronization or ownership management. The returned object is purely local and managed via the provided IPoolAdapter.

Implements MegaCrush.Spawner.IObjectFactory.

◆ SpawnAsync()

Task< ISpawnHandle > MegaCrush.Spawner.SinglePlayerPoolFactory.SpawnAsync ( SpawnRequest r)

Asynchronously spawns an object using the same logic as Spawn(SpawnRequest).

Parameters
rThe SpawnRequest to process.
Returns
A completed task containing the resulting ISpawnHandle. This implementation executes synchronously.

Implements MegaCrush.Spawner.IObjectFactory.

Member Data Documentation

◆ _pool

readonly IPoolAdapter MegaCrush.Spawner.SinglePlayerPoolFactory._pool
private

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