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(); // 隐藏面板 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(); } }