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

59 lines
977 B
C#
Raw Normal View History

2025-07-22 14:08:22 +00:00
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 currentState = GetTree().Paused;
var nextState = Mode.Toggle == mode ? ! currentState : Mode.Pause == mode ? false : true;
this.LogInfo( "SetPauseState", currentState, ">>", nextState );
if ( currentState == nextState && onlyTriggerOnChange )
{
return;
}
this.LogInfo( "Setting Pause State", nextState );
GetTree().Paused = nextState;
if ( nextState )
{
Action.Trigger( onPausing );
}
else
{
Action.Trigger( onResuming );
}
}
}
}