godot-plateformer/addons/reedscene/reedscene.gd

71 lines
2.0 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@tool
extends EditorPlugin
var inspector_plugins: Array[EditorInspectorPlugin] = []
const AUTOLOAD_REED_SCENE_NAME: StringName = "ReedSceneRegistry"
const AUTOLOAD_REED_SCENE_PATH:= "res://addons/reedscene/scene/SceneRegistry.gd"
var toolbar_button: Button
var main_screen: Control
func _enter_tree() -> void:
_load_mainscreen()
if not ProjectSettings.has_setting("autoload/%s" % AUTOLOAD_REED_SCENE_NAME):
add_autoload_singleton(AUTOLOAD_REED_SCENE_NAME, AUTOLOAD_REED_SCENE_PATH)
# Inspector 1你已有的
var act_inspector := preload(
"res://addons/reedscene/act/ActManagerInspector.gd"
).new()
act_inspector.editor_interface = get_editor_interface()
add_inspector_plugin(act_inspector)
inspector_plugins.append(act_inspector)
# Inspector 2新的比如 ReedSceneID
var scene_id_inspector := preload(
"res://addons/reedscene/scene/ReedSceneIDInspector.gd"
).new()
add_inspector_plugin(scene_id_inspector)
inspector_plugins.append(scene_id_inspector)
func _exit_tree() -> void:
_unload_mainscreen()
##自动删除单例
if ProjectSettings.has_setting("autoload/%s" % AUTOLOAD_REED_SCENE_NAME):
remove_autoload_singleton(AUTOLOAD_REED_SCENE_NAME)
# 移除 InspectorPlugin
for plugin in inspector_plugins:
remove_inspector_plugin(plugin)
inspector_plugins.clear()
##加載主界面
func _load_mainscreen() -> void:
main_screen = preload("res://addons/reedscene/dock/SceneIDMainPanel.tscn").instantiate()
EditorInterface.get_editor_main_screen().add_child(main_screen)
main_screen.visible = false
##卸載主界面
func _unload_mainscreen() -> void:
if main_screen:
main_screen.queue_free()
main_screen = null
func _has_main_screen() -> bool:
return true
func _make_visible(visible: bool) -> void:
if not main_screen: return
main_screen.visible = visible
if visible:
main_screen.on_activated()
func _get_plugin_name() -> String:
return "Reed Scene"
func _get_plugin_icon() -> Texture2D:
return EditorInterface.get_editor_theme().get_icon("Node", "EditorIcons")