下拉列表
cpp
void FYouPluginsModule::StartupModule()
{
FYouToolStyle::Initialize();
FYouToolStyle::ReloadTextures();
FYouToolCommands::Register();
PluginCommands = MakeShareable(new FUICommandList);
PluginCommands->MapAction(
FYouToolCommands::Get().PackByCloudAction,
FExecuteAction::CreateRaw(this,&FYouPluginsModule::OpenPakWidget),
FCanExecuteAction()
);
PluginCommands->MapAction(
FYouToolCommands::Get().GenerateJSAction,
FExecuteAction::CreateRaw(this,&FYouPluginsModule::GenerateJS),
FCanExecuteAction()
);
UToolMenus::RegisterStartupCallback(FSimpleMulticastDelegate::FDelegate::CreateRaw(this,&FYouPluginsModule::RegisterMenus));
}
void FYouPluginsModule::RegisterMenus()
{
FToolMenuOwnerScoped OwnerScoped(this);
UToolMenu* ToolMenu = UToolMenus::Get()->ExtendMenu("LevelEditor.LevelEditorToolBar.User");
{
FToolMenuSection& Section = ToolMenu->AddSection("YouTool");
Section.AddSeparator("YouToolSeparator");
{
FToolMenuEntry SettingEntry = FToolMenuEntry::InitComboButton(
"YouToolMenus",
FUIAction(),
FOnGetContent::CreateLambda([&]()->TSharedRef<SWidget,ESPMode::ThreadSafe>
{
FMenuBuilder MenuBuilder(true,PluginCommands);
MenuBuilder.BeginSection("YouTool",LOCTEXT("Package Tool","Pack Asset Or Scene witch Cloud"));
MenuBuilder.AddMenuEntry(FYouToolCommands::Get().PackByCloudAction);
MenuBuilder.EndSection();
return MenuBuilder.MakeWidget();
}),
LOCTEXT("YouToolMenu","YouTool"),
LOCTEXT("YouToolMenuTooltip","Package Asset Or Scene"),
FSlateIcon(FYouToolStyle::GetStyleSetName(),"YouTool"),
false,
"YouToolMenu"
);
SettingEntry.StyleNameOverride = "CalloutToolbar";
SettingEntry.SetCommandList(PluginCommands);
Section.AddEntry(SettingEntry);
}
}
}
大纲列表
cpp
void AddCustomMenuEntry(FMenuBuilder& MenuBuilder)
{
MenuBuilder.AddMenuEntry(
FText::FromString("Editor UserData"),
FText::FromString("Perform an action with the Editor UserData."),
FSlateIcon(),
FUIAction(FExecuteAction::CreateStatic([]()
{
// 这里是当你的菜单项被点击时要执行的代码
UE_LOG(LogTemp, Log, TEXT("Editor UserData clicked!"));
}))
);
}
TSharedRef<FExtender> OnExtendLevelEditorMenu(const TSharedRef<FUICommandList> CommandList, TArray<AActor*> SelectedActors)
{
TSharedRef<FExtender> Extender(new FExtender());
Extender->AddMenuExtension(
"ActorControl",
EExtensionHook::After,
CommandList,
FMenuExtensionDelegate::CreateStatic(&AddCustomMenuEntry)
);
return Extender;
}
void FYourGameEditorModule::StartupModule()
{
FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
auto& MenuExtenders = LevelEditorModule.GetAllLevelViewportContextMenuExtenders();
MenuExtenders.Add(FLevelEditorModule::FLevelViewportMenuExtender_SelectedActors::CreateStatic(&OnExtendLevelEditorMenu));
}
资源管理窗口
cpp
TSharedRef<FExtender> FYourGameEditorModule::OnExtendContentBrowserAssetSelectiongMenu(const TArray<FAssetData>& SelectAssets)
{
TSharedRef<FExtender> Extender(new FExtender());
Extender->AddMenuExtension(
"CommonAssetActions",
EExtensionHook::After,
nullptr,
FMenuExtensionDelegate::CreateRaw(this,&FYourGameEditorModule::MenuExtension,SelectAssets)
);
return Extender;
}
void FYourGameEditorModule::MenuExtension(FMenuBuilder& MenuBuilder, TArray<FAssetData> SelectAssets)
{
MenuBuilder.AddMenuEntry(
LOCTEXT("PakAssetTitle","Pak Asset"),
LOCTEXT("PakAssetTooltipText","Pak Asset And Dependence"),
//todo 增肌icon
// FSlateIcon(FPakToolEditorStyle::GetStyleSetName(), "PakTool"),
FSlateIcon(),
FUIAction(FExecuteAction::CreateRaw(this,&FYourGameEditorModule::OnClickMenu,SelectAssets,false))
);
MenuBuilder.AddMenuEntry(
LOCTEXT("PakAssetPIETitle","Pak Asset PIE"),
LOCTEXT("PakAssetTooltipPIEText","Pak Asset And Dependence In Editor"),
// FSlateIcon(FPakToolEditorStyle::GetStyleSetName(), "PakTool"),
FSlateIcon(),
FUIAction(FExecuteAction::CreateRaw(this,&FYourGameEditorModule::OnClickMenu,SelectAssets,true))
);
}
void FYourGameEditorModule::StartupModule()
{
FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>(TEXT("ContentBrowser"));
TArray<FContentBrowserMenuExtender_SelectedAssets>& MenuExtenderDelegates = ContentBrowserModule.GetAllAssetViewContextMenuExtenders();
ContentBrowserAssetExtenderDelegate = FContentBrowserMenuExtender_SelectedAssets::CreateRaw(this,&FYourGameEditorModule::OnExtendContentBrowserAssetSelectiongMenu);
MenuExtenderDelegates.Add(ContentBrowserAssetExtenderDelegate);
ContentBrowserAssetExtenderDelegateHandle = MenuExtenderDelegates.Last().GetHandle();
}
本文由博客一文多发平台 OpenWrite 发布!