2025-06-24 15:01:58 +08:00
|
|
|
|
#include "ProjectFishEditor.h"
|
|
|
|
|
|
|
2025-08-29 16:26:42 +08:00
|
|
|
|
#include "AssetTypeActions_Base.h"
|
2025-06-24 15:01:58 +08:00
|
|
|
|
#include "DataTableRowSelectorCustomization.h"
|
2025-08-31 14:41:41 +08:00
|
|
|
|
#include "AssetActions/BagConfigAssetTypeAction.h"
|
2025-08-29 16:26:42 +08:00
|
|
|
|
#include "AssetActions/BagShapeAssetTypeAction.h"
|
2025-08-30 19:55:46 +08:00
|
|
|
|
#include "AssetRegistry/AssetRegistryModule.h"
|
|
|
|
|
|
#include "ProjectFish/DataAsset/BagShapeAsset.h"
|
2025-08-31 15:14:48 +08:00
|
|
|
|
#include "../Public/Thumbnail/BagShapeAssetThumbnailRenderer.h"
|
2025-08-31 16:10:56 +08:00
|
|
|
|
#include "../Public/Thumbnail/BagConfigThumbnailRenderer.h"
|
2025-09-01 10:20:49 +08:00
|
|
|
|
#include "AssetActions/SkillAssetTypeAction.h"
|
2025-08-31 16:10:56 +08:00
|
|
|
|
#include "ProjectFish/DataAsset/BagConfigAsset.h"
|
2025-06-24 15:01:58 +08:00
|
|
|
|
|
|
|
|
|
|
#define LOCTEXT_NAMESPACE "FProjectFishEditorModule"
|
|
|
|
|
|
|
|
|
|
|
|
void FProjectFishEditorModule::StartupModule()
|
|
|
|
|
|
{
|
|
|
|
|
|
FPropertyEditorModule& PropModule = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
|
|
|
|
|
|
PropModule.RegisterCustomPropertyTypeLayout("SkillDataConfig"
|
|
|
|
|
|
, FOnGetPropertyTypeCustomizationInstance::CreateStatic(&FDataTableRowSelectorCustomization::MakeInstance));
|
2025-08-29 16:26:42 +08:00
|
|
|
|
|
|
|
|
|
|
//注册资源类型编辑器
|
|
|
|
|
|
RegisterAssetTypeActions();
|
2025-08-31 14:41:41 +08:00
|
|
|
|
//注册资源缩略图
|
|
|
|
|
|
RegisterThumbnailRenderers();
|
2025-06-24 15:01:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FProjectFishEditorModule::ShutdownModule()
|
|
|
|
|
|
{
|
|
|
|
|
|
if ( FPropertyEditorModule* PropModule = FModuleManager::GetModulePtr<FPropertyEditorModule>("PropertyEditor"))
|
|
|
|
|
|
{
|
|
|
|
|
|
PropModule->UnregisterCustomPropertyTypeLayout("SkillDataConfig");
|
|
|
|
|
|
}
|
2025-08-29 18:09:13 +08:00
|
|
|
|
//注销资源类型编辑器
|
2025-08-29 16:26:42 +08:00
|
|
|
|
UnregisterAssetTypeActions();
|
2025-08-31 14:41:41 +08:00
|
|
|
|
//注销缩略图
|
|
|
|
|
|
UnregisterThumbnailRenderers();
|
2025-08-29 16:26:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FProjectFishEditorModule::RegisterAssetTypeActions()
|
|
|
|
|
|
{
|
|
|
|
|
|
FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools");
|
|
|
|
|
|
IAssetTools& AssetTools = AssetToolsModule.Get();
|
2025-08-31 14:41:41 +08:00
|
|
|
|
//注册背包形状的菜单
|
|
|
|
|
|
EAssetTypeCategories::Type BogShapeAssetCategory = AssetTools.RegisterAdvancedAssetCategory(FName(TEXT("BagShape")), FText::FromString(TEXT("BagSystem")));
|
2025-08-29 16:26:42 +08:00
|
|
|
|
//BagShape
|
2025-08-31 14:41:41 +08:00
|
|
|
|
TSharedRef<FAssetTypeActions_Base> BagShapeAction = MakeShareable(new FBagShapeAssetTypeAction(BogShapeAssetCategory));
|
2025-08-29 16:26:42 +08:00
|
|
|
|
AssetTools.RegisterAssetTypeActions(BagShapeAction);
|
|
|
|
|
|
CreatedAssetTypeActions.Add(BagShapeAction);
|
2025-08-30 19:55:46 +08:00
|
|
|
|
|
2025-08-31 14:41:41 +08:00
|
|
|
|
//注册背包配置菜单
|
|
|
|
|
|
//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);
|
|
|
|
|
|
|
2025-09-01 10:20:49 +08:00
|
|
|
|
//注册技能资源菜单
|
|
|
|
|
|
TSharedRef<FAssetTypeActions_Base> SkillAssetAction = MakeShareable(new FSkillAssetTypeAction(BogShapeAssetCategory));
|
|
|
|
|
|
AssetTools.RegisterAssetTypeActions(SkillAssetAction);
|
|
|
|
|
|
CreatedAssetTypeActions.Add(SkillAssetAction);
|
2025-08-29 16:26:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
2025-08-31 14:41:41 +08:00
|
|
|
|
|
2025-08-30 19:55:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FProjectFishEditorModule::RegisterThumbnailRenderers()
|
|
|
|
|
|
{
|
|
|
|
|
|
UThumbnailManager::Get().RegisterCustomRenderer(UBagShapeAsset::StaticClass(), UBagShapeAssetThumbnailRenderer::StaticClass());
|
2025-08-31 16:10:56 +08:00
|
|
|
|
UThumbnailManager::Get().RegisterCustomRenderer(UBagConfigAsset::StaticClass(), UBagConfigThumbnailRenderer::StaticClass());
|
2025-08-30 19:55:46 +08:00
|
|
|
|
RefreshExistingAssetThumbnails();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FProjectFishEditorModule::UnregisterThumbnailRenderers()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (UObjectInitialized())
|
|
|
|
|
|
{
|
|
|
|
|
|
UThumbnailManager::Get().UnregisterCustomRenderer(UBagShapeAsset::StaticClass());
|
2025-08-31 16:10:56 +08:00
|
|
|
|
UThumbnailManager::Get().UnregisterCustomRenderer(UBagConfigAsset::StaticClass());
|
2025-08-30 19:55:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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资产
|
2025-08-31 16:10:56 +08:00
|
|
|
|
TArray<FAssetData> BagConfigAssetList;
|
|
|
|
|
|
AssetRegistry.GetAssetsByClass(UBagConfigAsset::StaticClass()->GetClassPathName(), BagConfigAssetList);
|
2025-08-30 19:55:46 +08:00
|
|
|
|
|
|
|
|
|
|
// 合并资产列表
|
|
|
|
|
|
TArray<FAssetData> AllAssets;
|
|
|
|
|
|
AllAssets.Append(BagShapeAssetList);
|
2025-08-31 16:10:56 +08:00
|
|
|
|
AllAssets.Append(BagConfigAssetList);
|
2025-08-30 19:55:46 +08:00
|
|
|
|
|
|
|
|
|
|
// 刷新每个资产的缩略图
|
|
|
|
|
|
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秒延迟
|
2025-06-24 15:01:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#undef LOCTEXT_NAMESPACE
|
|
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_MODULE(FProjectFishEditorModule, ProjectFishEditor)
|