public void Start() { Current = Max; OnChanged += (a, b) => OnFillValueChanged(); OnFillValueChanged?.Invoke(); Debug.Log($"Health initialized and set to {Max}."); }
private void UpdateRecovery(int amount, bool lerp) { if (lerp) { var to = exhaustionLevel - (float)amount; if (to <= 0) { to = 0; } StartCoroutine(Lerp(exhaustionLevel, to, 5f)); } else { exhaustionLevel -= amount; } if (exhaustionLevel <= 0) { exhaustionLevel = 0; } OnFillValueChanged?.Invoke(); }
public void RecoverHunger(int amount) { hunger -= amount; if (hunger <= 0) { hunger = 0; } OnFillValueChanged?.Invoke(); }
public void Gain(int _amount, ISource _source) { int prev = current; current += _amount; current = Mathf.Clamp(current, min, max); if (current != prev) { OnResourceGained?.Invoke(current - prev, _source); OnChanged?.Invoke(prev, current); OnFillValueChanged?.Invoke(); } }
public void IncreaseHunger() { hunger += 1; if (hunger >= 100) { hunger = 100; } OnFillValueChanged?.Invoke(); if (hunger == 100) { Die(); } }
public void Lose(int _amount, ISource _source) { int prev = current; current -= _amount; current = Mathf.Clamp(current, min, max); if (current != prev) { OnResourceLost?.Invoke(prev - current, _source); OnChanged?.Invoke(prev, current); OnFillValueChanged?.Invoke(); } if (current == min) { OnEmpty?.Invoke(); } }
// ----------- Lerp Coroutine ----------- IEnumerator Lerp(float amountFrom, float amountTo, float timeToComplete) { //Debug.LogError($"AmountFrom: {amountFrom} | AmountTo: {amountTo} | timeToComplete: {timeToComplete}"); float timeRemaining = timeToComplete; while (timeRemaining > 0) { timeRemaining -= Time.deltaTime; var lerp = Mathf.Lerp(amountFrom, amountTo, Mathf.InverseLerp(timeToComplete, 0, timeRemaining)); exhaustionLevel = Mathf.RoundToInt(lerp); OnFillValueChanged?.Invoke(); //Debug.Log($"timeRemaining {timeRemaining}"); yield return(null); } exhaustionLevel = Mathf.RoundToInt(amountTo); OnFillValueChanged?.Invoke(); }
public void SetCurrent(int _amount) { current = (int)_amount; OnFillValueChanged?.Invoke(); }
public void SetMax(int _amount) { max = (int)_amount; OnFillValueChanged?.Invoke(); }
public void SetMin(int _amount) { min = (int)_amount; OnFillValueChanged?.Invoke(); }
protected virtual void TriggerOnFillValueChanged() { currentResource = (int)resource.Current; OnFillValueChanged?.Invoke(); }
private void UpdateMaterialProgress(bool unused) { print("OnFillValueChanged Invoked"); OnFillValueChanged?.Invoke(); }