popcorn/Scripts/Utilities/Gauge/GaugeY.cs

32 lines
883 B
C#

using UnityEngine;
public sealed class GaugeY : 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){
if(gaugeSize < 0.0f){
gaugeSize = gauge.sizeDelta.y;
localPosition = gauge.localPosition;
}
base.Initialize(percentage);
}
public override void UpdateGauge(float percentage){
Vector2 sizeDelta = gauge.sizeDelta;
sizeDelta.y = gaugeSize * Mathf.Min(1.0f, percentage);
gauge.sizeDelta = sizeDelta;
this.percentage = percentage;
// 何故かPositionにNaNが入るバグがあるっぽいので暫定対処
gauge.localPosition = localPosition;
}
}