コード例 #1
0
    public bool ContainsItem(int id, int amount)
    {
        // First, check if the item requested exists in the database
        Item item = ItemDataBase.instance.GetItemFromList(id);

        if (item != null)
        {
            // Item exists in database
            // Search through the hotbar and find the last index of the item
            for (int i = 0; i < hotbarSlots.Count; i++)
            {
                HotbarSlot slot = hotbarSlots[i];
                if (item == slot.GetItem())
                {
                    // Item exists, check if the amount there is the same as requested
                    if (slot.amount >= amount)
                    {
                        return(true);
                    }
                }
            }
        }

        return(false);
    }
コード例 #2
0
    private void DropSelectedItem()
    {
        HotbarSlot slot = hotbarSlots[curSelectedSlot - 1];
        Item       i    = slot.GetItem();

        if (i != null)
        {
            int itemAmount = slot.amount;


            for (int j = 0; j < itemAmount; j++)
            {
                ItemDataBase.instance.SpawnItem(slot.item.id, dropArea.position);
            }

            slot.gameObject.transform.GetChild(0).GetComponent <Image>().enabled = false;
            slot.amount = 0;
            curItem     = null;
            if (slot.item.stackable)
            {
                slot.transform.GetChild(2).GetComponent <TextMeshProUGUI>().text = "";
            }
            slot.item = null;
        }
    }