Пример #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);
        }
    }
Пример #2
0
    public void OnEndDrag(PointerEventData eventData)
    {
        GameObject          _inventory           = Global.Obj.GetInventory();
        InventoryController _inventoryController = _inventory.GetComponent <InventoryController>();
        GameObject          _slot           = eventData.pointerDrag.GetComponent <PerentReference>().perent;
        ItemObject          _item           = _slot.GetComponent <ItemCell>().item;
        SlotController      _slotController = _slot.GetComponent <SlotController>();

        if (IsPointerOverUIElement() == false)
        {
            _inventoryController.DropItem(_item, _slotController.GetContainerItemType());
            _slotController.RemoveItem();
        }

        EventSubstitude eventSubstitude = new EventSubstitude();

        eventSubstitude.InvokeDressEvent(_slotController.GetItemType(), false);

        itemSpriteCanvasGroup.blocksRaycasts = true;
        rt.anchoredPosition = originPosition;
    }