92 lines
3.4 KiB
C#
92 lines
3.4 KiB
C#
using ChocDino.UIFX;
|
|
using Cielonos.MainGame.Characters;
|
|
using DG.Tweening;
|
|
using SLSUtilities.UI;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Cielonos.MainGame.UI
|
|
{
|
|
public class DodgeFunctionIcon : UIElementBase
|
|
{
|
|
public Image frame;
|
|
public Image iconImage;
|
|
public Image timerImage;
|
|
public TMP_Text timerText;
|
|
public TMP_Text costText;
|
|
|
|
private Sequence _frameOutlineSequence;
|
|
|
|
private void Start()
|
|
{
|
|
// 如果闪避不需要显示固定的能量消耗,可以在开始时隐藏消耗文本
|
|
// (如果你们后续为闪避增加了体力消耗,也可以在这里调整显示逻辑)
|
|
if (costText != null)
|
|
{
|
|
costText.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public override void UpdateUI()
|
|
{
|
|
Player player = MainGameManager.Player;
|
|
if (player == null || player.movementSc == null) return;
|
|
|
|
float maxCooldown = player.attributeSm[CharacterAttribute.DodgeInterval];
|
|
float currentCooldown = player.movementSc.dodgeIntervalTimer;
|
|
bool isActionOngoing = player.landMovementSc.isDashing || player.landMovementSc.isDodging;
|
|
|
|
if (isActionOngoing)
|
|
{
|
|
// 动作持续期间,保持遮罩全满,且不显示文字
|
|
if (timerImage != null) timerImage.fillAmount = 1f;
|
|
if (timerText != null) timerText.text = "";
|
|
}
|
|
else if (maxCooldown <= 0f)
|
|
{
|
|
if (timerImage != null) timerImage.fillAmount = 0;
|
|
if (timerText != null) timerText.text = "";
|
|
}
|
|
else
|
|
{
|
|
float fillAmount = Mathf.Clamp01(currentCooldown / maxCooldown);
|
|
if (timerImage != null) timerImage.fillAmount = fillAmount;
|
|
|
|
if (timerText != null)
|
|
{
|
|
if (currentCooldown > 0f)
|
|
{
|
|
timerText.text = currentCooldown.ToString("F1");
|
|
}
|
|
else
|
|
{
|
|
timerText.text = "";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SetFrameOutline(float totalDuration, Color color = default, float intensity = 0.5f)
|
|
{
|
|
if (frame == null) return;
|
|
|
|
color = color == default ? Color.white : color;
|
|
Color hdrColor = color * Mathf.Pow(2f, intensity);
|
|
GlowFilter glowFilter = frame.GetComponent<GlowFilter>();
|
|
if (glowFilter == null) return;
|
|
|
|
glowFilter.Color = hdrColor;
|
|
float fadeDuration = Mathf.Clamp(totalDuration / 2f, 0.2f, totalDuration);
|
|
float stayDuration = totalDuration - fadeDuration;
|
|
float strengthPeak = 0.5f;
|
|
_frameOutlineSequence?.Kill(true);
|
|
_frameOutlineSequence = DOTween.Sequence();
|
|
_frameOutlineSequence.Append(DOTween.To(() => glowFilter.Strength, x => glowFilter.Strength = x, strengthPeak, fadeDuration).SetEase(Ease.OutQuad));
|
|
_frameOutlineSequence.AppendInterval(stayDuration);
|
|
_frameOutlineSequence.Append(DOTween.To(() => glowFilter.Strength, x => glowFilter.Strength = x, 0f, fadeDuration).SetEase(Ease.InQuad));
|
|
_frameOutlineSequence.Play();
|
|
}
|
|
}
|
|
}
|