Files
SXDMystery/Assets/_SXDMystery/Scripts/Task/TreeTask/ScrollOpenUI.cs
2025-12-16 11:15:33 +08:00

62 lines
1.4 KiB
C#

using System;
using UnityEngine;
using DG.Tweening;
public class ScrollOpenUI : MonoBehaviour
{
public RectTransform leftPole;
public RectTransform rightPole;
public RectTransform mask;
public float openWidth = 800f;
public float maskWidth = 844f;
public float duration = 0.8f;
Tween tween;
private void Start()
{
mask.sizeDelta = new Vector2(0, mask.sizeDelta.y);
}
// ================= 对外接口 =================
public void Open(Action cb)
{
Play(1f,cb);
}
public void Close(Action cb)
{
Play(0f,cb);
}
// ============================================
void Play(float target,Action cb)
{
tween?.Kill();
float leftX = target == 1f ? -openWidth * 0.5f : 0f;
float rightX = target == 1f ? openWidth * 0.5f : 0f;
float maskX = target == 1f ? maskWidth : 0f;
tween = DOTween.Sequence()
.Join(leftPole.DOAnchorPosX(leftX, duration))
.Join(rightPole.DOAnchorPosX(rightX, duration))
.Join(mask.DOSizeDelta(
new Vector2(maskX, mask.sizeDelta.y),
duration
))
.SetEase(Ease.OutCubic).OnComplete(() =>
{
cb?.Invoke();
});
}
// ================= 初始化 =================
void OnDisable()
{
tween?.Kill();
}
}