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); }
public void SetItem(Item item) { Item oldItem = Item; Item = item; OnSlotChanged?.Invoke(Index); OnSlotItemChanged?.Invoke(Index, oldItem); }
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); }
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); }
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); }