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

52 lines
869 B
C#

using Godot;
namespace Rokojori
{
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/RJOnEvent.svg") ]
public partial class OnSensor: Node
{
[Export]
public Sensor sensor;
[Export]
public Action onStart;
[Export]
public Action onActive;
[Export]
public Action 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 )
{
Action.Trigger( onStart );
}
if ( active )
{
Action.Trigger( onActive );
}
if ( ended )
{
Action.Trigger( onActive );
}
}
}
}