-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditorAddon.gd
More file actions
40 lines (32 loc) · 1.08 KB
/
EditorAddon.gd
File metadata and controls
40 lines (32 loc) · 1.08 KB
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
tool
extends EditorPlugin
var selected_node : GridNode2D = null
# We want these nodes to be moved only by the grid increments
func handles(object):
return object is GridNode2D
func forward_canvas_gui_input(event):
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and not event.is_pressed():
updatePosition()
selected_node.property_list_changed_notify()
return false
# Update the node position on the grid and on the screen
func updatePosition():
var pos = selected_node.position
var grid_pos = Vector2()
var spacing = selected_node.grid_spacing
var offset = Vector2()
if selected_node.anchor_settings == GridNode2D.AnchorSettings.CENTERED:
offset = Vector2(spacing / 2, spacing / 2)
grid_pos.x = int(pos.x / spacing)
grid_pos.y = int(pos.y / spacing)
selected_node.grid_position = grid_pos
selected_node.position = grid_pos * spacing + offset
func edit(node):
selected_node = node
func clear():
selected_node = null
func _enter_tree():
print('GridNode2D addon loaded!')
set_process_input(true)
func _exit_tree():
print('GridNode2D addon unloaded!')