using System; using DG.Tweening; using SLSFramework.General; using UnityEngine; using UnityEngine.UI; namespace SLSFramework.UI { public class AttributeBarBase : UIElementBase { public Image fillImage; public LerpFloat fillLerp = new LerpFloat(1f, 0.2f); public bool useLerpColor; public LerpColor fillColor; protected virtual void Awake() { fillLerp = new LerpFloat(1f, 0.2f); } public void UpdateFillImage(float currentValue, float maxValue, bool isInstant = false) { if (maxValue < 0) { Debug.LogWarning("Max value is less than zero. Cannot update fill image."); return; } if (currentValue <= 0) { fillImage.fillAmount = 0; return; } if (!isInstant) { float targetFill = currentValue / maxValue; fillLerp.targetValue = targetFill; } else { fillLerp.targetValue = currentValue / maxValue; fillLerp.currentValue = currentValue / maxValue; } } public void UpdateFillColor(Color color, bool isInstant = false) { if (useLerpColor) { if (!isInstant) { fillColor.targetValue = color; } else { fillColor.targetValue = color; fillColor.currentValue = color; } } else { fillImage.color = color; } } public void Update() { fillLerp.Update(1); fillImage.fillAmount = fillLerp.currentValue; if (useLerpColor) { fillColor.Update(1); fillImage.color = fillColor.currentValue; } } private Tweener blinkTweener; public virtual void Blink(Color blinkColor, float duration = 0.2f) { blinkTweener?.Kill(); Color originalColor = useLerpColor ? fillColor.targetValue : fillImage.color; blinkTweener = fillImage.DOColor(blinkColor, duration / 2).SetLoops(2, LoopType.Yoyo).OnComplete(() => { fillImage.color = originalColor; }); blinkTweener.Play(); } } }