32 lines
1.1 KiB
GDScript
32 lines
1.1 KiB
GDScript
class_name Utils
|
|
extends Object
|
|
|
|
|
|
const VEC3_HOR := Vector3(1.0, 0.0, 1.0)
|
|
|
|
|
|
static func get_all_children(node: Node, internal: bool = false) -> Array[Node]:
|
|
if not is_instance_valid(node):
|
|
return []
|
|
|
|
var children: Array[Node] = []
|
|
for child: Node in node.get_children(internal):
|
|
children.append(child)
|
|
if child.get_child_count(internal) > 0:
|
|
children.append_array(get_all_children(child, internal))
|
|
|
|
return children
|
|
|
|
|
|
static func node_distance(node_a: Node3D, node_b: Node3D, position_modifier := Vector3.ONE) -> float:
|
|
if not is_instance_valid(node_a) or not is_instance_valid(node_b):
|
|
return -1.0
|
|
|
|
return (node_a.global_position * position_modifier).distance_to(node_b.global_position * position_modifier)
|
|
|
|
|
|
## Returns [code]true[/code] when [param node_a] is close to the [param from] node than [param node_b].[br]
|
|
## [b]Note:[/b] Meant to be used with the [method Array.sort_custom] function.
|
|
static func sort_by_distance(from: Node3D, node_a: Node3D, node_b: Node3D) -> bool:
|
|
return Utils.node_distance(from, node_a) <= Utils.node_distance(from, node_b)
|