Esempio n. 1
0
    public void Add(ItemObject item)
    {
        SlotController _freeSlot = GetFreeSlot().GetComponent <SlotController>();
        int            _slotID   = _freeSlot.GetSlotID();

        item.inventoryData.SetSlotID(_slotID);
        _freeSlot.SetItem(item);
    }
Esempio n. 2
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);
        }
    }