57 lines
1.7 KiB
C++
57 lines
1.7 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "Factory/FishInfoConfigAssetFactory.h"
|
|
#include "ProjectFish/DataAsset/QuestAsset.h"
|
|
#include "AssetRegistry/AssetRegistryModule.h"
|
|
#include "AssetRegistry/AssetData.h"
|
|
#include "ProjectFish/DataAsset/FishInfoConfigAsset.h"
|
|
|
|
UFishInfoConfigAssetFactory::UFishInfoConfigAssetFactory()
|
|
{
|
|
SupportedClass = UFishInfoConfigAsset::StaticClass();
|
|
bCreateNew = true;
|
|
bEditAfterNew = true;
|
|
}
|
|
|
|
UObject* UFishInfoConfigAssetFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags,
|
|
UObject* Context, FFeedbackContext* Warn)
|
|
{
|
|
UFishInfoConfigAsset* NewFishAsset = NewObject<UFishInfoConfigAsset>(InParent, Class, Name, Flags | RF_Transactional);
|
|
|
|
// 自动生成唯一的 QuestID
|
|
if (NewFishAsset)
|
|
{
|
|
int32 MaxFishID = 0;
|
|
|
|
// 获取资产注册表模块
|
|
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
|
|
IAssetRegistry& AssetRegistry = AssetRegistryModule.Get();
|
|
|
|
// 查找所有 QuestAsset 资产
|
|
TArray<FAssetData> AssetDataList;
|
|
AssetRegistry.GetAssetsByClass(UFishInfoConfigAsset::StaticClass()->GetClassPathName(), AssetDataList, true);
|
|
|
|
// 遍历所有已存在的任务资产,找到最大的 QuestID
|
|
for (const FAssetData& AssetData : AssetDataList)
|
|
{
|
|
if (UFishInfoConfigAsset* FishAsset = Cast<UFishInfoConfigAsset>(AssetData.GetAsset()))
|
|
{
|
|
if (FishAsset->FishID > MaxFishID)
|
|
{
|
|
MaxFishID = FishAsset->FishID;
|
|
}
|
|
}
|
|
}
|
|
NewFishAsset->FishID = MaxFishID + 1;
|
|
}
|
|
|
|
return NewFishAsset;
|
|
}
|
|
|
|
|
|
bool UFishInfoConfigAssetFactory::ShouldShowInNewMenu() const
|
|
{
|
|
return true;
|
|
}
|