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
| type_map = {'COMMAND': unreal.ToolMenuStringCommandType.COMMAND, 'PYTHON': unreal.ToolMenuStringCommandType.PYTHON} # 分割线字典用来分割项目 menu_section_dict = { "Assets":"AssetsManager", "Animation": "Animation", "Render":"Render", "Help":"Help" } #项目配置 menu_entry_dict = { "Assets_Tool" : { "section": "Assets", "label": "AssetsManager 2.0", "type": "PYTHON", "command": "from imp import reload;import UE4Tools;reload(UE4Tools);UE4Tools.showWindow()" } } #添加菜单栏目选项 menus = unreal.ToolMenus.get() main_menu = menus.find_menu('LevelEditor.MainMenu') if not main_menu: raise RuntimeError("Failed to find the 'Main' menu. Something is wrong in the force!") script_menu = main_menu.add_sub_menu(main_menu.get_name(), 'Tools', 'OneMT_Tools', 'OneMT') # 添加子项 for section, label in menu_section_dict.items(): script_menu.add_section(section, label)
for menu, data in menu_entry_dict.items(): entry = unreal.ToolMenuEntry(name=menu, type=unreal.MultiBlockType.MENU_ENTRY, insert_position=unreal.ToolMenuInsert('', unreal.ToolMenuInsertType.FIRST)) entry.set_label(data.get('label', 'untitle')) command = data.get('command', '') entry.set_string_command(type_map[data.get('type', 0)], '', string=command) script_menu.add_menu_entry(data.get('section', ''), entry) menus.refresh_all_widgets()
|