Skip to content

Latest commit

 

History

History
41 lines (33 loc) · 932 Bytes

File metadata and controls

41 lines (33 loc) · 932 Bytes

Pool Utility

Pooling Utility is a simple and powerful pooling system for Unity. It is generic, so any object that implements base classes can be pooled easily.

Usage

  1. Inherit your monobehaviour object from PoolableObject class.
public class MyAwesomeEnemy:PoolableObject
{
    //Logic
}
  1. Inherit a data container from SpawnDataContainer for injecting data to your Monobehaviour class.
public class EnemySpawnData:SpawnDataContainer
{
    public Vector3 SpawnPosition;
}
  1. Use PoolManager to pool your object.
[SerializeField] private MyAwesomeEnemy prefab;

private void Start()
{
    PoolManager.GetInstance().GenerateNewPool(prefab);
}

Then you can spawn/despawn your prefab clones from the pool as follows:

//Request spawn
var spawnedObject = PoolManager.RequestSpawnForType(prefab,dataContainer);

//Request despawn
PoolManager.DespawnObject(prefab, spawnedObject);