rokojori_action_library/Runtime/Actions/Node/SetNodeState.cs

67 lines
1.3 KiB
C#

using Godot;
namespace Rokojori
{
[Tool][GlobalClass, Icon("res://addons/rokojori_action_library/Icons/SetNodeState.svg")]
public partial class SetNodeState : Action
{
[Export]
public Node[] enable = [];
[Export]
public Node[] disable = [];
[ExportGroup( "Reference")]
[Export]
public SetNodeState reference;
[Export]
public bool inverseReference = false;
protected override void _OnTrigger()
{
this.CallDeferred(
()=>
{
var map = new System.Collections.Generic.HashSet<SetNodeState>();
SetStates( map, false, inverseReference );
}
);
}
public void SetStates( System.Collections.Generic.HashSet<SetNodeState> callMap, bool inverse, bool referenceInverse )
{
if ( callMap.Contains( this ) )
{
return;
}
callMap.Add( this );
if ( inverse )
{
Arrays.ForEach( enable, n => NodeState.Disable( n ) );
Arrays.ForEach( disable, n => NodeState.Enable( n ) );
}
else
{
Arrays.ForEach( enable, n => NodeState.Enable( n ) );
Arrays.ForEach( disable, n => NodeState.Disable( n ) );
}
if ( reference == null )
{
return;
}
reference.SetStates( callMap, referenceInverse, referenceInverse );
}
}
}