Example #1
0
    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();
    }