示例#1
0
        /// <summary>
        /// This method is for auto-equip only.Don't use it anywhere else
        /// </summary>
        /// <param name="panel">Equipment panel to move item on</param>
        /// <param name="item">Item we want to equip</param>
        public void EquipItem(EquipmentPanel panel, InventoryItem item)
        {
            item.transform.SetParent(panel.mainSlot.transform.parent);

            item.finalPosition = panel.mainSlot.GetComponent <RectTransform>().anchoredPosition;

            item.x = panel.mainSlot.x;
            item.y = panel.mainSlot.y;

            MarkSlots(panel.mainSlot.x, panel.mainSlot.y, item.width, item.height, false);
            panel.equipedItem = item.item;
        }
示例#2
0
        public void UnequipItemFromPanel(EquipmentPanel panel)
        {
            if (panel.equipedItem != null && CheckFreeSpaceForAllSlots(panel.equipedItem.width, panel.equipedItem.height))
            {
                var item = FindInventoryItemHandlerByItem(panel.equipedItem);

                item.transform.SetParent(this.transform);

                var targetItemSlot = CheckFreeSpaceForAllSlots(panel.equipedItem.width, panel.equipedItem.height);

                MarkSlots(panel.mainSlot.x, panel.mainSlot.y, item.width, item.height, true);

                item.finalPosition = targetItemSlot.GetComponent <RectTransform>().anchoredPosition;
                item.x             = targetItemSlot.x;
                item.y             = targetItemSlot.y;

                item.equipmentPanel = null;

                MarkSlots(targetItemSlot.x, targetItemSlot.y, item.width, item.height, false);

                panel.equipedItem = null;
                panel.lastItem    = null;
            }
        }
示例#3
0
        public void OnEndDrag(PointerEventData eventData)
        {
            image.color = Color.white;

            Cursor.visible = true;

            image.raycastTarget = true;

            drag = false;

            inventory.DrawRegularSlotsColors();

            var eventDataRaycast = eventData.pointerCurrentRaycast;

            if (eventDataRaycast.gameObject == null && inventory.dragItemOutsideToDrop)
            {
                inventory.DropItem(this);
                return;
            }

            if (eventDataRaycast.gameObject != null &&
                item != null &&
                item.stackable == true &&
                eventDataRaycast.gameObject.GetComponent <InventoryItem>() != null &&
                eventDataRaycast.gameObject.GetComponent <InventoryItem>().item.id == item.id &&
                eventDataRaycast.gameObject.GetComponent <InventoryItem>().item.stackSize + item.stackSize <= item.maxStackSize)
            {
                eventDataRaycast.gameObject.GetComponent <InventoryItem>().item.stackSize += item.stackSize;
                inventory.RemoveItem(this);
                Destroy(gameObject);
                return;
            }

            if (eventDataRaycast.gameObject != null && eventDataRaycast.gameObject.GetComponent <GridSlot>())
            {
                var slot = eventData.pointerCurrentRaycast.gameObject.GetComponent <GridSlot>();

                if (inventory.CheckFreeSpaceAtSlot(CalculateShiftedAxes().x, CalculateShiftedAxes().y, width, height) && slot.free && slot.equipmentPanel == null)
                {
                    transform.SetParent(slot.transform.parent);

                    finalPosition = inventory.FindSlotByIndex(CalculateShiftedAxes().x, CalculateShiftedAxes().y).GetComponent <RectTransform>().anchoredPosition;

                    x = CalculateShiftedAxes().x;
                    y = CalculateShiftedAxes().y;

                    equipmentPanel = null;

                    inventory.MarkSlots(CalculateShiftedAxes().x, CalculateShiftedAxes().y, width, height, false);
                }
                else if (inventory.CheckFreeSpaceAtSlot(CalculateShiftedAxes().x, CalculateShiftedAxes().y, width, height) && slot.free && slot.equipmentPanel != null && slot.equipmentPanel.allowedItemType == item.type)
                {
                    transform.SetParent(slot.transform.parent);

                    finalPosition = inventory.FindSlotByIndex(CalculateShiftedAxes().x, CalculateShiftedAxes().y).GetComponent <RectTransform>().anchoredPosition;

                    x = CalculateShiftedAxes().x;
                    y = CalculateShiftedAxes().y;

                    slot.equipmentPanel.equipedItem = item;

                    equipmentPanel = slot.equipmentPanel;

                    inventory.MarkSlots(CalculateShiftedAxes().x, CalculateShiftedAxes().y, width, height, false);
                }
                else
                {
                    finalPosition = lastPosition;
                    inventory.MarkSlots(x, y, width, height, false);
                }
            }
            else
            {
                finalPosition = lastPosition;
                inventory.MarkSlots(x, y, width, height, false);
            }
        }