public void SetAmount(int value) { if (Capacity == 0) { amount = 0; liquid?.SetFillPercentage(0); } else { amount = Math.Max(Math.Min(value, Capacity), 0); // liquid is null when OnValidate is called twice before Awake // when playing in Editor Mode // See: https://forum.unity.com/threads/onvalidate-called-twice-when-pressing-play-in-the-editor.430250/ float percentage = (float)amount / capacity; liquid?.SetFillPercentage(percentage); } OnAmountChange?.Invoke(); }
//Observer pattern for booster values (used to update the view public void AddRangeBoosterAmountListener(OnAmountChange callback) { rangeBoosterAmountListeners.Add(callback); }
public void RemoveRangeBoosterAmountListener(OnAmountChange callback) { rangeBoosterAmountListeners.Remove(callback); }
private void SendEvents() { OnAmountChange.Invoke(currentAmount); OnAmount01Change.Invoke(Current01Amount); }
public void SetAmount(int amount) { m_Amount = amount; OnAmountChange?.Invoke(); }
public void ChangeAmount(int amount) { m_Amount += amount; OnAmountChange?.Invoke(); }
public MyInventory(int maxItems) { MaxItems = maxItems; PriceCoeficient = DEFAULT_PRICE_COEFICIENT; m_onItemAmountChangeHandler = new OnAmountChange(OnAmountChange); }