Exemple #1
0
    /// <summary>
    /// Select the item currently held in the slot, or place an item in the slot
    /// </summary>
    public void SelectItem()
    {
        // If no item is currently selected
        if (!ItemSelector.Instance().ItemSelected())
        {
            if (HasItem())
            {
                ItemSelector.Instance().item   = ItemInSlot;
                ItemSelector.Instance().source = this;
                itemIcon.GetComponent <Image>().color = new Color(1, 1, 1, 0.5f);
                ItemSelector.Instance().isResultItem = isResultSlot;
            }
        }
        // If an item is currently selected and you are not clicking on the result ItemSlot
        else if (ItemSelector.Instance().ItemSelected() && !isResultSlot)
        {
            bool isPlaced = false;

            // If the currently selected item is NOT the result item and it does not match the item in the clicked ItemSlot
            if (!ItemSelector.Instance().isResultItem&& HasItem() && ItemSelector.Instance().item != ItemInSlot)
            {
                isPlaced = true;
            }
            // If the currently selected item matches the item in the clicked ItemSlot
            else if (HasItem() && ItemSelector.Instance().item == ItemInSlot)
            {
                SetContents(ItemInSlot, ItemCount + 1);
                ItemSelector.Instance().source.DecrementItemCount();
                isPlaced = true;
            }
            else if (!HasItem())
            {
                ItemSelector.Instance().source.DecrementItemCount();
                SetContents(ItemSelector.Instance().item, 1);
                isPlaced = true;
            }

            if (isPlaced)
            {
                ItemSelector.Instance().ClearSelection();
            }
            UpdateSlot();
        }
        // Deselects your item if its not the result item and you click on the result slot
        else if (ItemSelector.Instance().ItemSelected() && isResultSlot && !ItemSelector.Instance().isResultItem)
        {
            ItemSelector.Instance().ClearSelection();
        }
    }