示例#1
0
    public int Consume(int amount)
    {
        if (Amount <= 0)
        {
            Amount = 0;
            return(0);
        }
        Item oldItem   = Item;
        int  oldAmount = Amount;
        int  consumed  = Mathf.Min(Amount, amount);

        Amount -= consumed;
        if (Amount <= 0)
        {
            Item = null;
            if (oldItem != null)
            {
                OnSlotItemChanged?.Invoke(Index, oldItem);
            }
            Amount = 0;
        }
        OnSlotAmountChanged?.Invoke(Index, oldAmount);
        OnSlotChanged?.Invoke(Index);
        return(consumed);
    }
示例#2
0
    public void SetItem(Item item)
    {
        Item oldItem = Item;

        Item = item;
        OnSlotChanged?.Invoke(Index);
        OnSlotItemChanged?.Invoke(Index, oldItem);
    }
示例#3
0
    public void SetItemAmount(Item item, int amount)
    {
        Item oldItem   = Item;
        int  oldAmount = Amount;

        Item   = item;
        Amount = amount;
        OnSlotChanged?.Invoke(Index);
        OnSlotItemChanged?.Invoke(Index, oldItem);
        OnSlotAmountChanged?.Invoke(Index, oldAmount);
    }
示例#4
0
    public void SetAmount(int amount)
    {
        Item oldItem   = Item;
        int  oldAmount = Amount;

        Amount = Mathf.Max(amount, 0);
        if (Amount == 0)
        {
            Item = null;
            OnSlotItemChanged?.Invoke(Index, oldItem);
        }
        Amount = amount;
        OnSlotChanged?.Invoke(Index);
        OnSlotAmountChanged?.Invoke(Index, oldAmount);
    }
示例#5
0
    public bool TrySetItem(Item item)
    {
        Item oldItem = Item;

        if (CanSetItem(item))
        {
            if (Item == null)
            {
                Item = item;
                OnSlotChanged?.Invoke(Index);
                OnSlotItemChanged?.Invoke(Index, oldItem);
            }
            return(true);
        }
        return(false);
    }