public void AddItem(int itemId, KeyItemType itemType) { /* To avoid passing lots of pointless banana, an id and a type will be passed. * Depending on what that type is will depend on the prefab to use for that item * in the actual inventory. So somewhere there should be a sort of DB that'll map * the type of the item to the assigned inventory prefab. For now I'll just stick * it in here. Naturally. * The pickup in the meantime is long gone having transfered its id to the inventory. */ if (HasItem(itemId)) { return; } // So we create a new instance of a key item type to hold on to. var itemToAdd = new UIInventoryItem() { ItemType = itemType, Id = itemId, ItemSprite = GetPrefab(itemType) }; for (int i = 0; i < items.Length; i++) { if (items[i] == null) { items[i] = itemToAdd; itemImages[i].sprite = itemToAdd.ItemSprite; itemImages[i].enabled = true; return; } } }
public bool HasItemType(KeyItemType type) { return(items != null && items .Any(x => x != null && x.ItemType == type)); }
private Sprite GetPrefab(KeyItemType Type) { return(ItemTypes.Find(x => x.ItemType == Type) .InventorySprite); }