Replies: 2 comments 3 replies
-
Hey! There is currently no CancellationToken support in PrimeTween. Instead, PrimeTween offers a simple tween/sequence.Stop() method that can cancel animations, including those awaited with 'await'. Can you please provide an example in which use cases you would like to use CancellationToken together with PrimeTween? |
Beta Was this translation helpful? Give feedback.
-
I want to use PrimeTween in combination with R3(+UniTask) (the successor to UniRx). I want to write the following code. var rp = new ReactiveProperty<float>(10.0f);
rp.SubscribeAwait(async (x, ct) =>
{
await Tween.Scale(target, x, 1.0f).ToYieldInstruction().WithCancellation(cancellationToken: ct);
}, AwaitOperation.Switch); However, with this, the tween will continue to run even if the CancellationToken is canceled. var rp = new ReactiveProperty<float>(10.0f);
Tween tween = default;
rp.Subscribe(x =>
{
tween.Stop();
tween = Tween.Scale(target, x, 1.0f);
}); but I simply prefer the example first. I understood the design concept of PrimeTween by reading #46. public static class PrimeTweenExtensions
{
public static UniTask ToTask(this Tween tween, CancellationToken cancellationToken = default)
{
Disposable.Create(tween.Stop).AddTo(cancellationToken);
return tween.ToYieldInstruction().ToUniTask(cancellationToken: cancellationToken);
}
}
var rp = new ReactiveProperty<float>(10.0f);
rp.SubscribeAwait(async (x, ct) =>
{
await Tween.Scale(target, x, 1.0f).ToTask(ct);
}, AwaitOperation.Switch); |
Beta Was this translation helpful? Give feedback.
-
I would like to cancel Tween/Sequence using CancellationToken. Is there any way to do that?
Beta Was this translation helpful? Give feedback.
All reactions