using DG.Tweening; using TMPro; using UnityEngine; using UnityEngine.UI; namespace BlueWater.Uis { public class DashUi : MonoBehaviour { [SerializeField] private Image _filled; [SerializeField] private Image _flash; [SerializeField] private TMP_Text _dashKeyText; [SerializeField] private float _fadeInOutDuration = 0.2f; private Tween _dashCooldownTween; private Tween _flashFadeTween; private string _dashKeyBinding; private void Awake() { EventManager.OnDashCooldown += DashCooldown; } private void Start() { _filled.fillAmount = 1f; _flashFadeTween = _flash.DOFade(1f, _fadeInOutDuration) .From(0f) .SetLoops(2, LoopType.Yoyo) .SetEase(Ease.Linear) .SetAutoKill(false) .Pause(); _dashKeyBinding = PlayerInputKeyManager.Instance.GetBoundKey(InputActionMaps.Tycoon, TycoonActions.Dash); SetKeyText(_dashKeyBinding); } private void OnDestroy() { EventManager.OnDashCooldown -= DashCooldown; _dashCooldownTween.Kill(); _flashFadeTween.Kill(); } private void SetKeyText(string bindingKey) { _dashKeyText.text = bindingKey; } public void DashCooldown(float cooldown) { _dashCooldownTween = _filled.DOFillAmount(1f, cooldown) .From(0f) .SetEase(Ease.Linear) .OnComplete(() => _flashFadeTween.Restart()) .SetAutoKill(true); } } }