Exemple #1
0
        ///<summary>create other poolobject if the pool doesn't have any free ones.
        ///This is just for safety of the runtime, but will require to change it in editor mode
        ///</summary>
        private GameObject DynamicGrowPool(sPool aPool)
        {
            Debug.LogErrorFormat("Pool Too Small: The Pool {0} is not big enough, Creating {1} more PooledObject! Increments the pool size!", aPool.prefab.name, aPool.amount);

            GrowPool(aPool);
            return(GetObjectFromPool(aPool.prefab));
        }
Exemple #2
0
 ///<summary>Extend the Pool by creating all poolObject ask for</summary>
 private void GrowPool(sPool aPool)
 {
     for (int i = 0; i < aPool.amount; i++)
     {
         CreatePooledObject(aPool.prefab);
     }
 }
Exemple #3
0
 ///<summary>Create the pools for each object set in the data</summary>
 private void CreatePools()
 {
     for (int i = 0; i < m_Pools.Count; i++)
     {
         sPool pool = m_Pools[i];
         if (IsValidPoolObject(pool))
         {
             m_PoolsInactiveObjects.Add(pool.prefab, new List <GameObject>());
             m_PoolsActiveObjects.Add(pool.prefab, new List <GameObject>());
             GrowPool(pool);
         }
     }
 }
Exemple #4
0
        ///<summary>Manually return a PooledObject.</summary>
        public void ReturnedPooledObject(PooledObjSettings a_PooledObject, GameObject a_PoolOwner)
        {
            sPool pool = GetPoolStruct(a_PooledObject.gameObject);

            if (m_PoolsActiveObjects.ContainsKey(a_PooledObject.PoolOwner))
            {
                List <GameObject> activeObjects = m_PoolsActiveObjects[a_PoolOwner];

                if (activeObjects.Count != 0)
                {
                    activeObjects.Remove(a_PooledObject.gameObject);
                }
            }
        }
Exemple #5
0
        ///<summary>Get the oldest pooledobject to re-use it for a new one</summary>
        private GameObject UseFirstActivePooledObject(sPool aPool)
        {
            List <GameObject> activeObjects = new List <GameObject>();

            m_PoolsActiveObjects.TryGetValue(aPool.prefab, out activeObjects);

            if (activeObjects.Count != 0)
            {
                GameObject firstElement = activeObjects[0];
                activeObjects.RemoveAt(0);
                return(firstElement);
            }

            return(null);
        }
Exemple #6
0
        //If there's no inactive poolObject -> Catch Action : Get oldest active pooledObject or DynamicSafeGrowPool
        private GameObject NotEnoughPooledObject(GameObject aPrefab)
        {
            sPool pool = GetPoolStruct(aPrefab);

            if (IsValidPoolObject(pool))
            {
                if (!pool.overlapse)
                {
                    return(UseFirstActivePooledObject(pool));
                }
                else
                {
                    return(DynamicGrowPool(pool));
                }
            }

            return(null);
        }
Exemple #7
0
 ///<summary> Check if the poolObject ask for is valid </summary>
 private bool IsValidPoolObject(sPool aPool)
 {
     return(aPool.prefab != null);
 }