// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) VRMADA, All rights reserved.
//
// --------------------------------------------------------------------------------------------------------------------
using System;
using UltimateXR.Animation.Interpolation;
using UltimateXR.Extensions.Unity;
using UnityEngine;
using UnityEngine.UI;
namespace UltimateXR.Animation.UI
{
///
/// Tweening component to animate programatically or using the inspector.
///
public class UxrRotationTween : UxrGraphicTween
{
#region Inspector Properties/Serialized Fields
[SerializeField] private Vector3 _startAngles;
[SerializeField] private Vector3 _endAngles;
#endregion
#region Public Types & Data
///
/// The start local Euler angles in the rotation animation.
///
public Vector3 StartAngles
{
get => _startAngles;
set => _startAngles = value;
}
///
/// The end local Euler angles in the rotation animation.
///
public Vector3 EndAngles
{
get => _endAngles;
set => _endAngles = value;
}
#endregion
#region Public Methods
///
/// Creates and starts a rotation tweening animation for the of a Unity
/// UI component.
///
/// Target graphic
/// Start local angles
/// End local angles
/// Interpolation settings that control the animation
/// Optional callback when the animation finished
///
/// Tweening component that will update itself automatically. Can be used to stop the animation prematurely or
/// change parameters on the fly.
///
public static UxrRotationTween Animate(Graphic graphic, Vector3 startAngles, Vector3 endAngles, UxrInterpolationSettings settings, Action finishedCallback = null)
{
UxrRotationTween rotationTween = graphic.GetOrAddComponent();
rotationTween.StartAngles = startAngles;
rotationTween.EndAngles = endAngles;
rotationTween.InterpolationSettings = settings;
rotationTween.FinishedCallback = finishedCallback;
rotationTween.Restart();
return rotationTween;
}
#endregion
#region Protected Overrides UxrTween
///
protected override void RestoreOriginalValue()
{
RestoreLocalRotation();
}
///
protected override void Interpolate(float t)
{
TargetRectTransform.localEulerAngles = Vector3.Lerp(StartAngles, EndAngles, t);
}
#endregion
}
}