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

94 lines
1.5 KiB
C#
Raw Normal View History

2024-05-05 07:52:06 +00:00
using Godot;
namespace Rokojori
{
[Tool][GlobalClass, Icon("res://addons/rokojori_action_library/Icons/OnEvent.svg") ]
2024-05-05 07:52:06 +00:00
public partial class OnSensor: Node
{
2025-07-22 14:08:22 +00:00
[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
2025-07-25 08:13:35 +00:00
[Export]
public bool onlyWhenNotConsumed = true;
[Export]
public bool consumeEvent = true;
[ExportGroup("Condition")]
2025-07-22 14:08:22 +00:00
[Export]
public Condition condition;
[Export]
public SceneCondition sceneCondition;
2025-07-25 08:13:35 +00:00
public override void _Process( double delta )
2024-05-05 07:52:06 +00:00
{
2025-07-22 14:08:22 +00:00
if ( sensor == null )
{
return;
}
2024-05-05 07:52:06 +00:00
2025-07-25 08:13:35 +00:00
if ( onlyWhenNotConsumed && sensor.consumed )
{
return;
}
2025-07-22 14:08:22 +00:00
if ( condition != null && ! condition.Evaluate() )
2024-05-05 07:52:06 +00:00
{
return;
}
2025-07-22 14:08:22 +00:00
if ( sceneCondition != null && ! sceneCondition.Evaluate() )
{
return;
}
if ( sensor.isDown )
2024-05-05 07:52:06 +00:00
{
2025-01-08 18:46:17 +00:00
Action.Trigger( onStart );
2025-07-25 08:13:35 +00:00
if ( consumeEvent && onStart != null )
{
sensor.Consume();
return;
}
2024-05-05 07:52:06 +00:00
}
2025-07-22 14:08:22 +00:00
if ( sensor.isHold )
2024-05-05 07:52:06 +00:00
{
2025-01-08 18:46:17 +00:00
Action.Trigger( onActive );
2025-07-25 08:13:35 +00:00
if ( consumeEvent && onActive != null )
{
sensor.Consume();
return;
}
2024-05-05 07:52:06 +00:00
}
2025-07-22 14:08:22 +00:00
if ( sensor.isUp )
2024-05-05 07:52:06 +00:00
{
2025-07-25 08:13:35 +00:00
Action.Trigger( onEnd );
if ( consumeEvent && onEnd != null )
{
sensor.Consume();
return;
}
2024-05-05 07:52:06 +00:00
}
}
}
}