// --------------------------------------------------------------------------------------------------------------------
//
// 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 UxrScaleTween : UxrGraphicTween
{
#region Inspector Properties/Serialized Fields
[SerializeField] private Vector3 _startScale;
[SerializeField] private Vector3 _endScale;
#endregion
#region Public Types & Data
///
/// Animation start scale
///
public Vector3 StartScale
{
get => _startScale;
set => _startScale = value;
}
///
/// Animation end scale
///
public Vector3 EndScale
{
get => _endScale;
set => _endScale = value;
}
#endregion
#region Public Methods
///
/// Creates and starts a scale tweening animation for the of a Unity
/// UI component.
///
/// Target graphic
/// Start local scale
/// End local scale
/// 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 UxrScaleTween Animate(Graphic graphic, Vector3 startScale, Vector3 endScale, UxrInterpolationSettings settings, Action finishedCallback = null)
{
UxrScaleTween scaleTween = graphic.GetOrAddComponent();
scaleTween.StartScale = startScale;
scaleTween.EndScale = endScale;
scaleTween.InterpolationSettings = settings;
scaleTween.FinishedCallback = finishedCallback;
scaleTween.Restart();
return scaleTween;
}
#endregion
#region Protected Overrides UxrTween
///
protected override void RestoreOriginalValue()
{
RestoreLocalScale();
}
///
protected override void Interpolate(float t)
{
TargetRectTransform.localScale = Vector2.Lerp(StartScale, EndScale, t);
}
#endregion
}
}