Esempio n. 1
0
        /// <summary>
        /// Get a GameObject from a pool if there is any available
        /// </summary>
        /// <param name="prefab">The prefab to get, uses the prefab name</param>
        /// <param name="position">Position to set the acquired GameObject to</param>
        /// <param name="rotation">Rotation to set the acquired GameObject to</param>
        /// <returns></returns>
        public GameObject Create(GameObject prefab, Vector3 position, Quaternion rotation)
        {
            if (prefab.IsNull())
            {
                return(null);
            }

            string _key = PoolPrefab.GetKey(prefab);

            return(Create(_key, position, rotation));
        }
Esempio n. 2
0
 public void Add(GameObject prefab)
 {
     if (prefab.IsNull())
     {
         return;
     }
     if (PoolPrefab.GetKey(prefab) != Key)
     {
         return;                                   // Not apart of this pool
     }
     prefab.SetActive(false);
     m_pool.Enqueue(prefab);
 }
Esempio n. 3
0
        /// <summary>
        /// Return a GameObject to it's associated pool
        /// </summary>
        /// <param name="prefab">The prefab to return</param>
        public void Dispose(GameObject prefab)
        {
            if (prefab.IsNull())
            {
                return;
            }

            string _key = PoolPrefab.GetKey(prefab);

            if (m_poolDict.DoesNotContainKey(_key))
            {
                return;
            }

            UpdatePooledObjects(prefab, (IPooledObject _poolObj) => _poolObj.OnDespawned());

            m_poolDict[_key].Add(prefab);

            OnObjectReturned?.Invoke();
        }