using UnityEngine;

public abstract class GaugeParent : MonoBehaviour {

    protected Coroutine coroutine = null;
    protected float percentage;
    public float Percentage {
        get{ return percentage; }
    }

    public virtual void Initialize(float percentage){
        this.SafeStopCoroutine(coroutine);
        UpdateGauge(percentage);
    }

    public void GaugeAnimation(float toParcentage, float duration){
        GaugeAnimation(this.percentage, toParcentage, duration);
    }
    public void GaugeAnimation(float fromPercentage, float toParcentage, float duration){
        if(gameObject.activeInHierarchy){
            this.SafeStopCoroutine(coroutine);
            coroutine = this.CallLerpSmooth(duration, lerp => {
                UpdateGauge(Mathf.Lerp(fromPercentage, toParcentage, lerp));
            }, () => {
                UpdateGauge(toParcentage);
            });
        }else{
            UpdateGauge(toParcentage);
        }
    }

    public abstract void UpdateGauge(float percentage);
}
