UE4自定义资源编辑器开发-编辑器布局

UE4自定义资源编辑器开发-编辑器布局

1 布局注册


对于一种应用模式类,需要创建一种对应的布局,该布局会在编辑器类调用SetCurrentMode(ModeName)时应用。



FTestEditorApplicationMode::FTestEditorApplicationMode(TSharedPtr<class FTestEditor> InTestEditor)
	: FApplicationMode(FTestEditor::CustomTestMode, FTestEditor::GetLocalizedMode)
{
	TestEditor = InTestEditor;

	TestEditorTabFactories.RegisterFactory(MakeShareable(new FTestDetailsSummoner(InTestEditor)));
	TestEditorTabFactories.RegisterFactory(MakeShareable(new FTestSearchSummoner(InTestEditor)));

	TabLayout = FTabManager::NewLayout( "Standalone_TestEditor_Layout_v1" )
	->AddArea
	(
		FTabManager::NewPrimaryArea() ->SetOrientation(Orient_Vertical)
		->Split
		(
			FTabManager::NewStack()
			->SetSizeCoefficient(0.1f)
			->AddTab(InTestEditor->GetToolbarTabId(), ETabState::OpenedTab)
			->SetHideTabWell(true) 
		)
		->Split
		(
			FTabManager::NewSplitter() ->SetOrientation(Orient_Horizontal)
			->Split
			(
				FTabManager::NewStack()
				->SetSizeCoefficient(0.7f)
				->AddTab(FTestEditorTabs::GraphEditorID, ETabState::ClosedTab)
			)
			->Split
			(
				FTabManager::NewSplitter() ->SetOrientation(Orient_Vertical)
				->SetSizeCoefficient(0.3f)
				->Split
				(
					FTabManager::NewStack()
					->AddTab(FTestEditorTabs::GraphDetailsID, ETabState::OpenedTab)
					->AddTab(FTestEditorTabs::SearchID, ETabState::ClosedTab)
				)

			)
		)
	);
	
}

每个标签页通过唯一名称来标识, 如:FTestEditorTabs::GraphEditorID

查看代码可以发现, RestoreFromLayout会在 SetCurrentMode里被调用, 开发者也可以自行调用来实现。

void FWorkflowCentricApplication::SetCurrentMode(FName NewMode)
{
	...
	// Activate the new layout
	const TSharedRef<FTabManager::FLayout> NewLayout = CurrentAppModePtr->ActivateMode(TabManager);
	RestoreFromLayout(NewLayout);
	...
}

编辑器运行后,会自动将布局存储在配置文件中,再次打开时,如果存在配置,则会加载。若想删除配置,可以将Engine/Saved目录下的配置文件删除。

TSharedRef<FTabManager::FLayout> FApplicationMode::ActivateMode(TSharedPtr<FTabManager> InTabManager)
{
	check(InTabManager.IsValid());
	RegisterTabFactories(InTabManager);
	// Try loading the layout from INI
	check(TabLayout.IsValid());
	return FLayoutSaveRestore::LoadFromConfig(GEditorLayoutIni, TabLayout.ToSharedRef());
}

LayoutConfig


链接




Tags: UE4 Editor Vistied:
Share: Twitter Facebook LinkedIn