Skip to content

Instantly share code, notes, and snippets.

@Rokobokode
Created February 11, 2020 20:37
Show Gist options
  • Save Rokobokode/1d3e923d2abeb16e997d2b69dd768357 to your computer and use it in GitHub Desktop.
Save Rokobokode/1d3e923d2abeb16e997d2b69dd768357 to your computer and use it in GitHub Desktop.
Unity3D: DOTween: Tween As Task
public static class TweenExtensions
{
public static Task AsTask(this Tween tween, CancellationToken cancellationToken)
{
var taskCompletionSource = new TaskCompletionSource<bool>();
tween.OnComplete(() => { taskCompletionSource.TrySetResult(true); });
tween.OnKill(() => { taskCompletionSource.TrySetCanceled(); });
if (cancellationToken != CancellationToken.None)
{
tween.OnUpdate(() =>
{
if (cancellationToken.IsCancellationRequested)
{
tween.Kill();
}
});
}
return taskCompletionSource.Task;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment