Class GameObjectPool
A pool for a single type (blueprint) of GameObjects.
Inheritance
Implements
Namespace: GUPS.EasyPooling.Pooling
Assembly: cs.temp.dll.dll
Syntax
public class GameObjectPool : MonoBehaviour, IPoolRemarks
The GameObjectPool class provides a pool for managing and reusing instances of a single type (blueprint) of GameObject. It supports various spawning and despawning options, including applying decorators, spawn policies, and managing the pool size dynamically.
The pool is thread-safe, ensuring proper synchronization during spawn and despawn operations.
Properties
Blueprint
The blueprint of the GameObject is used to reset despawned instances.
Declaration
public GameObjectBlueprint Blueprint { get; }Property Value
| Type | Description | 
|---|---|
| GameObjectBlueprint | 
Capacity
Gets the capacity of the pool.
Declaration
public int Capacity { get; }Property Value
| Type | Description | 
|---|---|
| System.Int32 | 
Count
Gets the number of GameObjects in the pool.
Declaration
public int Count { get; }Property Value
| Type | Description | 
|---|---|
| System.Int32 | 
Name
Gets the name of the GameObject.
Declaration
public string Name { get; }Property Value
| Type | Description | 
|---|---|
| System.String | 
Original
The original GameObject used to spawn new pooled instances.
Declaration
public GameObject Original { get; }Property Value
| Type | Description | 
|---|---|
| GameObject | 
Strategy
Gets the pooling strategy of the pool.
Declaration
public EPoolingStrategy Strategy { get; }Property Value
| Type | Description | 
|---|---|
| EPoolingStrategy | 
Methods
Create(GameObject, EPoolingStrategy, Int32)
Create a new reference pool for a type of GameObject.
Declaration
public static GameObjectPool Create(GameObject _Original, EPoolingStrategy _Strategy = null, int _Capacity = 25)Parameters
| Type | Name | Description | 
|---|---|---|
| GameObject | _Original | The original GameObject used to spawn new pooled instances. | 
| EPoolingStrategy | _Strategy | The pooling strategy to use (optional, default is  | 
| System.Int32 | _Capacity | The initial capacity of the pool (optional, default is 25). | 
Returns
| Type | Description | 
|---|---|
| GameObjectPool | 
Create(String, EPoolingStrategy, Int32)
Create a new pool for an empty GameObject.
Declaration
public static GameObjectPool Create(string _Name, EPoolingStrategy _Strategy = null, int _Capacity = 25)Parameters
| Type | Name | Description | 
|---|---|---|
| System.String | _Name | The name to use. | 
| EPoolingStrategy | _Strategy | The pooling strategy to use (optional, default is  | 
| System.Int32 | _Capacity | The initial capacity of the pool (optional, default is 25). | 
Returns
| Type | Description | 
|---|---|
| GameObjectPool | 
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. | 
Spawn()
Either get a pooled instance or create a new one and apply the blueprint.
Declaration
public GameObject Spawn()Returns
| Type | Description | 
|---|---|
| GameObject | 
Spawn(SpawnPolicy)
Either get a pooled instance or create a new one and apply the blueprint.
Declaration
public GameObject Spawn(SpawnPolicy _SpawnPolicy)Parameters
| Type | Name | Description | 
|---|---|---|
| SpawnPolicy | _SpawnPolicy | The spawn policy to apply to the spawned GameObject. Applied before OnSpawn. | 
Returns
| Type | Description | 
|---|---|
| GameObject | 
Spawn(IDecorator)
Spawns a GameObject with a provided decorator. If you pass null, the GameObject will be spawned as it is.
Declaration
public GameObject Spawn(IDecorator _Decorator)Parameters
| Type | Name | Description | 
|---|---|---|
| IDecorator | _Decorator | The decorator to apply to the spawned GameObject. | 
Returns
| Type | Description | 
|---|---|
| GameObject | 
Spawn(IDecorator, SpawnPolicy)
Spawns a GameObject with a provided decorator. If you pass null, the GameObject will be spawned as it is.
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 to the spawned GameObject. Applied before OnSpawn. | 
Returns
| Type | Description | 
|---|---|
| GameObject | 
Spawn(IDecorator, Vector3, Quaternion)
Spawns a GameObject with a provided decorator at the specified position and rotation. If you pass null to the decorator, the GameObject will be spawned as it is.
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(IDecorator, Vector3, Quaternion, SpawnPolicy)
Spawns a GameObject with a provided decorator at the specified position and rotation. If you pass null to the decorator, the GameObject will be spawned as it is.
Declaration
public GameObject Spawn(IDecorator _Decorator, Vector3 _Position, Quaternion _Rotation, SpawnPolicy _SpawnPolicy)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. | 
| SpawnPolicy | _SpawnPolicy | The spawn policy to apply to the spawned GameObject. Applied before OnSpawn. | 
Returns
| Type | Description | 
|---|---|
| GameObject | 
Spawn(Vector3, Quaternion)
Spawns a GameObject 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 | 
Spawn(Vector3, Quaternion, SpawnPolicy)
Spawns a GameObject at the specified position and rotation.
Declaration
public GameObject Spawn(Vector3 _Position, Quaternion _Rotation, SpawnPolicy _SpawnPolicy)Parameters
| Type | Name | Description | 
|---|---|---|
| Vector3 | _Position | The position at which to spawn the GameObject. | 
| Quaternion | _Rotation | The rotation at which to spawn the GameObject. | 
| SpawnPolicy | _SpawnPolicy | The spawn policy to apply to the spawned GameObject. Applied before OnSpawn. | 
Returns
| Type | Description | 
|---|---|
| GameObject |