public void StopDragging()
        {
            (List <RaycastHit2D>, List <RaycastResult>)underTheMouse = _mouseCursorComponent.GetEveryObjectUnderTheMouse();

            InventorySlotComponent targetInventorySlot = underTheMouse.Item2.Where(e => e.gameObject.GetComponent <InventorySlotComponent>() != null)
                                                         .Select(e => e.gameObject.GetComponent <InventorySlotComponent>())
                                                         .FirstOrDefault();

            InteractableComponent playerInteractableComponent = GetCurrentInteractableComponentUnderTheMouseThatsCanEat(underTheMouse);

            // => CHANGE ITEM SLOT
            if (targetInventorySlot != null && targetInventorySlot.GetInstanceID() != _dragInventorySlot.GetInstanceID())
            {
                if (targetInventorySlot.CheckIfCanAcceptItem(_dragItem))
                {
                    targetInventorySlot.SetItem(_dragItem);
                }
                else
                {
                    _dragInventorySlot.SetItem(_dragItem);
                }
            }
            // => FEED THE PLAYER
            else if (playerInteractableComponent != null && _dragItem.Item.ItemType == ScriptableComponents.Item.EnumItemScriptableType.Flower)
            {
                _dragItem.Amount--;

                playerInteractableComponent.EatFlowerByDrag(new ItemDTO()
                {
                    Item = _dragItem.Item, Amount = 1
                });

                if (_dragItem.Amount > 0)
                {
                    _dragInventorySlot.SetItem(_dragItem);
                }
            }
            // => DROP ITEM
            else if (targetInventorySlot == null)
            {
                this.DropItem();
            }
            // => PUT ITEM ON THE SAME SPOT
            else
            {
                _dragInventorySlot.SetItem(_dragItem);
            }

            _image.enabled     = false;
            transform.position = _initialPosition;
            _dragInventorySlot = null;
            IsDragging         = false;
            _mouseCursorComponent.HasItemUnderTheCursor = false;
        }
示例#2
0
        public void AddItem(ItemDTO newItem)
        {
            InventorySlotComponent emptySlot = _slotList.FirstOrDefault(e => e.CheckIfCanAcceptItem(newItem));

            if (emptySlot == null)
            {
                Debug.LogError("Your inventory is full!");
                return;
            }

            emptySlot.SetItem(newItem);
        }