rokojori_action_library/Runtime/Actions/SetPauseState.cs

61 lines
1.1 KiB
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()
{
2026-02-26 14:06:27 +00:00
var isCurrentlyPaused = GetTree().Paused;
2025-07-22 14:08:22 +00:00
2026-02-26 14:06:27 +00:00
var nextIsPaused = Mode.Toggle == mode ? ! isCurrentlyPaused :
Mode.Pause == mode ? true : false;
2025-07-22 14:08:22 +00:00
2026-02-26 14:06:27 +00:00
this.LogInfo( "SetPauseState: is paused", isCurrentlyPaused, ">> next is paused", nextIsPaused );
2025-07-22 14:08:22 +00:00
2026-02-26 14:06:27 +00:00
if ( isCurrentlyPaused == nextIsPaused && onlyTriggerOnChange )
2025-07-22 14:08:22 +00:00
{
return;
}
2026-02-26 14:06:27 +00:00
this.LogInfo( "Setting Paused State", nextIsPaused );
GetTree().Paused = nextIsPaused;
2025-07-22 14:08:22 +00:00
2026-02-26 14:06:27 +00:00
if ( nextIsPaused )
2025-07-22 14:08:22 +00:00
{
Action.Trigger( onPausing );
}
else
{
Action.Trigger( onResuming );
}
}
}
}