using UnityEngine;

public sealed class GaugeX : GaugeParent {

    [SerializeField]
    private RectTransform gauge = default;

    private float gaugeSize = -1.0f;
    public float GaugeSize {
        get{ return gaugeSize; }
    }
    private Vector3 localPosition;

    public override void Initialize(float percentage = 0.0f){
        if(gaugeSize < 0.0f){
            gaugeSize = gauge.sizeDelta.x;
            localPosition = gauge.localPosition;
        }
        base.Initialize(percentage);
    }

    public override void UpdateGauge(float percentage){
        Vector2 sizeDelta = gauge.sizeDelta;
        sizeDelta.x = gaugeSize * Mathf.Clamp(percentage, 0.0f, 1.0f);
        gauge.sizeDelta = sizeDelta;
        this.percentage = percentage;

        // 何故かPositionにNaNが入るバグがあるっぽいので暫定対処
        gauge.localPosition = localPosition;
    }
}
