This is a quick and lightweight solution that you can just immediately throw objects at to be pooled. (.Net 4.6+)
- No need to pre-define pools (although you can if you want).
- Calls Spawn/Despawn interface
- Neatly organized in project hierarchy
var obj = ObjectPooler.Instance.Spawn(prefab, position, rotation);
ObjectPooler.Instance.Despawn(gameObject);
public class Enemy : MonoBehaviour, IPoolable
{
public void Spawn()
{
// do stuff...
}
public void Despawn()
{
// do stuff...
}
}