示例#1
0
    // @IDropHandler
    public void OnDrop(PointerEventData eventData)
    {
        if (eventData.pointerDrag != null)
        {
            GameObject     _otherSlotGo         = eventData.pointerDrag.gameObject.GetComponent <PerentReference>().perent;
            SlotController _otherSlotController = _otherSlotGo.GetComponent <SlotController>();
            ItemObject     _otherItem           = _otherSlotGo.GetComponent <ItemCell>().item;

            if (cell.item == null)
            {
                if (IsSameTypeForSlots(_otherItem, this.itemType))
                {
                    cell.item = _otherItem;
                    cell.item.inventoryData.SetSlotID(slotID);
                    TryActivateItemSprite();

                    _otherSlotController.RemoveItem();
                }
            }
            else
            {
                if (IsSameTypeForSlots(_otherItem, this.itemType) && IsSameTypeForSlots(cell.item, _otherSlotController.GetItemType()))
                {
                    /*  swap items  */
                    ItemObject _item = cell.item;
                    cell.item = _otherItem;
                    _otherSlotGo.GetComponent <ItemCell>().item = _item;

                    /*   set slot id   */
                    cell.item.inventoryData.SetSlotID(slotID);
                    _otherSlotGo.GetComponent <ItemCell>().item.inventoryData.SetSlotID(_otherSlotController.GetSlotID());

                    /*   refresh slot spries   */
                    TryActivateItemSprite();
                    _otherSlotController.TryActivateItemSprite();
                }
            }

            EventSubstitude eventSubstitude = new EventSubstitude();
            eventSubstitude.InvokeDressEvent(itemType, true, cell.item);
        }
    }