What's the accepted/simplest way to create(cache) a Tween or sequence without starting it? #88
-
I'm doing a kind of animation editor for my game and it needs to be able to not start itself when i create the Tween at the start or the end |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
In PrimeTween there is no way to create an animation without starting it. You can create an animation and pause it, but this is probably not what you're looking for. If you're looking for DOTween's way of creating animation upfront, then calling PlayForward/Backwards() on it, there is no equivalent to it in PrimeTween for many reasons. Instead, in PrimeTween you create an animation at the same exact moment you need to play it. More info: |
Beta Was this translation helpful? Give feedback.
-
Seeing as Tweens play when they are created, you can 'store' them inside a Func and create them when you need them. public class TestTweener : MonoBehaviour
{
// We can 'store' the tween in a variable
public Func<Tween> MyTween;
public void Start()
{
// Assign the tween as an anonymous function.
MyTween= () => Tween.PositionX(transform, 1f, new() { duration = 1f });
}
public void PlayTween()
{
// Create a new tween when you're ready to use it.
MyTween();
}
} I'm doing this because I want a central tween controller than I can add tweens to using composition. Although I'm assuming there some dangers about this. No chance to recycle tweens and I'm not sure about leaks. [RequireComponent(typeof(MeshRenderer))]
public class AnimationController : MonoBehaviour
{
private MeshRenderer _meshRenderer;
private TweenComponent[] _tweens;
private IEnumerator Start()
{
_tweens = GetComponents<TweenComponent>();
_meshRenderer = GetComponent<MeshRenderer>();
var startSequence = Sequence.Create(cycles:3);
foreach (var tween in _tweens)
{
startSequence.Group(tween.Create());
}
startSequence.OnComplete(() => _meshRenderer.enabled = false);
}
} and my components public abstract class TweenComponent : MonoBehaviour
{
public abstract Tween Create();
}
public class MoveInY : TweenComponent
{
[SerializeField]
private TweenSettings<float> MoveInYSettings = new()
{
startValue = -5f,
endValue = 0f,
};
public override Tween Create() => Tween.PositionY(transform, MoveInYSettings);
} Is this cursed? Time will tell. |
Beta Was this translation helpful? Give feedback.
In PrimeTween there is no way to create an animation without starting it. You can create an animation and pause it, but this is probably not what you're looking for.
If you're looking for DOTween's way of creating animation upfront, then calling PlayForward/Backwards() on it, there is no equivalent to it in PrimeTween for many reasons. Instead, in PrimeTween you create an animation at the same exact moment you need to play it.
More info:
https://github.com/KyryloKuzyk/PrimeTween?tab=readme-ov-file#tweenplayforwardplaybackwardsrestart
https://discussions.unity.com/t/primetween-high-performance-animations-and-sequences/926420/125