public Item GetItem(string id, Itemtype itemType) { ItemsScriptableObject obj = Resources.Load(StaticStrings.ItemsScriptableObject_FileName) as ItemsScriptableObject; if (obj == null) { Debug.Log("Couldn't find the file: " + StaticStrings.ItemsScriptableObject_FileName + " under Resources!"); } Dictionary <string, int> dict = null; List <Item> listItem = null; switch (itemType) { case Itemtype.Weapon: dict = item_Weapons; listItem = obj.weapon_Items; break; case Itemtype.Spell: dict = item_Spells; listItem = obj.spell_Items; break; case Itemtype.Consumable: dict = item_Consumables; listItem = obj.consumable_Items; break; case Itemtype.Equipment: default: return(null); } if (dict == null) { return(null); } if (listItem == null) { return(null); } int index = GetIndexFromString(dict, id); if (index == -1) { return(null); } return(listItem[index]); }
void LoadItems() { ItemsScriptableObject obj = Resources.Load(StaticStrings.ItemsScriptableObject_FileName) as ItemsScriptableObject; if (obj == null) { Debug.Log("Couldn't load spell item from: " + StaticStrings.ItemsScriptableObject_FileName); } //Weapon Items for (int i = 0; i < obj.weapon_Items.Count; i++) { if (item_Weapons.ContainsKey(obj.weapon_Items[i].item_id)) { Debug.Log("Weapon Item already exists in the resource manager dictionary!"); } else { item_Weapons.Add(obj.weapon_Items[i].item_id, i); } } //Spell Items for (int i = 0; i < obj.spell_Items.Count; i++) { if (item_Spells.ContainsKey(obj.spell_Items[i].item_id)) { Debug.Log("Spell Item already exists in the resource manager dictionary!"); } else { item_Spells.Add(obj.spell_Items[i].item_id, i); } } //Consumable Items for (int i = 0; i < obj.consumable_Items.Count; i++) { if (item_Consumables.ContainsKey(obj.consumable_Items[i].item_id)) { Debug.Log("Consumable Item already exists in the resource manager dictionary!"); } else { item_Consumables.Add(obj.consumable_Items[i].item_id, i); } } }