// Author: Daniele Giardini - http://www.demigiant.com
// Created: 2015/01/29 12:57
using DG.Tweening.Core;
using DG.Tweening.Core.Easing;
using UnityEngine;
namespace DG.Tweening
{
///
/// Creates virtual tweens that can be used to change other elements via their OnUpdate calls
///
public static class DOVirtual
{
#region Virtual Tweens
///
/// Tweens a virtual float.
/// You can add regular settings to the generated tween,
/// but do not use SetUpdate or you will overwrite the onVirtualUpdate parameter
///
/// The value to start from
/// The value to tween to
/// The duration of the tween
/// A callback which must accept a parameter of type float, called at each update
///
public static Tweener Float(float from, float to, float duration, TweenCallback onVirtualUpdate)
{
float val = from;
return DOTween.To(() => val, x => val = x, to, duration).OnUpdate(() => onVirtualUpdate(val));
}
#endregion
#region Virtual Functions
/// Returns a value based on the given ease and lifetime percentage (0 to 1)
/// The value to start from when lifetimePercentage is 0
/// The value to reach when lifetimePercentage is 1
/// The time percentage (0 to 1) at which the value should be taken
/// The type of ease
public static float EasedValue(float from, float to, float lifetimePercentage, Ease easeType)
{
return from + (to - from) * EaseManager.Evaluate(easeType, null, lifetimePercentage, 1, DOTween.defaultEaseOvershootOrAmplitude, DOTween.defaultEasePeriod);
}
/// Returns a value based on the given ease and lifetime percentage (0 to 1)
/// The value to start from when lifetimePercentage is 0
/// The value to reach when lifetimePercentage is 1
/// The time percentage (0 to 1) at which the value should be taken
/// The type of ease
/// Eventual overshoot to use with Back ease
public static float EasedValue(float from, float to, float lifetimePercentage, Ease easeType, float overshoot)
{
return from + (to - from) * EaseManager.Evaluate(easeType, null, lifetimePercentage, 1, overshoot, DOTween.defaultEasePeriod);
}
/// Returns a value based on the given ease and lifetime percentage (0 to 1)
/// The value to start from when lifetimePercentage is 0
/// The value to reach when lifetimePercentage is 1
/// The time percentage (0 to 1) at which the value should be taken
/// The type of ease
/// Eventual amplitude to use with Elastic easeType
/// Eventual period to use with Elastic easeType
public static float EasedValue(float from, float to, float lifetimePercentage, Ease easeType, float amplitude, float period)
{
return from + (to - from) * EaseManager.Evaluate(easeType, null, lifetimePercentage, 1, amplitude, period);
}
/// Returns a value based on the given ease and lifetime percentage (0 to 1)
/// The value to start from when lifetimePercentage is 0
/// The value to reach when lifetimePercentage is 1
/// The time percentage (0 to 1) at which the value should be taken
/// The AnimationCurve to use for ease
public static float EasedValue(float from, float to, float lifetimePercentage, AnimationCurve easeCurve)
{
return from + (to - from) * EaseManager.Evaluate(Ease.INTERNAL_Custom, new EaseCurve(easeCurve).Evaluate, lifetimePercentage, 1, DOTween.defaultEaseOvershootOrAmplitude, DOTween.defaultEasePeriod);
}
/// Fires the given callback after the given time.
/// Callback delay
/// Callback to fire when the delay has expired
/// If TRUE (default) ignores Unity's timeScale
public static Tween DelayedCall(float delay, TweenCallback callback, bool ignoreTimeScale = true)
{
return DOTween.Sequence().AppendInterval(delay).OnComplete(callback).SetUpdate(UpdateType.Normal, ignoreTimeScale).SetAutoKill(true);
}
#endregion
}
}