120 lines
3.5 KiB
C#
120 lines
3.5 KiB
C#
using DG.Tweening;
|
|
using SLSUtilities.UI;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace Cielonos.MainGame.UI
|
|
{
|
|
/// <summary>
|
|
/// NotificationUIArea 使用的顶部横幅,用于显示 Combat 完成等特殊提示。
|
|
/// </summary>
|
|
public class BattleCompletionBanner : UIElementBase
|
|
{
|
|
[SerializeField] private TMP_Text messageText;
|
|
[SerializeField] private string completionMessage = "战斗结束";
|
|
[SerializeField, Min(0f)] private float enterDuration = 0.3f;
|
|
[SerializeField, Min(0f)] private float displayDuration = 1.5f;
|
|
[SerializeField, Min(0f)] private float exitDuration = 0.3f;
|
|
[SerializeField] private float slideDistance = 900f;
|
|
|
|
private Sequence sequence;
|
|
|
|
private void Awake()
|
|
{
|
|
rectTransform ??= GetComponent<RectTransform>();
|
|
canvasGroup ??= GetComponent<CanvasGroup>();
|
|
|
|
if (canvasGroup != null)
|
|
{
|
|
canvasGroup.alpha = 0f;
|
|
canvasGroup.interactable = false;
|
|
canvasGroup.blocksRaycasts = false;
|
|
}
|
|
|
|
gameObject.SetActive(true);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
sequence?.Kill();
|
|
}
|
|
|
|
public void ShowBattleCompleted()
|
|
{
|
|
Show(completionMessage);
|
|
}
|
|
|
|
public void Show(string message)
|
|
{
|
|
if (!gameObject.activeSelf && GetComponent<NotificationUIArea>() == null)
|
|
{
|
|
gameObject.SetActive(true);
|
|
}
|
|
|
|
if (messageText != null)
|
|
{
|
|
messageText.text = string.IsNullOrEmpty(message) ? completionMessage : message;
|
|
}
|
|
|
|
sequence?.Kill();
|
|
if (canvasGroup != null)
|
|
{
|
|
canvasGroup.interactable = false;
|
|
canvasGroup.blocksRaycasts = false;
|
|
}
|
|
|
|
if (rectTransform == null)
|
|
{
|
|
if (canvasGroup != null)
|
|
{
|
|
canvasGroup.alpha = 1f;
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
Vector2 visiblePosition = rectTransform.anchoredPosition;
|
|
Vector2 hiddenLeft = visiblePosition + Vector2.left * slideDistance;
|
|
Vector2 hiddenRight = visiblePosition + Vector2.right * slideDistance;
|
|
rectTransform.anchoredPosition = hiddenLeft;
|
|
|
|
if (canvasGroup != null)
|
|
{
|
|
canvasGroup.alpha = 0f;
|
|
}
|
|
|
|
sequence = DOTween.Sequence()
|
|
.SetUpdate(true)
|
|
.SetAutoKill(true)
|
|
.Pause();
|
|
if (canvasGroup != null)
|
|
{
|
|
sequence.Join(canvasGroup.DOFade(1f, enterDuration));
|
|
}
|
|
|
|
sequence.Join(rectTransform.DOAnchorPos(visiblePosition, enterDuration).SetEase(Ease.OutCubic));
|
|
sequence.AppendInterval(displayDuration);
|
|
|
|
if (canvasGroup != null)
|
|
{
|
|
sequence.Append(canvasGroup.DOFade(0f, exitDuration));
|
|
}
|
|
|
|
sequence.Join(rectTransform.DOAnchorPos(hiddenRight, exitDuration).SetEase(Ease.InCubic));
|
|
sequence.OnComplete(() =>
|
|
{
|
|
if (rectTransform != null)
|
|
{
|
|
rectTransform.anchoredPosition = visiblePosition;
|
|
}
|
|
|
|
if (canvasGroup != null)
|
|
{
|
|
canvasGroup.alpha = 0f;
|
|
}
|
|
});
|
|
sequence.Play();
|
|
}
|
|
}
|
|
}
|