using Godot; namespace Rokojori { [Tool] [GlobalClass] public partial class TimeLooper : Node { bool _active = false; [Export] public bool active { get => _active; set { SetActive( value ); } } [Export] public float duration; [Export] public float offset; [Export] public TimeLine timeLine; [Export] public Action action; int _eventID = -1; void SetActive( bool active ) { if ( active == _active || Engine.IsEditorHint() ) { return; } _active = active; if ( _active ) { if ( _eventID != -1 ) { TimeLineScheduler.RemoveEvent( timeLine, _eventID ); return; } _eventID = TimeLineScheduler.ScheduleLoopEvent( timeLine, duration, offset, id => Action.Trigger( action ) ); } else { if ( _eventID == -1 ) { return; } TimeLineScheduler.RemoveEvent( timeLine, _eventID ); _eventID = -1; } } } }