コード例 #1
0
    public bool Remove(int id, int num = 1)
    {
        ItemData itemData = DataTableManager.singleton.GetItemData(id);

        if (itemData == null)
        {
            Debug.LogError(LogUtility.MakeLogStringFormat("Inventory", "Try to remove non-existing item (id = {0}).", id));
        }
        else if (items.ContainsKey(id))
        {
            if (items[id] >= num)
            {
                items[id] -= num;

                attributes.Decrement(itemData.Attributes, OnAttributeChange, num);

                OnItemNumChange.Invoke(itemData, items[id], -num);

                return(true);
            }
            else if (items[id] == num)
            {
                items.Remove(id);

                attributes.Decrement(itemData.Attributes, OnAttributeChange, num);

                OnItemNumChange.Invoke(itemData, 0, -num);

                return(true);
            }
        }

        return(false);
    }