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

52 lines
906 B
C#
Raw Normal View History

2025-07-20 11:22:12 +00:00
using Godot;
2025-10-24 11:38:51 +00:00
using System.Threading.Tasks;
2025-07-20 11:22:12 +00:00
namespace Rokojori
{
[Tool][GlobalClass]
public partial class RemoveNode : Action
{
[Export]
public Node target;
2025-07-22 14:08:22 +00:00
[Export]
public bool queue = true;
2025-10-31 12:09:03 +00:00
[Export]
public bool disableAllNodes = true;
2025-10-24 11:38:51 +00:00
2025-07-20 11:22:12 +00:00
protected override void _OnTrigger()
{
2025-10-24 11:38:51 +00:00
if ( target == null || Engine.IsEditorHint() )
2025-07-20 11:22:12 +00:00
{
2025-07-22 14:08:22 +00:00
return;
2025-07-20 11:22:12 +00:00
}
2025-07-25 15:35:19 +00:00
2025-10-24 11:38:51 +00:00
if ( ! IsInstanceValid( this ) || ! IsInstanceValid( target ) )
{
return;
}
CallDeferred( "SelfDestroy" );
2025-07-22 14:08:22 +00:00
2025-07-20 11:22:12 +00:00
}
2025-10-24 11:38:51 +00:00
void SelfDestroy()
{
if ( ! IsInstanceValid( target ) )
{
return;
}
2025-10-31 12:09:03 +00:00
if ( disableAllNodes )
{
target.ForEach<Node>( n => NodeState.Disable( n ) );
NodeState.Disable( target );
}
2025-10-24 11:38:51 +00:00
target.SelfDestroy( queue );
}
2025-07-20 11:22:12 +00:00
}
}