42 lines
1.1 KiB
GDScript
42 lines
1.1 KiB
GDScript
extends Object
|
|
|
|
# 移除node节点
|
|
static func removeNode(node: Node) -> void:
|
|
if (node == null):
|
|
return
|
|
var parent = node.get_parent()
|
|
if (parent == null):
|
|
node.queue_free()
|
|
return
|
|
parent.remove_child(node)
|
|
node.queue_free()
|
|
pass
|
|
|
|
# 查找指定节点下的第一个目标节点
|
|
static func find_child_by_name(parent_node, target_name):
|
|
if parent_node.name == target_name:
|
|
return parent_node
|
|
for child in parent_node.get_children():
|
|
var found_node = find_child_by_name(child, target_name)
|
|
if found_node != null:
|
|
return found_node
|
|
return null
|
|
|
|
static func search_node(node,target_name,matching_nodes):
|
|
if node.name == target_name:
|
|
matching_nodes.append(node)
|
|
for child in node.get_children():
|
|
search_node(child,target_name,matching_nodes)
|
|
|
|
# 查找指定节点下的所有目标节点
|
|
static func find_children_by_name(parent_node, target_name):
|
|
var matching_nodes = []
|
|
search_node(parent_node,target_name,matching_nodes)
|
|
return matching_nodes
|
|
|
|
##节点下的所有节点可见
|
|
static func make_node_and_descendants_visible(node: Node):
|
|
node.visible = true
|
|
for child in node.get_children():
|
|
make_node_and_descendants_visible(child)
|