Exemple #1
0
        /// <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);
        }
Exemple #2
0
 public abstract void Return(PoolableObject aObject);
Exemple #3
0
 /// <summary>
 /// Get the pool attached to the PoolableObject's id
 /// </summary>
 public Pool Get(PoolableObject poolableObject)
 {
     return(Get(poolableObject.ID));
 }
Exemple #4
0
 /// <summary>
 /// Remove the pool associated to the PoolableObject's id
 /// </summary>
 public void Remove(PoolableObject poolableObject)
 {
     _pools.Remove(poolableObject.ID);
 }
Exemple #5
0
 /// <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;
 }