-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_tree_godot.gd
33 lines (26 loc) · 1.14 KB
/
node_tree_godot.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
@tool
extends EditorPlugin
func _enter_tree():
print("[PLUGIN] Copy Tree Plugin Loaded ✅")
var selection = get_editor_interface().get_selection()
if selection:
selection.selection_changed.connect(_on_selection_changed)
else:
print("[ERROR] Could not get EditorSelection! ❌")
func _exit_tree():
print("[PLUGIN] Copy Tree Plugin Unloaded ❌")
func _on_selection_changed():
var selected_nodes = get_editor_interface().get_selection().get_selected_nodes()
if selected_nodes.size() > 0:
var selected_node = selected_nodes[0]
print("\n[PLUGIN] Node Tree for:", selected_node.name)
print(selected_node.name + " (" + selected_node.get_class() + ")")
_print_node_tree(selected_node, "", true) # ✅ Fixed `true` (lowercase)
func _print_node_tree(node: Node, prefix: String, is_last: bool):
var connector = "└── " if is_last else "├── "
print(prefix + connector + node.name + " (" + node.get_class() + ")")
var child_count = node.get_child_count()
for i in range(child_count):
var child = node.get_child(i)
var new_prefix = prefix + (" " if is_last else "│ ")
_print_node_tree(child, new_prefix, i == child_count - 1)