using Godot; namespace Rokojori { [Tool][GlobalClass ] public partial class SetPauseState : Action { public enum Mode { Pause, Resume, Toggle } [Export] public Mode mode; [Export] public Action onPausing; [Export] public Action onResuming; [Export] public bool onlyTriggerOnChange = true; protected override void _OnTrigger() { var isCurrentlyPaused = GetTree().Paused; var nextIsPaused = Mode.Toggle == mode ? ! isCurrentlyPaused : Mode.Pause == mode ? true : false; this.LogInfo( "SetPauseState: is paused", isCurrentlyPaused, ">> next is paused", nextIsPaused ); if ( isCurrentlyPaused == nextIsPaused && onlyTriggerOnChange ) { return; } this.LogInfo( "Setting Paused State", nextIsPaused ); GetTree().Paused = nextIsPaused; if ( nextIsPaused ) { Action.Trigger( onPausing ); } else { Action.Trigger( onResuming ); } } } }