_TheStrongestSnail/TheStrongestSnail/Assets/Scripts/Battle_Royale/BasePanel.cs
2024-11-13 02:03:11 +08:00

57 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BasePanel : MonoBehaviour
{
public RectTransform panel; // 面板的 RectTransform
public CanvasGroup canvasGroup; // 用于控制透明度
public virtual void Start()
{
panel = GetComponent<RectTransform>();
// 隐藏面板
panel.localScale = Vector3.zero; // 初始缩放为0表示不可见
}
// 显示面板(弹出动画)
public virtual void ShowPanel()
{
// 将面板从中心弹出,并逐渐淡入
Sequence sequence = DOTween.Sequence();
// 缩放动画从0缩放到1
sequence.Append(panel.DOScale(Vector3.one, 0.5f).SetEase(Ease.OutBack));
// 透明度动画逐渐从0变为1
sequence.Join(canvasGroup.DOFade(1, 0.5f));
// 开始播放动画
sequence.Play();
}
// 隐藏面板(收回动画)
public virtual void HidePanel()
{
// 将面板缩回并淡出
Sequence sequence = DOTween.Sequence();
// 缩放动画从1缩放回0
sequence.Append(panel.DOScale(Vector3.zero, 0.3f).SetEase(Ease.InBack));
// 透明度动画逐渐从1变为0
sequence.Join(canvasGroup.DOFade(0, 0.3f));
// 开始播放动画
sequence.Play();
}
}