Files
ichni_Official/Assets/Scripts/NewStorySystem/UI/DialogWheel.cs
SoulliesOfficial 7b7d069b84 StorySystem
2026-07-07 01:28:27 -04:00

73 lines
2.4 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 UnityEngine;
namespace Ichni.Story.UI
{
/// <summary>
/// 对话时常驻转动的齿轮/轮盘,以及伴随浮动的指针。
/// </summary>
public class DialogWheel : MonoBehaviour
{
[Header("轮盘旋转")]
[Tooltip("要旋转的 RectTransform。如果不填默认获取自身。")]
public RectTransform wheelRect;
[Tooltip("顺时针旋转一整圈360度所需的时间")]
public float rotationCycleDuration = 5f;
[Header("指针浮动")]
[Tooltip("常驻上下浮动的指针对象 (RectTransform)")]
public RectTransform pointerRect;
[Tooltip("指针单向浮动的距离(像素)")]
public float pointerFloatDistance = 5f;
[Tooltip("指针完成单向浮动所需的时间")]
public float pointerFloatDuration = 0.3f;
private Tween _rotateTween;
private Tween _pointerTween;
private float _pointerStartY;
private void Awake()
{
if (wheelRect == null) wheelRect = GetComponent<RectTransform>();
if (pointerRect != null)
{
_pointerStartY = pointerRect.anchoredPosition.y;
}
}
private void Start()
{
// 轮盘常驻匀速旋转
if (wheelRect != null && rotationCycleDuration > 0f)
{
// SetRelative(true) 保证无论当前角度是多少,都在其基础上转 -360 度
// LoopType.Restart 配合 Linear 缓动,实现无限丝滑旋转
_rotateTween = wheelRect.DORotate(new Vector3(0, 0, -360f), rotationCycleDuration, RotateMode.FastBeyond360)
.SetRelative(true)
.SetLoops(-1, LoopType.Restart)
.SetEase(Ease.Linear);
_rotateTween.Play();
}
// 指针常驻浮动,启动后永不停止
if (pointerRect != null)
{
_pointerTween = pointerRect.DOAnchorPosY(_pointerStartY + pointerFloatDistance, pointerFloatDuration)
.SetLoops(-1, LoopType.Yoyo)
.SetEase(Ease.InOutSine);
_pointerTween.Play();
}
}
private void OnDestroy()
{
_rotateTween?.Kill();
_pointerTween?.Kill();
}
}
}