Last active
November 22, 2024 09:44
-
-
Save Odaimoko/f4b05bbf34be90abd17ff1945dac0f1b to your computer and use it in GitHub Desktop.
Godot tween awaiter implementation in CSharp
This file contains 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
using System.Runtime.CompilerServices; | |
using Godot; | |
namespace Imk.GodotWrapper; | |
public static class TweenExtensions | |
{ | |
public static TweenAwaiter GetAwaiter(this Tween tween) => new TweenAwaiter(tween); | |
} | |
public struct TweenAwaiter : INotifyCompletion | |
{ | |
private Tween? _tween; | |
public TweenAwaiter(Tween? tween) | |
{ | |
_tween = tween; | |
} | |
public void OnCompleted(Action continuation) | |
{ | |
if (_tween != null) | |
{ | |
_tween.Finished += () => | |
{ | |
continuation?.Invoke(); | |
}; | |
} | |
else | |
{ | |
continuation?.Invoke(); | |
} | |
} | |
public bool IsCompleted | |
{ | |
get | |
{ | |
var isCompleted = _tween == null || !_tween.IsRunning(); | |
return isCompleted; | |
} | |
} | |
public void GetResult() | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment