public void Start()
 {
     Current    = Max;
     OnChanged += (a, b) => OnFillValueChanged();
     OnFillValueChanged?.Invoke();
     Debug.Log($"Health initialized and set to {Max}.");
 }
Exemple #2
0
    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();
    }
Exemple #3
0
    public void RecoverHunger(int amount)
    {
        hunger -= amount;

        if (hunger <= 0)
        {
            hunger = 0;
        }

        OnFillValueChanged?.Invoke();
    }
Exemple #4
0
        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();
            }
        }
Exemple #5
0
    public void IncreaseHunger()
    {
        hunger += 1;

        if (hunger >= 100)
        {
            hunger = 100;
        }

        OnFillValueChanged?.Invoke();

        if (hunger == 100)
        {
            Die();
        }
    }
Exemple #6
0
        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();
            }
        }
Exemple #7
0
    // ----------- 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();
    }
Exemple #8
0
 public void SetCurrent(int _amount)
 {
     current = (int)_amount;
     OnFillValueChanged?.Invoke();
 }
Exemple #9
0
 public void SetMax(int _amount)
 {
     max = (int)_amount;
     OnFillValueChanged?.Invoke();
 }
Exemple #10
0
 public void SetMin(int _amount)
 {
     min = (int)_amount;
     OnFillValueChanged?.Invoke();
 }
 protected virtual void TriggerOnFillValueChanged()
 {
     currentResource = (int)resource.Current;
     OnFillValueChanged?.Invoke();
 }
Exemple #12
0
 private void UpdateMaterialProgress(bool unused)
 {
     print("OnFillValueChanged Invoked");
     OnFillValueChanged?.Invoke();
 }