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

下拉列表

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);
        }
    }
}

大纲列表

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));
}

资源管理窗口

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Dawn·张

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值