GenericPooler.GetPooledObject C# (CSharp) Method

GetPooledObject() public method

public GetPooledObject ( string objType ) : GameObject
objType string
return GameObject
    public GameObject GetPooledObject(string objType)
    {
        List<GameObject> iterList;                                      // Temp list to grab all objects of requested type

        if (poolDict.ContainsKey(objType))                              // Check if the requested object is in the pool
        {
            iterList = poolDict[objType];                               // Grab all objects of requested type

            for (int i = 0; i < iterList.Count; i++)                    // Iterate through requested types
            {

                if (!iterList[i].activeInHierarchy)                     // If an inactive one is found return it
                    return iterList[i];
            }
        }

        return null;
    }

Usage Example

Esempio n. 1
0
        private void GenerateLoot(ILootable lootable)
        {
            LootConfig.LootDropDef lootDropDef = lootable._lootDropDef;

            List <LootConfig.ProbabilityDef> probabilities = lootDropDef.probabilities;

            probabilities.Sort(LootUtil.CompareLootByProbability);

            int   lootToDrop = LootUtil.GetLootDropCount(lootDropDef);
            float totalSum   = LootUtil.GetTotalSum(probabilities);

            for (int i = 0; i < lootToDrop; i++)
            {
                Loot.Rarity        rarity  = LootUtil.GetWeightedRarity(probabilities, totalSum);
                LootConfig.LootDef lootDef = _lootConfig.GetLootDef(rarity);
                int bucket = Random.Range(0, lootDef.lootItems.Count);
                LootConfig.LootItemDef itemDef = lootDef.lootItems[bucket];
                string    key  = Storeable.GetCachedStoreableKey(itemDef.type);
                ILootItem item = _lootPool.GetPooledObject(key).GetComponent <ILootItem>();
                if (item != null)
                {
                    item.Init(lootable, _playerCombatSystem.playerController.transform, lootDef, _lootConfig, itemDef);
                }
                else
                {
                    Debug.LogError("Item of type " + key + " does not implement  ILootItem");
                }
            }
        }
All Usage Examples Of GenericPooler::GetPooledObject