10using System.Collections.Generic;
66 public static class Pool<T> where T : new() {
68 private static Stack<T> _pool =
new Stack<T>();
70 public static T Spawn() {
71 if (_pool ==
null) _pool =
new Stack<T>();
74 if (_pool.Count > 0) {
80 if (value is IPoolable) {
81 (value as IPoolable).OnSpawn();
87 public static void Recycle(T t) {
89 Debug.LogError(
"Cannot recycle a null object.");
94 (t as IPoolable).OnRecycle();
101 public static void Recycle(T t0, T t1) {
102 Recycle(t0); Recycle(t1);
106 public static void Recycle(T t0, T t1, T t2) {
107 Recycle(t0); Recycle(t1); Recycle(t2);
111 public static void Recycle(T t0, T t1, T t2, T t3) {
112 Recycle(t0); Recycle(t1); Recycle(t2); Recycle(t3);
Implement this interface to recieve a callback whenever your object is spawned from a pool.