forked from godot-extended-libraries/godot-next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvector_display_2d.gd
55 lines (45 loc) · 1.49 KB
/
vector_display_2d.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
tool
class_name VectorDisplay2D
extends Node
# Displays Vector2 members in the editor via Position2D nodes.
export(String) var variable_name = ""
export(bool) var relative = true
var _old_variable_name = null
var _storage: Node2D
func _process(delta):
if Engine.is_editor_hint():
if not variable_name:
if _old_variable_name != variable_name:
_old_variable_name = variable_name
printerr("VectorDisplay2D: Please provide a variable name.")
return
if not _storage:
_storage = Node2D.new()
get_tree().get_edited_scene_root().add_child(_storage)
return
for child in _storage.get_children():
child.queue_free()
var parent = get_parent()
if relative:
_storage.transform.origin = parent.global_transform.origin
else:
_storage.transform.origin = Vector2.ZERO
var variable = parent.get(variable_name)
if variable == null:
if _old_variable_name != variable_name:
_old_variable_name = variable_name
printerr("VectorDisplay2D: Variable '" + variable_name + "' not found or invalid on parent node '" + get_parent().get_name() + "'.")
elif variable is Vector2:
_add_position_child(variable)
elif variable is PoolVector2Array:
for item in variable:
_add_position_child(item)
elif variable is Array:
for item in variable:
if item is Vector2:
_add_position_child(item)
func _add_position_child(vector):
var node = Position2D.new()
node.transform.origin = vector
_storage.add_child(node)
node.set_owner(get_tree().get_edited_scene_root())