Created
February 11, 2020 20:37
-
-
Save Rokobokode/1d3e923d2abeb16e997d2b69dd768357 to your computer and use it in GitHub Desktop.
Unity3D: DOTween: Tween As Task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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