FantasyRun/utils.gd

24 lines
797 B
GDScript3
Raw Normal View History

extends Node
func get_first_node_of_type(parent: Node, type: Variant, include_internal: bool = false) -> Node:
var result = null
for child in parent.get_children(include_internal):
if is_instance_of(child, type):
result = child
break
elif child.get_child_count(include_internal) > 0:
result = get_first_node_of_type(child, type, include_internal)
if result != null:
break
return result
func get_nodes_of_class(parent: Node, type: Variant, include_internal: bool = false) -> Array[Variant]:
2024-09-30 20:50:05 -07:00
var nodes: Array[Variant] = []
for child in parent.get_children(include_internal):
if is_instance_of(child, type):
nodes.append(child)
2024-09-30 20:50:05 -07:00
elif child.get_child_count(include_internal) > 0:
nodes.append_array(get_nodes_of_class(child, type, include_internal))
return nodes