rj-action-library/Runtime/Sensors/OnSensor.cs

52 lines
884 B
C#
Raw Normal View History

2024-05-05 07:52:06 +00:00
using Godot;
namespace Rokojori
{
2024-11-13 11:57:10 +00:00
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/RJOnEvent.svg") ]
2024-05-05 07:52:06 +00:00
public partial class OnSensor: Node
{
[Export]
public RJSensor sensor;
[Export]
public RJAction onStart;
[Export]
public RJAction onActive;
[Export]
public RJAction onEnd;
public override void _Process( double delta)
{
var active = sensor.IsActive();
var wasActive = sensor.WasActive();
if ( ! active && ! wasActive )
{
return;
}
var started = ! wasActive && active;
var ended = wasActive && ! active;
if ( started )
{
Actions.Trigger( onStart );
}
if ( active )
{
Actions.Trigger( onActive );
}
if ( ended )
{
Actions.Trigger( onActive );
}
}
}
}