NextAvailableObject() public method

public NextAvailableObject ( bool autoActive ) : GameObject
autoActive bool
return GameObject
Ejemplo n.º 1
0
        /// <summary>
        /// Returns an available object from the pool
        /// OR null in case the pool does not have any object available & can grow size is false.
        /// </summary>
        /// <param name="poolName"></param>
        /// <returns></returns>
        public GameObject GetObjectFromPool(string poolName, bool autoActive = true, int autoCreate = 0)
        {
            GameObject result = null;

            if (!poolDict.ContainsKey(poolName) && autoCreate > 0)
            {
                InitPool(poolName, autoCreate, PoolInflationType.INCREMENT);
            }

            if (poolDict.ContainsKey(poolName))
            {
                Pool pool = poolDict[poolName];
                result = pool.NextAvailableObject(autoActive);
                //scenario when no available object is found in pool
#if UNITY_EDITOR
                if (result == null)
                {
                    Debug.LogWarning("[ResourceManager]:No object available in " + poolName);
                }
#endif
            }
#if UNITY_EDITOR
            else
            {
                Debug.LogError("[ResourceManager]:Invalid pool name specified: " + poolName);
            }
#endif


            return(result);
        }
Ejemplo n.º 2
0
    public static GameObject Spawn(string poolName, Transform parent, Vector3 position, Quaternion rotation, float lifetime)
    {
        GameObject result = null;

        if (instance.poolDictionary.ContainsKey(poolName))
        {
            Pool       pool = instance.poolDictionary[poolName];
            PoolObject po   = pool.NextAvailableObject();

            po.gameObject.SetActive(false);

            if (po != null)
            {
                po.lifetime = lifetime;
                result      = po.gameObject;
                Transform trans = po.transform;
                trans.SetParent(parent);
                trans.localPosition = position;
                trans.localRotation = rotation;

                po.gameObject.SetActive(true);
            }
            else
            {
                Debug.LogWarning("No object available in pool. Consider setting fixedSize to false.: " + poolName);
            }
        }
        else
        {
            Debug.LogError("Invalid pool name specified: " + poolName);
        }

        return(result);
    }
Ejemplo n.º 3
0
    /* Returns an available object from the pool
     * OR
     * null in case the pool does not have any object available & can grow size is false.
     */
    public GameObject GetObjectFromPool(string poolName, Vector2 position, Quaternion rotation)
    {
        GameObject result = null;

        if (poolDictionary.ContainsKey(poolName))
        {
            Pool pool = poolDictionary[poolName];
            result = pool.NextAvailableObject(position, rotation);
            //scenario when no available object is found in pool
            if (result == null)
            {
                Debug.LogWarning("No object available in pool. Consider setting fixedSize to false.: " + poolName);
            }
        }
        else
        {
            Debug.LogError("Invalid pool name specified: " + poolName);
        }

        return(result);
    }
        TweetView Add(float offset, int overrideIndex = -1)
        {
            var go = _pool.NextAvailableObject(true);

            go.transform.SetParent(TweetViewsRoot);
            go.transform.localPosition = new Vector3(0, offset);
            var view = go.GetComponent <TweetView>();

            if (overrideIndex == -1)
            {
                _instances.Add(view);
            }
            else
            {
                if ((overrideIndex < 0) || (overrideIndex > _instances.Count))
                {
                    Debug.LogErrorFormat("Invalid overrideIndex '{0}'", overrideIndex);
                    return(null);
                }
                _instances.Insert(overrideIndex, view);
            }
            return(view);
        }