Class AGamePool<T>
Abstract base class for implementing a generic game object pooling system.
Implements
Namespace: GUPS.EasyPooling
Assembly: cs.temp.dll.dll
Syntax
public abstract class AGamePool<T> : Singleton<T>, IPool where T : AGamePool<T>
Type Parameters
| Name | Description |
|---|---|
| T | The type of the concrete pool class inheriting from this base class. |
Remarks
The AGamePool<T> class serves as a foundation for creating specialized game object pooling systems in Unity.
It extends the functionality of the
The pooling system maintains an empty pool for spawning and despawning empty game objects, and blueprint 'sub'-pools for managing different types of game objects. It supports various pooling strategies and allows for dynamic registration of blueprints during initialization. Blueprints can be registered with specified pooling strategies and initial capacities.
The class provides a comprehensive set of methods for spawning and despawning game objects based on blueprint names, applying decorators and spawn policies as needed.
Fields
StartupBlueprints
Array of GameObject blueprints to register on pool awake, useful if you want to assing protoypes in the inspector.
Declaration
public BlueprintPoolDefinition[] StartupBlueprints
Field Value
| Type | Description |
|---|---|
| BlueprintPoolDefinition[] |
Properties
Capacity
Gets the capacity of the empty pool.
Declaration
public int Capacity { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Count
Gets the number of GameObjects in the empty pool.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Strategy
Gets the pooling strategy of the empty pool.
Declaration
public EPoolingStrategy Strategy { get; }
Property Value
| Type | Description |
|---|---|
| EPoolingStrategy |
Methods
Awake()
Called during Awake to initialize the LocalPool instance.
Declaration
protected override void Awake()
Despawn(GameObject)
Despawns a poolable GameObject back into the pool.
Declaration
public void Despawn(GameObject _PoolAble)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | _PoolAble | The poolable GameObject to despawn. |
Despawn(GameObject, IUnDecorator)
Despawns a poolable GameObject back into the pool using a provided un-decorator.
Declaration
public void Despawn(GameObject _PoolAble, IUnDecorator _UnDecorator)
Parameters
| Type | Name | Description |
|---|---|---|
| GameObject | _PoolAble | The poolable GameObject to despawn. |
| IUnDecorator | _UnDecorator | The un-decorator to apply to the despawned GameObject. |
HasBlueprint(String)
Checks if a blueprint pool with the specified name already exists.
Declaration
public bool HasBlueprint(string _Name)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | _Name | The name or identifier of the blueprint. |
Returns
| Type | Description |
|---|---|
| System.Boolean | True if a pool with the specified name exists; otherwise, false. |
Register(BlueprintPoolDefinition)
Declaration
public void Register(BlueprintPoolDefinition _BlueprintPoolDefinition)
Parameters
| Type | Name | Description |
|---|---|---|
| BlueprintPoolDefinition | _BlueprintPoolDefinition |
Register(String, GameObject, EPoolingStrategy, Int32)
Registers a GameObject as poolable blueprint to the pool. This process creates a new local 'sub'-pool, clones the passed GameObject and attaches it to the new created 'sub'-pool as blueprint reference. If the GameObject has no IPoolAble component attached, the DefaultPoolAble component will be added.
Declaration
public void Register(string _Name, GameObject _Blueprint, EPoolingStrategy _PoolingStrategy = null, int _Capacity = 25)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | _Name | The name or identifier of the blueprint. |
| GameObject | _Blueprint | The GameObject blueprint to register. |
| EPoolingStrategy | _PoolingStrategy | The pooling strategy to use (optional, default is |
| System.Int32 | _Capacity | The initial capacity of the pool (optional, default is 25). |
Spawn()
Spawns an empty GameObject from the pool or creates a new one.
Declaration
public GameObject Spawn()
Returns
| Type | Description |
|---|---|
| GameObject | The spawned GameObject. |
Spawn(SpawnPolicy)
Spawns an empty GameObject from the pool or creates a new one.
Declaration
public GameObject Spawn(SpawnPolicy _SpawnPolicy)
Parameters
| Type | Name | Description |
|---|---|---|
| SpawnPolicy | _SpawnPolicy | The spawn policy to apply. Applied before OnSpawn. |
Returns
| Type | Description |
|---|---|
| GameObject | The spawned GameObject. |
Spawn(IDecorator)
Spawns an empty GameObject from the pool or creates a new one and decorates it with the provided decorator.
Declaration
public GameObject Spawn(IDecorator _Decorator)
Parameters
| Type | Name | Description |
|---|---|---|
| IDecorator | _Decorator | The decorator to apply to the spawned GameObject. |
Returns
| Type | Description |
|---|---|
| GameObject | The spawned GameObject. |
Spawn(IDecorator, SpawnPolicy)
Spawns an empty GameObject from the pool or creates a new one and decorates it with the provided decorator and applying a spawn policy.
Declaration
public GameObject Spawn(IDecorator _Decorator, SpawnPolicy _SpawnPolicy)
Parameters
| Type | Name | Description |
|---|---|---|
| IDecorator | _Decorator | The decorator to apply to the spawned GameObject. |
| SpawnPolicy | _SpawnPolicy | The spawn policy to apply. |
Returns
| Type | Description |
|---|---|
| GameObject | The spawned GameObject. |
Spawn(IDecorator, Vector3, Quaternion)
Spawns an empty GameObject from the pool or creates a new one and decorates it with the provided decorator at the specified position and rotation.
Declaration
public GameObject Spawn(IDecorator _Decorator, Vector3 _Position, Quaternion _Rotation)
Parameters
| Type | Name | Description |
|---|---|---|
| IDecorator | _Decorator | The decorator to apply to the spawned GameObject. |
| Vector3 | _Position | The position at which to spawn the GameObject. |
| Quaternion | _Rotation | The rotation at which to spawn the GameObject. |
Returns
| Type | Description |
|---|---|
| GameObject |
Spawn(String)
Spawns a GameObject based on its blueprint name.
Declaration
public GameObject Spawn(string _Blueprint)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | _Blueprint | The name or identifier of the blueprint to spawn. |
Returns
| Type | Description |
|---|---|
| GameObject | The spawned GameObject. |
Spawn(String, SpawnPolicy)
Spawn a GameObject based on its blueprint name, applying a spawn policy.
Declaration
public GameObject Spawn(string _Blueprint, SpawnPolicy _SpawnPolicy)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | _Blueprint | The name or identifier of the blueprint to spawn. |
| SpawnPolicy | _SpawnPolicy | The spawn policy to apply. Applied before OnSpawn. |
Returns
| Type | Description |
|---|---|
| GameObject | The spawned GameObject. |
Spawn(String, IDecorator)
Spawns a GameObject based on its blueprint name with a custom provided decorator.
Declaration
public GameObject Spawn(string _Blueprint, IDecorator _Decorator)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | _Blueprint | The name or identifier of the blueprint to spawn. |
| IDecorator | _Decorator | The decorator to apply to the spawned GameObject. |
Returns
| Type | Description |
|---|---|
| GameObject | The spawned GameObject. |
Spawn(String, IDecorator, SpawnPolicy)
Spawns a GameObject based on its blueprint name with a custom provided decorator.
Declaration
public GameObject Spawn(string _Blueprint, IDecorator _Decorator, SpawnPolicy _SpawnPolicy)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | _Blueprint | The name or identifier of the blueprint to spawn. |
| IDecorator | _Decorator | The decorator to apply to the spawned GameObject. |
| SpawnPolicy | _SpawnPolicy | The spawn policy to apply. Applied before OnSpawn. |
Returns
| Type | Description |
|---|---|
| GameObject | The spawned GameObject. |
Spawn(String, IDecorator, Vector3, Quaternion)
Spawns a GameObject based on its blueprint name with a custom provided decorator at the specified position and rotation.
Declaration
public GameObject Spawn(string _Blueprint, IDecorator _Decorator, Vector3 _Position, Quaternion _Rotation)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | _Blueprint | The name or identifier of the blueprint to spawn. |
| IDecorator | _Decorator | The decorator to apply to the spawned GameObject. |
| Vector3 | _Position | The position at which to spawn the GameObject. |
| Quaternion | _Rotation | The rotation at which to spawn the GameObject. |
Returns
| Type | Description |
|---|---|
| GameObject |
Spawn(String, Vector3, Quaternion)
Spawns a GameObject based on its blueprint name at the specified position and rotation.
Declaration
public GameObject Spawn(string _Blueprint, Vector3 _Position, Quaternion _Rotation)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | _Blueprint | The name or identifier of the blueprint to spawn. |
| Vector3 | _Position | The position at which to spawn the GameObject. |
| Quaternion | _Rotation | The rotation at which to spawn the GameObject. |
Returns
| Type | Description |
|---|---|
| GameObject |
Spawn(Vector3, Quaternion)
Spawns an empty GameObject from the pool or creates a new one at the specified position and rotation.
Declaration
public GameObject Spawn(Vector3 _Position, Quaternion _Rotation)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector3 | _Position | The position at which to spawn the GameObject. |
| Quaternion | _Rotation | The rotation at which to spawn the GameObject. |
Returns
| Type | Description |
|---|---|
| GameObject |
SpawnMany(IDecorator, Int32)
Spawns multiple empty GameObjects from the pool or creates new ones, decorating each with the provided decorator.
Declaration
public GameObject[] SpawnMany(IDecorator _Decorator, int _Count)
Parameters
| Type | Name | Description |
|---|---|---|
| IDecorator | _Decorator | The decorator to apply to the spawned GameObjects. |
| System.Int32 | _Count | The number of GameObjects to spawn. |
Returns
| Type | Description |
|---|---|
| GameObject[] | An array of spawned GameObjects. |
SpawnMany(IDecorator, Int32, SpawnPolicy)
Spawns multiple empty GameObjects from the pool or creates new ones, decorating each with the provided decorator, and applying a spawn policy to each.
Declaration
public GameObject[] SpawnMany(IDecorator _Decorator, int _Count, SpawnPolicy _SpawnPolicy)
Parameters
| Type | Name | Description |
|---|---|---|
| IDecorator | _Decorator | The decorator to apply to the spawned GameObjects. |
| System.Int32 | _Count | The number of GameObjects to spawn. |
| SpawnPolicy | _SpawnPolicy | The spawn policy to apply. Applied before OnSpawn. |
Returns
| Type | Description |
|---|---|
| GameObject[] | An array of spawned GameObjects. |
SpawnMany(Int32)
Spawns multiple empty GameObjects from the pool or creates new ones.
Declaration
public GameObject[] SpawnMany(int _Count)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | _Count | The number of GameObjects to spawn. |
Returns
| Type | Description |
|---|---|
| GameObject[] | An array of spawned GameObjects. |
SpawnMany(Int32, SpawnPolicy)
Spawns multiple empty GameObjects from the pool or creates new ones, applying a spawn policy to each.
Declaration
public GameObject[] SpawnMany(int _Count, SpawnPolicy _SpawnPolicy)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | _Count | The number of GameObjects to spawn. |
| SpawnPolicy | _SpawnPolicy | The spawn policy to apply. Applied before OnSpawn. |
Returns
| Type | Description |
|---|---|
| GameObject[] | An array of spawned GameObjects. |
SpawnMany(String, IDecorator, Int32)
Spawns multiple GameObjects based on the blueprint name with a custom provided decorator.
Declaration
public GameObject[] SpawnMany(string _Blueprint, IDecorator _Decorator, int _Count)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | _Blueprint | The name or identifier of the blueprint to spawn. |
| IDecorator | _Decorator | The decorator to apply to the spawned GameObject. |
| System.Int32 | _Count | The number of GameObjects to spawn. |
Returns
| Type | Description |
|---|---|
| GameObject[] | An array of spawned GameObjects. |
SpawnMany(String, IDecorator, Int32, SpawnPolicy)
Spawns multiple GameObjects based on the blueprint name with a custom provided decorator, applying a spawn policy to each.
Declaration
public GameObject[] SpawnMany(string _Blueprint, IDecorator _Decorator, int _Count, SpawnPolicy _SpawnPolicy)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | _Blueprint | The name or identifier of the blueprint to spawn. |
| IDecorator | _Decorator | The decorator to apply to the spawned GameObject. |
| System.Int32 | _Count | The number of GameObjects to spawn. |
| SpawnPolicy | _SpawnPolicy | The spawn policy to apply. |
Returns
| Type | Description |
|---|---|
| GameObject[] | An array of spawned GameObjects. |
SpawnMany(String, Int32)
Spawns multiple GameObjects based on the blueprint name.
Declaration
public GameObject[] SpawnMany(string _Blueprint, int _Count)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | _Blueprint | The name or identifier of the blueprint to spawn. |
| System.Int32 | _Count | The number of GameObjects to spawn. |
Returns
| Type | Description |
|---|---|
| GameObject[] | An array of spawned GameObjects. |
SpawnMany(String, Int32, SpawnPolicy)
Spawns multiple GameObjects based on the blueprint name, applying a spawn policy to each.
Declaration
public GameObject[] SpawnMany(string _Blueprint, int _Count, SpawnPolicy _SpawnPolicy)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | _Blueprint | The name or identifier of the blueprint to spawn. |
| System.Int32 | _Count | The number of GameObjects to spawn. |
| SpawnPolicy | _SpawnPolicy | The spawn policy to apply. Applied before OnSpawn. |
Returns
| Type | Description |
|---|---|
| GameObject[] | An array of spawned GameObjects. |