public void OnDrop(GameObject receiveSlotGameObject) { DragItem receiveDragItem = receiveSlotGameObject.GetComponent <DragItem>(); if (receiveDragItem == null) { return; } InventorySlotUI receiveInventorySlotUI = receiveDragItem.originalParent.GetComponent <InventorySlotUI>(); Slot receiveSlot = receiveInventorySlotUI.GetSlot(); if (receiveSlot == slot) { return; } if (receiveSlot == null || receiveSlot.item == null) { return; } if (readOnly || receiveInventorySlotUI.readOnly) { return; } if (Slot.hasEqualItemIDs(slot, receiveSlot) && slot.amount + receiveSlot.amount <= slot.maxAmount) { slot.AddAmount(receiveSlot.amount); UpdateSlot(); receiveInventorySlotUI.SetSlot(new Slot(null, 0)); } else { if (slot != null && slot.item != null && !receiveInventorySlotUI.canReceive || !canReceive) { return; } receiveInventorySlotUI.SetSlot(slot); SetSlot(receiveSlot); } InventoryUI slotInventoryUI = GetComponentInParent <InventoryUI>(); InventoryUI receiveSlotInventoryUI = receiveDragItem.originalParent.GetComponentInParent <InventoryUI>(); slotInventoryUI.UpdateInvetory(); receiveSlotInventoryUI.UpdateInvetory(); }
InventorySlotUI AddSlot() { InventorySlotUI slot = Instantiate(slotPrefab, transform); Navigation customNav = slot.GetComponent <Button>().navigation; Navigation leftNav, upNav; int index = slots.Count; int y = index / columns; int x = index % columns; if (y == 0) { customNav.selectOnUp = interactableUp; upNav = interactableUp.navigation; if (x == 0) { upNav.selectOnDown = slot.GetComponent <Button>(); interactableUp.navigation = upNav; } } else { customNav.selectOnUp = getSlot(x, y - 1).GetComponent <Button>(); upNav = getSlot(x, y - 1).GetComponent <Button>().navigation; upNav.selectOnDown = slot.GetComponent <Button>(); getSlot(x, y - 1).GetComponent <Button>().navigation = upNav; } if (x == 0) { } else { customNav.selectOnLeft = getSlot(x - 1, y).GetComponent <Button>(); leftNav = getSlot(x - 1, y).GetComponent <Button>().navigation; leftNav.selectOnRight = slot.GetComponent <Button>(); getSlot(x - 1, y).GetComponent <Button>().navigation = leftNav; } slot.GetComponent <Button>().navigation = customNav; slots.Add(slot); slot.SetSlot(index, panel); return(slot); }