public static void AddToPool <T>(ref T[] pool, IMonoBehaviourPool item) where T : IMonoBehaviourPool { Array.Resize(ref pool, pool.Length + 1); int id = pool.Length - 1; pool[id] = (T)item; }
public static IMonoBehaviourPool TryGetMonoBehaviourFromPool <T>(ref T[] pool, IMonoBehaviourPool prefab) where T : IMonoBehaviourPool { IMonoBehaviourPool item = GetAvailableMonoBehaviourInPool(pool); if (item == null) { item = GameObject.Instantiate(prefab.MonoBehaviourReference) as IMonoBehaviourPool; AddToPool(ref pool, item); } item.GameObjectReference.SetActive(true); return(item); }
public static IMonoBehaviourPool GetAvailableMonoBehaviourInPool <T>(T[] pool) where T : IMonoBehaviourPool { IMonoBehaviourPool toReturn = null; for (int i = 0; i < pool.Length; i++) { GameObject item = pool[i].GameObjectReference; if (!item.activeSelf) { toReturn = pool[i]; break; } } return(toReturn); }