/// <summary> /// Create a new GameObject for the pool /// </summary> protected virtual T CreateObject() { T newObject = Object.Instantiate(prefab); newObject.gameObject.SetActive(false); newObject.transform.SetParent(container.transform, false); // Initialize the poolable object PoolableObject newPoolableObject = newObject.GetComponent <PoolableObject>(); if (newPoolableObject != null) { newPoolableObject.Initialize(this); } else { Debug.LogError(string.Format("Prefab '{0}' does not contain component '{1}'", prefab, typeof(PoolableObject))); } _objects.Push(newObject); return(newObject); }
public abstract void Return(PoolableObject aObject);
/// <summary> /// Get the pool attached to the PoolableObject's id /// </summary> public Pool Get(PoolableObject poolableObject) { return(Get(poolableObject.ID)); }
/// <summary> /// Remove the pool associated to the PoolableObject's id /// </summary> public void Remove(PoolableObject poolableObject) { _pools.Remove(poolableObject.ID); }
/// <summary> /// Add an Object Pool to the map of pools using the PoolableObject's id as a key /// </summary> public void Add(PoolableObject poolableObject, Pool pool) { _pools[poolableObject.ID] = pool; }