UniTask icon indicating copy to clipboard operation
UniTask copied to clipboard

DOTween ToUniTask vs WithCancellation

Open codemonkeynorth opened this issue 3 years ago • 2 comments

is there any difference between:

await transform.DOScale(1, 1).ToUniTask(cancellationToken: token);

and

await transform.DOScale(1, 1).WithCancellation(token);

Presumably the first one can be assigned to a variable and returned ?

Thanks

codemonkeynorth avatar Apr 27 '22 23:04 codemonkeynorth

I see from here

https://twitter.com/su10_dev/status/1356186330535919620?s=20&t=U_29PEjZvwqOHMKlkTbFOA

they are similar.. allowing the tween to be cancelled, with the first being preferable?

codemonkeynorth avatar Apr 28 '22 23:04 codemonkeynorth

Press F12 :)

public static UniTask WithCancellation(this Tween tween, CancellationToken cancellationToken)
{
    Error.ThrowArgumentNullException(tween, nameof(tween));

    if (!tween.IsActive()) return UniTask.CompletedTask;
    return new UniTask(TweenConfiguredSource.Create(tween, TweenCancelBehaviour.Kill, cancellationToken, CallbackType.Kill, out var token), token);
}

 public static UniTask ToUniTask(this Tween tween, TweenCancelBehaviour tweenCancelBehaviour = TweenCancelBehaviour.Kill, CancellationToken cancellationToken = default)
{
    Error.ThrowArgumentNullException(tween, nameof(tween));

    if (!tween.IsActive()) return UniTask.CompletedTask;
    return new UniTask(TweenConfiguredSource.Create(tween, tweenCancelBehaviour, cancellationToken, CallbackType.Kill, out var token), token);
}

YegorStepanov avatar May 22 '22 19:05 YegorStepanov

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Aug 21 '22 00:08 github-actions[bot]

Press F12 :)

public static UniTask WithCancellation(this Tween tween, CancellationToken cancellationToken)
{
    Error.ThrowArgumentNullException(tween, nameof(tween));

    if (!tween.IsActive()) return UniTask.CompletedTask;
    return new UniTask(TweenConfiguredSource.Create(tween, TweenCancelBehaviour.Kill, cancellationToken, CallbackType.Kill, out var token), token);
}

 public static UniTask ToUniTask(this Tween tween, TweenCancelBehaviour tweenCancelBehaviour = TweenCancelBehaviour.Kill, CancellationToken cancellationToken = default)
{
    Error.ThrowArgumentNullException(tween, nameof(tween));

    if (!tween.IsActive()) return UniTask.CompletedTask;
    return new UniTask(TweenConfiguredSource.Create(tween, tweenCancelBehaviour, cancellationToken, CallbackType.Kill, out var token), token);
}

where can I put this code?

farhnmh avatar Jan 22 '24 02:01 farhnmh