This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
extend.gd
65 lines (56 loc) · 3.01 KB
/
extend.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
56
57
58
59
60
61
62
63
64
65
#*******************************************************************************#
# extend.gd #
#*******************************************************************************#
# This file is part of: #
# EXTEND #
# https://github.com/Iron-Stag-Games/Godot-Extend #
#*******************************************************************************#
# Copyright (c) 2020 hoontee @ Iron Stag Games. #
# #
# This library is free software; you can redistribute it and/or #
# modify it under the terms of the GNU Lesser General Public #
# License as published by the Free Software Foundation; either #
# version 3 of the License, or (at your option) any later version. #
# #
# This library is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
# Lesser General Public License for more details. #
# #
# You should have received a copy of the GNU Lesser General Public License #
# along with this library; if not, see <https://www.gnu.org/licenses/>. #
#*******************************************************************************#
tool
extends EditorPlugin
const classes := [
"Spatial",
"CSGCombiner",
"MeshInstance",
"RigidBody",
"StaticBody",
]
const GizmoPlugin := preload("res://addons/extend/ExtendGizmoPlugin.gd")
var editor_settings := get_editor_interface().get_editor_settings()
var color: Color = editor_settings.get_setting("editors/3d_gizmos/gizmo_colors/shape")
var gizmo_plugins := []
var old_global_transform: Transform
onready var undo_redo := get_undo_redo()
func _init() -> void:
for v in classes:
var gizmo_plugin := GizmoPlugin.new(v, color)
gizmo_plugin.connect("start_drag", self, "start_drag")
gizmo_plugin.connect("end_drag", self, "end_drag")
gizmo_plugins.push_back(gizmo_plugin)
func _enter_tree() -> void:
for gizmo_plugin in gizmo_plugins:
add_spatial_gizmo_plugin(gizmo_plugin)
func _exit_tree() -> void:
for gizmo_plugin in gizmo_plugins:
remove_spatial_gizmo_plugin(gizmo_plugin)
func start_drag(spatial: Spatial) -> void:
old_global_transform = spatial.global_transform
func end_drag(spatial: Spatial) -> void:
undo_redo.create_action("Translate Scale")
undo_redo.add_do_property(spatial, "global_transform", spatial.global_transform)
undo_redo.add_undo_property(spatial, "global_transform", old_global_transform)
undo_redo.commit_action()