UI自动旋转
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotateImage : MonoBehaviour
{
public Transform rotImageRight, rotImagLeft;
public bool isLoop;
public float duration = 3f;
private Sequence rotTweener;
private void Awake()
{
if (isLoop)
{
if (rotImageRight != null)
{
rotTweener.Append(rotImageRight.DOLocalRotate(Vector3.forward * -360, duration, RotateMode.FastBeyond360).SetEase(Ease.Linear)
.SetLoops(-1, LoopType.Restart));
}
if (rotImagLeft != null)
{
rotTweener.Append(rotImagLeft.DOLocalRotate(Vector3.forward * 360, duration, RotateMode.FastBeyond360).SetEase(Ease.Linear)
.SetLoops(-1, LoopType.Restart));
}
}
}
private void OnEnable()
{
if (!isLoop)
{
if (rotImageRight != null)
{
rotTweener.Append(rotImageRight.DOLocalRotate(Vector3.forward * -360, duration, RotateMode.FastBeyond360).SetEase(Ease.Linear));
}
if (rotImagLeft != null)
{
rotTweener.Append(rotImagLeft.DOLocalRotate(Vector3.forward * 360, duration, RotateMode.FastBeyond360).SetEase(Ease.Linear));
}
}
}
private void OnDestroy()
{
rotTweener = null;
}
}