Skip to content

Instantly share code, notes, and snippets.

@Odaimoko
Last active November 22, 2024 09:44
Show Gist options
  • Save Odaimoko/f4b05bbf34be90abd17ff1945dac0f1b to your computer and use it in GitHub Desktop.
Save Odaimoko/f4b05bbf34be90abd17ff1945dac0f1b to your computer and use it in GitHub Desktop.
Godot tween awaiter implementation in CSharp
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