132 lines
5.1 KiB
C++
132 lines
5.1 KiB
C++
#include "ProjectFishEditor.h"
|
||
|
||
#include "AssetTypeActions_Base.h"
|
||
#include "DataTableRowSelectorCustomization.h"
|
||
#include "AssetActions/BagConfigAssetTypeAction.h"
|
||
#include "AssetActions/BagShapeAssetTypeAction.h"
|
||
#include "AssetRegistry/AssetRegistryModule.h"
|
||
#include "ProjectFish/DataAsset/BagShapeAsset.h"
|
||
#include "../Public/Thumbnail/BagShapeAssetThumbnailRenderer.h"
|
||
|
||
#define LOCTEXT_NAMESPACE "FProjectFishEditorModule"
|
||
|
||
void FProjectFishEditorModule::StartupModule()
|
||
{
|
||
FPropertyEditorModule& PropModule = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
|
||
PropModule.RegisterCustomPropertyTypeLayout("SkillDataConfig"
|
||
, FOnGetPropertyTypeCustomizationInstance::CreateStatic(&FDataTableRowSelectorCustomization::MakeInstance));
|
||
|
||
//注册资源类型编辑器
|
||
RegisterAssetTypeActions();
|
||
//注册资源缩略图
|
||
RegisterThumbnailRenderers();
|
||
}
|
||
|
||
void FProjectFishEditorModule::ShutdownModule()
|
||
{
|
||
if ( FPropertyEditorModule* PropModule = FModuleManager::GetModulePtr<FPropertyEditorModule>("PropertyEditor"))
|
||
{
|
||
PropModule->UnregisterCustomPropertyTypeLayout("SkillDataConfig");
|
||
}
|
||
//注销资源类型编辑器
|
||
UnregisterAssetTypeActions();
|
||
//注销缩略图
|
||
UnregisterThumbnailRenderers();
|
||
}
|
||
|
||
void FProjectFishEditorModule::RegisterAssetTypeActions()
|
||
{
|
||
FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools");
|
||
IAssetTools& AssetTools = AssetToolsModule.Get();
|
||
//注册背包形状的菜单
|
||
EAssetTypeCategories::Type BogShapeAssetCategory = AssetTools.RegisterAdvancedAssetCategory(FName(TEXT("BagShape")), FText::FromString(TEXT("BagSystem")));
|
||
//BagShape
|
||
TSharedRef<FAssetTypeActions_Base> BagShapeAction = MakeShareable(new FBagShapeAssetTypeAction(BogShapeAssetCategory));
|
||
AssetTools.RegisterAssetTypeActions(BagShapeAction);
|
||
CreatedAssetTypeActions.Add(BagShapeAction);
|
||
|
||
//注册背包配置菜单
|
||
//EAssetTypeCategories::Type BagConfigAssetCategory = AssetTools.RegisterAdvancedAssetCategory(FName(TEXT("BagConfig")), FText::FromString(TEXT("BagSystem")));
|
||
TSharedRef<FAssetTypeActions_Base> BagConfigAction = MakeShareable(new FBagConfigAssetTypeAction(BogShapeAssetCategory));
|
||
AssetTools.RegisterAssetTypeActions(BagConfigAction);
|
||
CreatedAssetTypeActions.Add(BagConfigAction);
|
||
|
||
|
||
}
|
||
|
||
void FProjectFishEditorModule::UnregisterAssetTypeActions()
|
||
{
|
||
if (FModuleManager::Get().IsModuleLoaded("AssetTools"))
|
||
{
|
||
FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools");
|
||
IAssetTools& AssetTools = AssetToolsModule.Get();
|
||
for (auto action : CreatedAssetTypeActions)
|
||
{
|
||
AssetTools.UnregisterAssetTypeActions(action.ToSharedRef());
|
||
}
|
||
}
|
||
CreatedAssetTypeActions.Empty();
|
||
|
||
}
|
||
|
||
void FProjectFishEditorModule::RegisterThumbnailRenderers()
|
||
{
|
||
UThumbnailManager::Get().RegisterCustomRenderer(UBagShapeAsset::StaticClass(), UBagShapeAssetThumbnailRenderer::StaticClass());
|
||
RefreshExistingAssetThumbnails();
|
||
}
|
||
|
||
void FProjectFishEditorModule::UnregisterThumbnailRenderers()
|
||
{
|
||
if (UObjectInitialized())
|
||
{
|
||
UThumbnailManager::Get().UnregisterCustomRenderer(UBagShapeAsset::StaticClass());
|
||
}
|
||
}
|
||
|
||
void FProjectFishEditorModule::RefreshExistingAssetThumbnails()
|
||
{
|
||
// 延迟执行以确保所有模块都已加载
|
||
FTSTicker::GetCoreTicker().AddTicker(FTickerDelegate::CreateLambda([](float DeltaTime) -> bool
|
||
{
|
||
if (FModuleManager::Get().IsModuleLoaded("AssetRegistry"))
|
||
{
|
||
FAssetRegistryModule& AssetRegistryModule = FModuleManager::GetModuleChecked<FAssetRegistryModule>("AssetRegistry");
|
||
IAssetRegistry& AssetRegistry = AssetRegistryModule.Get();
|
||
|
||
// 查找所有BagShapeAsset资产
|
||
TArray<FAssetData> BagShapeAssetList;
|
||
AssetRegistry.GetAssetsByClass(UBagShapeAsset::StaticClass()->GetClassPathName(), BagShapeAssetList);
|
||
|
||
// 查找所有BagClass资产
|
||
TArray<FAssetData> BagClassAssetList;
|
||
//AssetRegistry.GetAssetsByClass(UBagClass::StaticClass()->GetClassPathName(), BagClassAssetList);
|
||
|
||
// 合并资产列表
|
||
TArray<FAssetData> AllAssets;
|
||
AllAssets.Append(BagShapeAssetList);
|
||
AllAssets.Append(BagClassAssetList);
|
||
|
||
// 刷新每个资产的缩略图
|
||
UThumbnailManager& ThumbnailManager = UThumbnailManager::Get();
|
||
for (const FAssetData& AssetData : AllAssets)
|
||
{
|
||
if (UObject* Asset = AssetData.GetAsset())
|
||
{
|
||
// 通知系统资源已修改
|
||
if (GEditor)
|
||
{
|
||
GEditor->GetEditorSubsystem<UImportSubsystem>()->BroadcastAssetPostImport(nullptr, Asset);
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
|
||
// 只执行一次,返回false停止ticker
|
||
return false;
|
||
}), 1.0f); // 1秒延迟
|
||
}
|
||
|
||
#undef LOCTEXT_NAMESPACE
|
||
|
||
IMPLEMENT_MODULE(FProjectFishEditorModule, ProjectFishEditor) |