using Godot; using System.Threading.Tasks; namespace Rokojori { [Tool][GlobalClass, Icon("res://addons/rokojori_action_library/Icons/Delay.svg")] public partial class DelayFrames : SequenceAction { [Export] public int numFrames; protected override void _OnTrigger() { var sequenceID = DispatchStart(); // this.LogInfo( "time:", Time.GetTicksMsec() / 1000f ); if ( Engine.IsEditorHint() ) { var timeLine = TimeLineManager.Ensure( null ); TimeLineManager.ScheduleSpanIn( timeLine, 0, numFrames * 1f/60f , ( span, type )=> { if ( type == TimeLineSpanUpdateType.End ) { DispatchEnd( sequenceID ); this.LogInfo( "time:", Time.GetTicksMsec() / 1000f ); } }, this ); } else { runForFrames( numFrames, sequenceID ); } } protected async Task runForFrames( int frames, int sequenceID ) { while ( frames > 0 ) { await this.RequestNextFrame(); frames --; } DispatchEnd( sequenceID ); } } }