CapersProject/Assets/02.Scripts/Ui/Tycoon/DashUi.cs

69 lines
1.7 KiB
C#
Raw Normal View History

2024-11-19 06:03:43 +00:00
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);
}
}
}