You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.0 KiB
GDScript

@tool
extends EditorPlugin
var selected_skill_file: String
var skill_popup: PopupMenu
var skill_cfg_list: Array[SkillCfg]
var menu_parent: Node
func _enter_tree():
var root: Node = EditorInterface.get_editor_main_screen()
while root.get_parent() != null:
root = root.get_parent()
menu_parent = root.get_child(0).get_child(4).get_child(0).get_child(0).get_child(0)
if menu_parent:
skill_popup = PopupMenu.new()
skill_popup.name = "技能配置"
skill_popup.about_to_popup.connect(skill_popup_about_to_popup)
skill_popup.index_pressed.connect(skill_popup_index_pressed)
menu_parent.add_child(skill_popup)
else:
print("menu_parent is null")
func skill_popup_about_to_popup():
skill_cfg_list.clear()
skill_popup.set_item_count(0)
skill_cfg_list = Util.get_all_skill()
for skill_cfg in skill_cfg_list:
skill_popup.add_item(skill_cfg.get_res_name())
func skill_popup_index_pressed(index: int):
EditorInterface.select_file(skill_cfg_list[index].resource_path)
func _process(delta: float) -> void:
var selected_paths: PackedStringArray = EditorInterface.get_selected_paths()
if len(selected_paths) != 1:
return
var selected_path: String = selected_paths[0]
if selected_skill_file == selected_path:
return
selected_skill_file = selected_path
if not selected_path.ends_with(".tres"):
return
var res := ResourceLoader.load(selected_path)
if not res is SkillCfg:
return
var skill_cfg: SkillCfg = res as SkillCfg
if not skill_cfg.skill_animation:
return
EditorInterface.open_scene_from_path("res://scene/character/character.tscn")
var root: Node = EditorInterface.get_edited_scene_root()
var character_skill: AnimationPlayer = root.find_child("Skill") as AnimationPlayer
EditorInterface.edit_node(character_skill)
var animation_name: String = "animation_library/%s" % Util.get_resource_name(res)
character_skill.current_animation = animation_name
EditorInterface.edit_resource(res)
func _exit_tree():
remove_tool_menu_item("Test")
if skill_popup: skill_popup.queue_free()