目录
Editor-Slate
WorkSpaceMenu(Slate相关类)
Editor-Tab-界面刷新
Editor-Slate
基本上,地球人都知道(我不是地球人)虚幻引擎的Editor界面(自定义)通过Slate管理
Slate的入口是方法::Construct()
所以我们知道了如下代码,产生如下的界面
void SPjcTabMain::Construct(const FArguments& InArgs, const TSharedRef<SDockTab>& ConstructUnderMajorTab, const TSharedPtr<SWindow>& ConstructUnderWindow)
{
TabManager = FGlobalTabmanager::Get()->NewTabManager(ConstructUnderMajorTab);
const TSharedRef<FWorkspaceItem> AppMenuGroup = TabManager->AddLocalWorkspaceMenuCategory(FText::FromString(PjcConstants::ModulePjcName.ToString()));
WorkSpaceMenu(Slate相关类)
当点击【Tabs】时,弹出界面Popup即可通过如下代码,获取WorkSpaceMenu(目测时虚幻引擎内置)
{
MenuBarBuilder.AddPullDownMenu(
FText::FromString(TEXT("Tabs")),
FText::GetEmpty(),
FNewMenuDelegate::CreateRaw(this, &SPjcTabMain::CreateMenuBarTabs, TabManager),
"Window"
);
}
void SPjcTabMain::CreateMenuBarTabs(FMenuBuilder& MenuBuilder, const TSharedPtr<FTabManager> TabManagerPtr)
{
if (!TabManagerPtr.IsValid()) return;
#if !WITH_EDITOR
FGlobalTabmanager::Get()->PopulateTabSpawnerMenu(MenuBuilder, WorkspaceMenu::GetMenuStructure().GetStructureRoot());
#endif
TabManagerPtr->PopulateLocalTabSpawnerMenu(MenuBuilder);
}
Editor-Tab-界面刷新
这个界面的刷新 cpp代码又是如何实现的呢?
(很传统的UI做法:由上而下刷新,子对象一层层刷新;你要说先进么,其实Unity Editor 的IMGUI,无限刷新还比较先进一点,写法也更灵活一点)
关键在于SPjcTabAssetsUnused这个类,也肯定是继承 XXXWidget 的
.h 代码
class SPjcTabAssetsUnused final : public SCompoundWidget
{
代码太多,.cpp 不贴了
void SPjcTabAssetsUnused::Construct(const FArguments& InArgs)
{
SubsystemPtr = GEditor->GetEditorSubsystem<UPjcSubsystem>();
if (!SubsystemPtr) return;
UContentBrowserSettings* ContentBrowserSettings = GetMutableDefault<UContentBrowserSettings>();
if (!ContentBrowserSettings) return;
ContentBrowserSettings->SetDisplayDevelopersFolder(true);
ContentBrowserSettings->SetDisplayEngineFolder(false);
ContentBrowserSettings->SetDisplayCppFolders(false);
ContentBrowserSettings->SetDisplayPluginFolders(false);
ContentBrowserSettings->bShowAllFolder = false;
ContentBrowserSettings->bOrganizeFolders = false;
ContentBrowserSettings->PostEditChange();
Cmds = MakeShareable(new FUICommandList);
Cmds->MapAction(FPjcCmds::Get().ScanProject, FExecuteAction::CreateRaw(this, &SPjcTabAssetsUnused::OnProjectScan));
Cmds->MapAction(
FPjcCmds::Get().CleanProject,
FExecuteAction::CreateRaw(this, &SPjcTabAssetsUnused::OnProjectClean),
FCanExecuteAction::CreateRaw(this, &SPjcTabAssetsUnused::CanCleanProject)
);
//............................
(你要是说虚幻复杂么,也挺复杂,各种继承;你要说它简单么,也挺简单,反正就是一切面向对象;大部分功能又必须多加很多额外的类,特别是相当于各种Wrap,各种事件回调;)
额外的还是搞下代码
SPjcTabAssetsUnused.cpp 的600+行
//最后获得几个关键字:GetModuleAssetRegistry() UseFilterToExcludeAssets
void UPjcSubsystem::GetAssetsAll(TArray<FAssetData>& Assets)
{
if (GetModuleAssetRegistry().Get().IsLoadingAssets()) return;
Assets.Reset();
GetModuleAssetRegistry().Get().GetAssetsByPath(PjcConstants::PathRoot, Assets, true);
// filtering assets that are in '/Game/__ExternalActors__' and '/Game/__ExternalObjects__' folders
FARFilter Filter;
Filter.bRecursivePaths = true;
Filter.PackagePaths.Add(FName{*GetPathExternalActors()});
Filter.PackagePaths.Add(FName{*GetPathExternalObjects()});
GetModuleAssetRegistry().Get().UseFilterToExcludeAssets(Assets, Filter);
}
参考项目:
这个项目真的不收费么。。。。。开源么。。。。。。
虚幻插件:ProjectCleaner