/// <summary>The main API of the PrimeTween library.<br/><br/>
/// Use static Tween methods to start animations (tweens).<br/>
/// Use the returned Tween struct to control the running tween and access its properties.<br/><br/>
/// Tweens are non-reusable. That is, when a tween completes (or is stopped manually), it becomes 'dead' (<see cref="isAlive"/> == false) and can no longer be used to control the tween or access its properties.<br/>
/// To restart the animation from the beginning (or play in the opposite direction), simply start a new Tween. Starting tweens is very fast and doesn't allocate garbage,
/// so you can start hundreds of tweens per seconds with no performance overhead.</summary>
/// <example><code>
/// var tween = Tween.LocalPositionX(transform, endValue: 1.5f, duration: 1f);
/// // Let the tween run for some time...
/// if (tween.isAlive) {
/// Debug.Log($"Animation is still running, elapsed time: {tween.elapsedTime}.");
/// } else {
/// Debug.Log("Animation is already completed.");
/// }
/// </code></example>
#ifENABLE_SERIALIZATION
[Serializable]
#endif
public
#if!ENABLE_SERIALIZATION
readonly
#endif
partialstructTween:IEquatable<Tween>{
/// Uniquely identifies the tween.
/// Can be observed from the Debug Inspector if PRIME_TWEEN_INSPECTOR_DEBUGGING is defined. Use only for debugging purposes.
internal
#if!ENABLE_SERIALIZATION
readonly
#endif
longid;
internalreadonlyReusableTweentween;
internalboolIsCreated=>id!=0;
internalTween([NotNull]ReusableTweentween){
Assert.IsNotNull(tween);
Assert.AreNotEqual(-1,tween.id);
id=tween.id;
this.tween=tween;
}
/// A tween is 'alive' when it has been created and is not stopped or completed yet. Paused tween is also considered 'alive'.
/// Interrupts the tween, ignoring onComplete callback.
publicvoidStop(){
if(isAlive&&tryManipulate()){
tween.kill();
}
}
/// <summary>Immediately completes the tween.<br/>
/// If the tween has infinite cycles (cycles == -1), completes only the current cycle. To choose between 'startValue' and 'endValue' in the case of infinite cycles, use <see cref="SetRemainingCycles(bool stopAtEndValue)"/> before calling Complete().</summary>
publicvoidComplete(){
// don't warn that tween is dead because dead tween means that it's already 'completed'
/// <summary>Stops the tween when it reaches 'startValue' or 'endValue' for the next time.<br/>
/// For example, if you have an infinite tween (cycles == -1) with CycleMode.Yoyo/Rewind, and you wish to stop it when it reaches the 'endValue', then set <see cref="stopAtEndValue"/> to true.
/// To stop the animation at the 'startValue', set <see cref="stopAtEndValue"/> to false.</summary>
Debug.LogWarning(nameof(SetRemainingCycles)+"(bool "+nameof(stopAtEndValue)+") is meant to be used with CycleMode.Yoyo or Rewind. Please consider using the overload that accepts int instead.");
Debug.LogError("Applying cycles to Delay will not repeat the OnComplete() callback, but instead will increase the Delay duration.\n"+
"OnComplete() is called only once when ALL tween cycles complete. To repeat the OnComplete() callback, please use the Sequence.Create(cycles: numCycles) and put the tween inside a Sequence.\n"+
/// <summary>Adds completion callback. Please consider using <see cref="OnComplete{T}"/> to prevent a possible capture of variable into a closure.</summary>
/// <param name="warnIfTargetDestroyed">Set to 'false' to disable the error about target's destruction. Please note that the the <see cref="onComplete"/> callback will be silently ignored in the case of target's destruction. More info: https://github.com/KyryloKuzyk/PrimeTween/discussions/4</param>
/// <param name="warnIfTargetDestroyed">Set to 'false' to disable the error about target's destruction. Please note that the the <see cref="onComplete"/> callback will be silently ignored in the case of target's destruction. More info: https://github.com/KyryloKuzyk/PrimeTween/discussions/4</param>
/// <example>The example shows how to destroy the object after the completion of a tween.
/// Please note: we're using the '_transform' variable from the onComplete callback to prevent garbage allocation. Using the 'transform' variable directly will capture it into a closure and generate garbage.