godot/modules/mono/glue/GodotSharp/GodotSharp/Core/SignalAwaiter.cs
Ignacio Etcheverry 6a85cdf640 Fix C# bindings after recent breaking changes
Implementation for new Variant types Callable, Signal, StringName.
Added support for PackedInt64Array and PackedFloat64Array.

Add generation of signal members as events, as well as support for
user created signals as events.
NOTE: As of now, raising such events will not emit the signal. As such,
one must use `EmitSignal` instead of raising the event directly.

Removed old ThreadLocal fallback class. It's safe to use thread_local now since
it's supported on all minimum versions of compilers we support.
2020-03-17 16:30:04 +01:00

55 lines
1.3 KiB
C#

using System;
using System.Runtime.CompilerServices;
namespace Godot
{
public class SignalAwaiter : IAwaiter<object[]>, IAwaitable<object[]>
{
private bool completed;
private object[] result;
private Action action;
public SignalAwaiter(Object source, StringName signal, Object target)
{
godot_icall_SignalAwaiter_connect(Object.GetPtr(source), StringName.GetPtr(signal), Object.GetPtr(target), this);
}
[MethodImpl(MethodImplOptions.InternalCall)]
internal extern static Error godot_icall_SignalAwaiter_connect(IntPtr source, IntPtr signal, IntPtr target, SignalAwaiter awaiter);
public bool IsCompleted
{
get
{
return completed;
}
}
public void OnCompleted(Action action)
{
this.action = action;
}
public object[] GetResult()
{
return result;
}
public IAwaiter<object[]> GetAwaiter()
{
return this;
}
internal void SignalCallback(object[] args)
{
completed = true;
result = args;
if (action != null)
{
action();
}
}
}
}