コード例 #1
0
    public void StopDragging(ItemSlot _currentSlot)
    {
        if (_currentSlot == null && currentSlot == null)
        {
            Debug.Log("something went wrong!");
            //draggingRect.anchoredPosition = Vector2.zero;
            //draggingRect = null;
            //currentDragging = null;
            currentItem.AddItem(handler.item.item, handler.item.amount); //jump back to original spot
            return;
        }

        currentSlot = _currentSlot;

        if (currentSlot.Empty) //Current node is empty, just add the item.
        {
            currentSlot.AddItem(handler.item.item, handler.item.amount);
        }
        else
        {
            if (currentSlot.item.item.id == handler.item.item.id) //plus the two together
            {
                //check stacking
                if (currentSlot.item.amount + handler.item.amount > handler.item.item.stack)
                {
                    int diff = (currentSlot.item.amount + handler.item.amount) - handler.item.item.stack;
                    currentSlot.item.amount = currentSlot.item.item.stack;
                    currentSlot.UpdateUI();

                    handler.item.amount = diff;
                    handler.UpdateUI();

                    return; //Return - we dont want to stop dragging yet.
                }
                else        //else just add the amount
                {
                    currentSlot.AddItem(handler.item.item, handler.item.amount);
                }
            }
            else
            {
                //find out whats currently under
                InventoryItem under = currentSlot.item;
                //remove whats currently under, and add the handler item
                currentSlot.RemoveItem();
                currentSlot.AddItem(handler.item.item, handler.item.amount);
                //add what was under, to holder
                handler.RemoveItem();
                handler.AddItem(under);

                return;
            }
        }

        handler.RemoveItem();
        currentItem = null;
    }