Esempio n. 1
0
    public static T FindFirstNodeOf <T>(this Godot.Node node) where T : Godot.Node
    {
        foreach (Godot.Node child in node.GetChildren())
        {
            if (child is T)
            {
                return((T)child);
            }
        }

        return(null);
    }
Esempio n. 2
0
        public static Godot.Node[] GetChildrenRecursive(this Godot.Node parent)
        {
            List <Godot.Node> result = new List <Godot.Node>();

            foreach (Godot.Node node in parent.GetChildren())
            {
                result.Add(node);

                if (node.GetChildCount() > 0)
                {
                    foreach (Godot.Node child in GetChildrenRecursive(node))
                    {
                        result.Add(child);
                    }
                }
            }

            return(result.ToArray());
        }
Esempio n. 3
0
    public static Array <T> FindAllNodesOf <T>(this Godot.Node node) where T : Godot.Node
    {
        var matching = new Array <T>();

        foreach (Godot.Node child in node.GetChildren())
        {
            if (child is T)
            {
                matching.Add((T)child);
            }

            Array <T> kids = child.FindAllNodesOf <T>();
            foreach (T kid in kids)
            {
                matching.Add(kid);
            }
        }

        return(matching);
    }