问题描述: 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的名字)。
就这些内容。