rj-action-library/Runtime/Events/Signals.cs

53 lines
1.2 KiB
C#
Raw Normal View History

2025-07-22 14:08:22 +00:00
using System.Collections.Generic;
using Godot;
namespace Rokojori
{
public static class Signals
{
public static void OnFinished( this GpuParticles3D particles3D, System.Action action, bool once = false )
{
if ( once )
{
_OnSignalOnce( particles3D, GpuParticles3D.SignalName.Finished, action );
}
else
{
_OnSignal( particles3D, GpuParticles3D.SignalName.Finished, action );
}
}
public static void OnFinishedOnce( this GpuParticles3D particles3D, System.Action action )
{
OnFinished( particles3D, action, true );
}
2025-08-31 06:05:39 +00:00
public static void _OnSignal( this Node node, string name, System.Action action )
2025-07-22 14:08:22 +00:00
{
node.Connect( name, Callable.From( action ) );
}
2025-08-31 06:05:39 +00:00
public static void _OnSignal( this Node node, string name, Callable callable )
{
node.Connect( name, callable );
}
public static void _OnSignalOnce( this Node node, string name, System.Action action )
2025-07-22 14:08:22 +00:00
{
Callable? onceAction = null;
onceAction = Callable.From(
()=>
{
action();
node.Disconnect( name, (Callable) onceAction );
}
);
2025-08-31 06:05:39 +00:00
node.Connect( name, (Callable) onceAction );
2025-07-22 14:08:22 +00:00
}
}
}