rj-action-library/Runtime/Actions/OnTick.cs

74 lines
1.2 KiB
C#
Raw Normal View History

2025-01-16 07:20:32 +00:00
using Godot;
namespace Rokojori
{
[Tool]
[GlobalClass, Icon("res://addons/rokojori_action_library/Icons/OnEvent.svg") ]
public partial class OnTick : Node
2025-01-16 07:20:32 +00:00
{
[Export]
public Action action;
2025-01-16 07:20:32 +00:00
bool _active = false;
[Export]
public bool active
{
get => _active;
set
{
SetActive( value );
}
}
[Export]
public float duration;
[Export]
public float offset;
[Export]
public TimeLine timeLine;
int _eventID = -1;
void SetActive( bool active )
{
if ( active == _active || Engine.IsEditorHint() )
{
return;
}
_active = active;
if ( _active )
{
if ( _eventID != -1 )
{
2025-01-19 20:35:51 +00:00
TimeLineManager.RemoveEvent( timeLine, _eventID );
2025-01-16 07:20:32 +00:00
return;
}
2025-01-19 20:35:51 +00:00
var tle = TimeLineManager.ScheduleLoopEvent( timeLine, duration, offset, tle => Action.Trigger( action ) );
_eventID = tle.id;
2025-01-16 07:20:32 +00:00
}
else
{
if ( _eventID == -1 )
{
return;
}
2025-01-19 20:35:51 +00:00
TimeLineManager.RemoveEvent( timeLine, _eventID );
2025-01-16 07:20:32 +00:00
_eventID = -1;
}
}
}
}