Пример #1
0
    public override void SwapItems(PointerEventData eventData)
    {
        var draggedObj = eventData.pointerDrag;

        if (draggedObj != null)
        {
            var inventorySlot = eventData.pointerDrag.GetComponent <Slot>();
            if (inventorySlot.icon.GetComponent <Image>().enabled)
            {
                if (inventorySlot.itemStack.Peek().type == slotType)
                {
                    Stack <Item> localItemStack = slot.itemStack;

                    var dragItem = draggedObj.GetComponent <DragItem>();
                    slot.RemoveItem();
                    slot.AddItem(inventorySlot.itemStack);
                    craftList.AddAt(slot.itemIndex, inventorySlot.itemStack);
                    inventorySlot.RemoveItem();
                    dragItem.SetDragVariables(1f, true, dragItem.defaultIconParent);
                    if (localItemStack != null && localItemStack.Peek().type == slotType)
                    {
                        inventorySlot.AddItem(localItemStack);
                        itemList.AddAt(inventorySlot.itemIndex, localItemStack);
                    }

                    if (inventorySlot.stackEvent != null)
                    {
                        inventorySlot.stackEvent.Raise();
                    }
                }
            }
        }
    }
Пример #2
0
    public virtual bool AddItem()
    {
        var stack = CheckIfContains(item);

        if (stack != null)
        {
            stack.Push(item);
            itemStack = stack;
            stackEvent.Raise();
            return(true);
        }
        else
        {
            var availableSlots = CheckAvailableSlots();
            if (availableSlots.Count > 0)
            {
                stack = new Stack <Item>();
                stack.Push(item);
                itemStack = stack;
                inventory.AddAt(availableSlots[0], stack);

                inventory.itemEvent.Raise();

                return(true);
            }
            else
            {
                return(false);
            }
        }
    }
Пример #3
0
    private void CraftItem(CraftingRecipe recipe)
    {
        List <int> availableSlots = CheckAvailableSlots();

        if (availableSlots.Count >= 3)
        {
            Stack <Item> stack = new Stack <Item>();
            stack.Push(recipe.craftedItem);
            AddItemToSlot(availableSlots[0], stack);
            inventory.AddAt(availableSlots[0], stack);

            SpendMaterials();

            inventory.itemEvent.Raise();
            stackedEvent.Raise();
        }
        else
        {
            Debug.Log("Not enough open slots");
        }
    }
Пример #4
0
    public override void SwapItems(Slot callingSlot)
    {
        var localItemStack = itemStack;
        var incomingStack  = callingSlot.itemStack;

        RemoveItem();
        callingSlot.RemoveItem();

        AddItem(incomingStack);
        equipment.AddAt(itemIndex, incomingStack);
        if (localItemStack != null && localItemStack.Peek().type == slotType)
        {
            callingSlot.AddItem(localItemStack);
            itemList.AddAt(callingSlot.itemIndex, localItemStack);
            equipment.itemEvent.Raise();
        }
        else
        {
            callingSlot.RemoveItem();
            itemList.itemEvent.Raise();
        }
    }