/// <summary> /// Increments the prefab's or GameObject's object pool. /// </summary> /// <param name="objToInc">The prefab or GameObject to increment.</param> public static void IncrementPoolWithObj(GameObject objToInc) { PoolableGameObject poolable = objToInc.GetComponent <PoolableGameObject>(); if (poolable == null) { Debug.LogErrorFormat(REQUIRES_COMP, objToInc.name, "IncrementPool"); return; } poolable.IncrementPool(); }
/// <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); }