rj-action-library/Runtime/Godot/Nodes.cs

102 lines
2.1 KiB
C#
Raw Normal View History

2024-05-04 08:26:16 +00:00
using Godot;
namespace Rokojori
{
public class Nodes
{
public static T GetSibling<T>( Node node ) where T:Node
{
if ( node == null )
{
return null;
}
var parent = node.GetParent();
if ( parent == null )
{
return null;
}
return GetDirectChild<T>( parent );
}
public static T GetDirectChild<T>( Node parent ) where T:Node
{
if ( parent == null )
{
return null;
}
var numChildren = parent.GetChildCount();
for ( int i = 0; i < numChildren; i++ )
{
var node = parent.GetChild( i );
if ( node is T )
{
2024-05-12 17:03:20 +00:00
return (T) node;
2024-05-04 08:26:16 +00:00
}
}
return null;
}
2024-05-12 17:03:20 +00:00
public static void ForEachDirectChild<T>( Node parent, System.Action<T> action ) where T:Node
{
if ( parent == null || action == null )
{
return;
}
var numChildren = parent.GetChildCount();
for ( int i = 0; i < numChildren; i++ )
{
var node = parent.GetChild( i );
if ( ! ( node is T ) )
{
continue;
}
action( node as T );
}
}
2024-05-04 08:26:16 +00:00
static NodesWalker nodesWalker = new NodesWalker();
public static T GetAnyChild<T>( Node parent ) where T:Node
{
return (T) nodesWalker.Find( parent, ( n )=> n is T, true );
2024-05-05 07:52:06 +00:00
}
/*
2024-05-04 08:26:16 +00:00
public static void Enable( Node n, bool affectProcess = true, bool affectPhysicsProcess = true, bool affectInput = true )
{
SetState.SetStateOfNode( NodeStateType.Enabled, n, affectProcess, affectPhysicsProcess, affectInput );
}
public static void Disable( Node n, bool affectProcess = true, bool affectPhysicsProcess = true, bool affectInput = true )
{
SetState.SetStateOfNode( NodeStateType.Disabled, n, affectProcess, affectPhysicsProcess, affectInput );
}
2024-05-12 17:03:20 +00:00
*/
2024-05-04 08:26:16 +00:00
public static void Iterate( Node[] nodes, System.Action<Node> callback )
{
for ( int i = 0; i < nodes.Length; i++ )
{
nodesWalker.Iterate( nodes[ i ], callback );
}
}
2024-05-05 07:52:06 +00:00
2024-05-12 17:03:20 +00:00
2024-05-04 08:26:16 +00:00
}
}