UE4编辑器ToolBar扩展

问题描述: Sequencer工具栏上后增加定制按钮,如图所示:

红框按钮后新增定制按钮。

寻找解决办法:商城上有一个插件是Substance Source,安装上之后可以看到如下界面:

跟我们的需求一致,那么就看下它是如何实现的。

virtual void StartupModule() override
{
   ...
   //Creates the button above the scene viewport to launch source window
   CreateToolbarButton();
    ...
}
void CreateToolbarButton()
	{
		FSubstanceSourceModuleCommands::Register(); //

		// Bind command
		CommandList = MakeShareable(new FUICommandList);

		struct Local
		{
			static void AddToolbarButton(FToolBarBuilder& ToolbarBuilder)
			{
				//NOTE:: Leave spacing in names for auto padding - Might be benificial to alter this later to lock in a solid size
				//and to remove string size
				ToolbarBuilder.AddToolBarButton(FSubstanceSourceModuleCommands::Get().LaunchSubstanceSourceWindow,
				                                NAME_None,
				                                FText::FromString("   Source   "),
				                                FText::FromString("   Source   "),
				                                FSlateIcon("SubstanceSourceStyle", "SubstanceSourceButtonIcon")
				                               );
			}
		};

		const FSubstanceSourceModuleCommands& Commands = FSubstanceSourceModuleCommands::Get();

		TSharedPtr<FExtender> ToolbarExtender = MakeShareable(new FExtender);

		ToolbarExtender->AddToolBarExtension(
		    "Content",
		    EExtensionHook::After,
		    CommandList,
		    FToolBarExtensionDelegate::CreateStatic(&Local::AddToolbarButton)
		);

		CommandList->MapAction(
		    Commands.LaunchSubstanceSourceWindow,
		    FExecuteAction::CreateRaw(this, &FSubstanceSourceModule::OnLaunchSubstanceSourceWindow),
		    FCanExecuteAction()
		);

		FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");

		LevelEditorModule.GetToolBarExtensibilityManager()->AddExtender(ToolbarExtender);
	}

这个有几个点: 

大部分的编辑器的ToolBar都支持扩展的,想知道该ToolBar是否支持扩展,可看下这个模块是否有提供类似于GetToolBarExtensibilityManager类似的函数,这个ExtensManager是在Toolbar构建的时候传入的,这样就支持了Toolbar扩展。举例看下LevelEditor的Toolbar构建时的代码:

FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
TSharedPtr<FExtender> Extenders = LevelEditorModule.GetToolBarExtensibilityManager()->GetAllExtenders();

static const FName LevelEditorToolBarName = "LevelEditorToolBar";
FToolBarBuilder ToolbarBuilder( InCommandList, FMultiBoxCustomization::AllowCustomization( LevelEditorToolBarName ), Extenders );

那么我们需要做的就是构建FExtender内容,获取到指定模块的ExtendsManager,然后执行AddExtender操作就可以了。

构建Extender主要是构建扩展的是按钮的样貌,点击后的响应,还是就是添加到哪个Section后面,SubstanceSource上的按钮是放在了“市场”后面,“市场”属于“Content”Section.(可以通过看下编辑器Toolbar构造代码可以知道按钮属于哪个Section以及Section的名字)。

就这些内容。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值