UE小计:顶部工具栏按钮添加下拉列表,大纲列表、资源管理窗口右键添加按键

下拉列表

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 发布!

相关推荐
GDAL1 个月前
UE5入门教程:蓝图概念
ue
GDAL1 个月前
Pixel Streaming入门教程:SignallingWebServer
数字孪生·ue
Dawn·张2 个月前
UE小:UE5的Pixelstreaming在捕获画面的时候没办法显示非Viewport的Slate区域按钮的ToolTip
unity·游戏引擎·ue
普世的微光3 个月前
UE-- 引入IOS framework 库 真机运行闪退
c++·ios·ue
挨代码4 个月前
UE基础 —— Actors Reference
ue
挨代码4 个月前
UE基础 —— 编辑器界面
ue
海码0075 个月前
【UE 网络】Gameplay框架在DS架构中的扮演的角色
网络·架构·php·ue
闲杂人等121385 个月前
UE/Unity加载倾斜摄影太卡问题-使用局部网格简化重构导出为FBX/OBJ
unity·重构·游戏引擎·ue·倾斜摄影·灵易智模
何去何从28575 个月前
虚幻引擎中增强输入映射中鼠标输入无反应,怎么办?
虚幻引擎·ue
Carpe_yj_Diem7 个月前
UE5 FARFilter筛选器使用方法
ue