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