totalFrames = 500000 textDisplay = "This is the text displayed on a progress bar"# 进度显示的文字
with unreal.ScopedSlowTask(totalFrames, textDisplay) as ST: ST.make_dialog(True) # 创建对话框 for i inrange(totalFrames): if ST.should_cancel(): # 当用户点击取消时 break unreal.log("running running") ST.enter_progress_frame(1)
with unreal.ScopedSlowTask(totalRequiredBlueprints, slowTaskDisplayText) as ST: ST.make_dialog(True) for x inrange(totalRequiredBlueprints): if ST.should_cancel(): break newAsset = assetTools.create_asset(newAssetName%(x), createdAssetsPath, None, factory) unreal.EditorAssetLibrary.save_loaded_asset(newAsset) unreal.log("Just created an asset BP_PythonMade_%d via PYTHON API" %(x)) ST.enter_progress_frame(1)
with unreal.ScopedSlowTask(actorsCount, slowTaskDisplayText) as ST: ST.make_dialog(True) for x inrange(actorsCount): if ST.should_cancel(): break # 针对关卡的操作,所有这里去找EditorLevelLibray里的方法 unreal.EditorLevelLibrary.spawn_actor_from_object(selectedAssets[0], unreal.Vector(1.0+x*100, 1.0+x*100, 30.0), unreal.Rotator(0.0, 0.0, 10.0*x)) unreal.log("Just added an actor to the level!") ST.enter_progress_frame(1)
在程序主菜单下添加自定义菜单
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
import unreal
# Get the main menu class menus = unreal.ToolMenus.get() menu_name = 'LevelEditor.MainMenu' menu = menus.find_menu(menu_name)
# Custom menu parameters owner = menu.get_name() section_name = 'PythonTools' name = 'lingyunFX' label = 'lingyunFX' tool_tip = 'This is some python toolset.'
# Add and refresh menu.add_sub_menu(owner, section_name, name, label, tool_tip) menus.refresh_all_widgets()
为菜单添加按钮
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
import unreal
# Get the menu class menus = unreal.ToolMenus.get() menu_name = "LevelEditor.MainMenu.lingyunFX" menu = menus.find_menu(menu_name)
# Set the button type and label entry = unreal.ToolMenuEntry(type=unreal.MultiBlockType.MENU_ENTRY) entry.set_label('TEST BUTTON 01')
# Set button command typ = unreal.ToolMenuStringCommandType.PYTHON entry.set_string_command(typ, "", 'print "this is test button"')
# Add and refresh section_name = '' menu.add_menu_entry(section_name, entry) menus.refresh_all_widgets()