IPoolable¶
An interface that poolable classes can implement to get notified when they’re spawned or despawned.
Need multiple MonoBehaviours to get notified when their prefab instance is spawned or despawned then look atPoolableGroup.
Usage¶
Just implement the interface in the pooled class.
publicclassMyPooledClass:IPoolable{publicvoidOnSpawned(){Debug.Log("I'm alive!");}publicvoidOnDespawned(){Debug.Log("Back into the pool I go :(");}}// somewhere elsevarmyInstance=PoolHelper<MyPooledClass>.Spawn();Debug.Log("I just spawned myInstance");PoolHelper<MyPooledClass>.Despawn(myInstance);Debug.Log("I just despawned myInstance");
Will output:
I'm alive!I just spawned myInstanceBack into the pool I go :(I just despawned myInstance