46 lines
1.1 KiB
C#
46 lines
1.1 KiB
C#
using DG.Tweening;
|
|
using UnityEngine;
|
|
|
|
public class BasePanel_2 : MonoBehaviour
|
|
{
|
|
public CanvasGroup canvasGroup; // 用于控制透明度
|
|
|
|
public virtual void Start()
|
|
{
|
|
// 获取 CanvasGroup 组件
|
|
if (canvasGroup == null)
|
|
{
|
|
canvasGroup = GetComponent<CanvasGroup>();
|
|
}
|
|
|
|
// 初始状态:隐藏面板
|
|
canvasGroup.alpha = 0; // 完全透明
|
|
canvasGroup.interactable = false; // 不可交互
|
|
canvasGroup.blocksRaycasts = false; // 不阻挡射线
|
|
}
|
|
|
|
// 显示面板(淡入效果)
|
|
public virtual void ShowPanel()
|
|
{
|
|
// 透明度从0逐渐变为1
|
|
canvasGroup.DOFade(1, 0.8f).OnStart(() =>
|
|
{
|
|
// 开始时设置为可交互和阻挡射线
|
|
canvasGroup.interactable = true;
|
|
canvasGroup.blocksRaycasts = true;
|
|
});
|
|
}
|
|
|
|
// 隐藏面板(淡出效果)
|
|
public virtual void HidePanel()
|
|
{
|
|
// 透明度从1逐渐变为0
|
|
canvasGroup.DOFade(0, 0.8f).OnComplete(() =>
|
|
{
|
|
// 完成后禁用交互和阻挡射线
|
|
canvasGroup.interactable = false;
|
|
canvasGroup.blocksRaycasts = false;
|
|
});
|
|
}
|
|
}
|