private void InstantiateSlots() { // Create one empty slot until we hit the bags capacity for (int i = 0; i < _itemBag.Capacity; i++) { InventorySlotUI uiSlot = Instantiate(_inventorySlotUIPrefab, _slotHolder); uiSlot.ShowEmptyItem(); _inventorySlots.Add(uiSlot); } }
private void OnItemRemoved(Item item, ItemBag bag) { // item can only be removed if it is contained in this bag and its not null if ((item == null) || (bag != _itemBag)) { return; } // Search for the inventory slot with the given item InventorySlotUI uiSlot = FindInventorySlotUIForItem(item); if (uiSlot != null) { // remove it from that slot uiSlot.RemoveItem(item); } }
private void OnItemAdded(Item item, ItemBag bag) { // item can only be added if it is contained in this bag and its not null if ((item == null) || (bag != _itemBag)) { return; } // Search for the inventory slot with the given item InventorySlotUI uiSlot = FindInventorySlotUIForItem(item); if (uiSlot != null) { // add it to that slot uiSlot.AddItem(item); } else { // if it is in no slot, find the first empty one and add it there uiSlot = FindFirstEmptyInventorySlot(); uiSlot.AddItem(item); } }