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

52 lines
869 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]
2025-01-08 18:46:17 +00:00
public Sensor sensor;
2024-05-05 07:52:06 +00:00
[Export]
2025-01-08 18:46:17 +00:00
public Action onStart;
2024-05-05 07:52:06 +00:00
[Export]
2025-01-08 18:46:17 +00:00
public Action onActive;
2024-05-05 07:52:06 +00:00
[Export]
2025-01-08 18:46:17 +00:00
public Action onEnd;
2024-05-05 07:52:06 +00:00
public override void _Process( double delta)
{
2025-01-08 18:46:17 +00:00
var active = sensor.isActive;
var wasActive = sensor.wasActive;
2024-05-05 07:52:06 +00:00
if ( ! active && ! wasActive )
{
return;
}
var started = ! wasActive && active;
var ended = wasActive && ! active;
if ( started )
{
2025-01-08 18:46:17 +00:00
Action.Trigger( onStart );
2024-05-05 07:52:06 +00:00
}
if ( active )
{
2025-01-08 18:46:17 +00:00
Action.Trigger( onActive );
2024-05-05 07:52:06 +00:00
}
if ( ended )
{
2025-01-08 18:46:17 +00:00
Action.Trigger( onActive );
2024-05-05 07:52:06 +00:00
}
}
}
}