TowerGame/addons/PathMesh3D/plugin.gd

54 lines
2.1 KiB
GDScript3
Raw Normal View History

2025-04-20 20:55:30 +01:00
@tool
extends EditorPlugin
const PathMesh3DOptions := preload("res://addons/PathMesh3D/scripts/path_mesh_3d_options.gd")
const PathMesh3DOptionsScene := preload("res://addons/PathMesh3D/scenes/path_mesh_3d_options.tscn")
const PathScene3DOptions := preload("res://addons/PathMesh3D/scripts/path_scene_3d_options.gd")
const PathScene3DOptionsScene := preload("res://addons/PathMesh3D/scenes/path_scene_3d_options.tscn")
var _mesh_editor_button: PathMesh3DOptions
var _scene_editor_button: PathScene3DOptions
var _path_object
func _enter_tree() -> void:
_mesh_editor_button = PathMesh3DOptionsScene.instantiate()
add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU, _mesh_editor_button)
_mesh_editor_button.hide()
_scene_editor_button = PathScene3DOptionsScene.instantiate()
add_control_to_container(CONTAINER_SPATIAL_EDITOR_MENU, _scene_editor_button)
_scene_editor_button.hide()
func _exit_tree() -> void:
remove_control_from_container(CONTAINER_SPATIAL_EDITOR_MENU, _mesh_editor_button)
remove_control_from_container(CONTAINER_SPATIAL_EDITOR_MENU, _scene_editor_button)
_mesh_editor_button.queue_free()
_scene_editor_button.queue_free()
func _handles(object: Object) -> bool:
2025-04-21 20:48:03 +01:00
return is_instance_valid(object) and (object is PathMesh3D or object is PathExtrude3D or object is PathScene3D)
2025-04-20 20:55:30 +01:00
func _edit(object: Object) -> void:
2025-04-21 20:48:03 +01:00
if is_instance_valid(object) and (object is PathMesh3D or object is PathExtrude3D) and _mesh_editor_button:
2025-04-20 20:55:30 +01:00
_path_object = object
_mesh_editor_button.path_mesh = object
_mesh_editor_button.ur = get_undo_redo()
2025-04-21 20:48:03 +01:00
elif is_instance_valid(object) and object is PathScene3D and _scene_editor_button:
2025-04-20 20:55:30 +01:00
_path_object = object
_scene_editor_button.path_scene = object
_scene_editor_button.ur = get_undo_redo()
func _make_visible(visible: bool) -> void:
2025-04-21 20:48:03 +01:00
if is_instance_valid(_path_object) and (_path_object is PathMesh3D or _path_object is PathExtrude3D) and visible:
2025-04-20 20:55:30 +01:00
_mesh_editor_button.visible = visible
2025-04-21 20:48:03 +01:00
elif is_instance_valid(_path_object) and _path_object is PathScene3D and visible:
2025-04-20 20:55:30 +01:00
_scene_editor_button.visible = visible
elif not visible:
_mesh_editor_button.visible = visible
_scene_editor_button.visible = visible