UnityPooler.PoolableGameObject.AmountInPool C# (CSharp) Method

AmountInPool() public method

Count of GameObjects currently in the pool.
public AmountInPool ( ) : int
return int
        public int AmountInPool()
        {
            return _pooledObjs.Count;
        }

Usage Example

Example #1
0
        /// <summary>
        /// Populates the GameObject's object pool to the specified amount within an enumerator. Intended to work with
        /// https://github.com/GalvanicGames/unity-game-loader
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="amount"></param>
        /// <returns></returns>
        public static IEnumerator PopulatePoolCo(this GameObject obj, int amount)
        {
            PoolableGameObject poolable = obj.GetComponent <PoolableGameObject>();

            if (poolable == null)
            {
                Debug.LogErrorFormat(REQUIRES_COMP, obj.name, "PopulatePool");
            }
            else
            {
                int amountToAdd = amount - poolable.AmountInPool();

                for (int i = 0; i < amountToAdd; i++)
                {
                    poolable.IncrementPool();
                    yield return(null);
                }
            }

            yield return(null);
        }