74 lines
1.6 KiB
C#
74 lines
1.6 KiB
C#
|
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 )
|
||
|
{
|
||
|
return (T)node;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return null;
|
||
|
}
|
||
|
|
||
|
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 );
|
||
|
}
|
||
|
|
||
|
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 );
|
||
|
}
|
||
|
|
||
|
public static void Iterate( Node[] nodes, System.Action<Node> callback )
|
||
|
{
|
||
|
for ( int i = 0; i < nodes.Length; i++ )
|
||
|
{
|
||
|
nodesWalker.Iterate( nodes[ i ], callback );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|