完善任务存档数据的加载读取
This commit is contained in:
parent
a8756f2e4c
commit
10d2c7e354
Binary file not shown.
Binary file not shown.
@ -13,6 +13,7 @@ FixedCameraDistance=1500.0
|
|||||||
+PrimaryAssetTypesToScan=(PrimaryAssetType="PrimaryAssetLabel",AssetBaseClass="/Script/Engine.PrimaryAssetLabel",bHasBlueprintClasses=False,bIsEditorOnly=True,Directories=((Path="/Game")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=Unknown))
|
+PrimaryAssetTypesToScan=(PrimaryAssetType="PrimaryAssetLabel",AssetBaseClass="/Script/Engine.PrimaryAssetLabel",bHasBlueprintClasses=False,bIsEditorOnly=True,Directories=((Path="/Game")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=Unknown))
|
||||||
+PrimaryAssetTypesToScan=(PrimaryAssetType="FishingRewardDataAsset",AssetBaseClass="/Script/ProjectFish.FishingRewardDataAsset",bHasBlueprintClasses=False,bIsEditorOnly=False,Directories=((Path="/Game/DataAssets/FishReward")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=AlwaysCook))
|
+PrimaryAssetTypesToScan=(PrimaryAssetType="FishingRewardDataAsset",AssetBaseClass="/Script/ProjectFish.FishingRewardDataAsset",bHasBlueprintClasses=False,bIsEditorOnly=False,Directories=((Path="/Game/DataAssets/FishReward")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=AlwaysCook))
|
||||||
+PrimaryAssetTypesToScan=(PrimaryAssetType="ShapeAsset",AssetBaseClass="/Script/ProjectFish.ShapeAsset",bHasBlueprintClasses=False,bIsEditorOnly=False,Directories=((Path="/Game/DataAssets")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=AlwaysCook))
|
+PrimaryAssetTypesToScan=(PrimaryAssetType="ShapeAsset",AssetBaseClass="/Script/ProjectFish.ShapeAsset",bHasBlueprintClasses=False,bIsEditorOnly=False,Directories=((Path="/Game/DataAssets")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=AlwaysCook))
|
||||||
|
+PrimaryAssetTypesToScan=(PrimaryAssetType="QuestAsset",AssetBaseClass="/Script/ProjectFish.QuestAsset",bHasBlueprintClasses=False,bIsEditorOnly=False,Directories=((Path="/Game/DataAssets/Quest")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=AlwaysCook))
|
||||||
bOnlyCookProductionAssets=False
|
bOnlyCookProductionAssets=False
|
||||||
bShouldManagerDetermineTypeAndName=False
|
bShouldManagerDetermineTypeAndName=False
|
||||||
bShouldGuessTypeAndNameInEditor=True
|
bShouldGuessTypeAndNameInEditor=True
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -48,14 +48,20 @@ bool UGameInfoManager::LoadGameInfo()
|
|||||||
PlayerInfo = Cast<UPlayerInfoSaveGame>(UGameplayStatics::LoadGameFromSlot(SaveGameSlotName, 0));
|
PlayerInfo = Cast<UPlayerInfoSaveGame>(UGameplayStatics::LoadGameFromSlot(SaveGameSlotName, 0));
|
||||||
|
|
||||||
// 加载任务数据
|
// 加载任务数据
|
||||||
if (PlayerInfo && GetGameInstance())
|
if (UQuestManager* QuestManager = GetGameInstance()->GetSubsystem<UQuestManager>())
|
||||||
{
|
{
|
||||||
if (UQuestManager* QuestManager = GetGameInstance()->GetSubsystem<UQuestManager>())
|
if (PlayerInfo && GetGameInstance())
|
||||||
{
|
{
|
||||||
QuestManager->LoadFromSaveData(PlayerInfo->QuestSaveData);
|
QuestManager->LoadFromSaveData(PlayerInfo->QuestSaveData);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TArray<FQuestSaveData> SaveData;
|
||||||
|
QuestManager->LoadFromSaveData(SaveData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "QuestManager.h"
|
#include "QuestManager.h"
|
||||||
|
|
||||||
|
#include "AssetRegistry/AssetRegistryModule.h"
|
||||||
|
#include "Engine/AssetManager.h"
|
||||||
#include "ProjectFish/DataAsset/QuestAsset.h"
|
#include "ProjectFish/DataAsset/QuestAsset.h"
|
||||||
#include "ProjectFish/Quest/QuestTypes.h"
|
#include "ProjectFish/Quest/QuestTypes.h"
|
||||||
|
|
||||||
@ -18,6 +20,30 @@ void UQuestManager::Deinitialize()
|
|||||||
CompletedQuestIDs.Empty();
|
CompletedQuestIDs.Empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UQuestManager::LoadAllQuests()
|
||||||
|
{
|
||||||
|
if (QuestAssets.Num() == 0)
|
||||||
|
{
|
||||||
|
// 获得所有任务资源id
|
||||||
|
TArray<FPrimaryAssetId> QuestAssetIds;
|
||||||
|
UAssetManager::Get().GetPrimaryAssetIdList(TEXT("QuestAsset"), QuestAssetIds);
|
||||||
|
|
||||||
|
// 异步加载所有任务资产
|
||||||
|
TSharedPtr<FStreamableHandle> LoadHandle = UAssetManager::Get().LoadPrimaryAssets(QuestAssetIds);
|
||||||
|
if (LoadHandle.IsValid())
|
||||||
|
{
|
||||||
|
LoadHandle->WaitUntilComplete();
|
||||||
|
TArray<UObject*> Assets;
|
||||||
|
LoadHandle->GetLoadedAssets(Assets); // 获取所有加载成功的资源
|
||||||
|
for (auto questAsset : Assets)
|
||||||
|
{
|
||||||
|
QuestAssets.Add(Cast<UQuestAsset>(questAsset));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool UQuestManager::AcceptQuest(UQuestAsset* QuestAsset)
|
bool UQuestManager::AcceptQuest(UQuestAsset* QuestAsset)
|
||||||
{
|
{
|
||||||
if (!QuestAsset)
|
if (!QuestAsset)
|
||||||
@ -250,10 +276,7 @@ void UQuestManager::LoadFromSaveData(const TArray<FQuestSaveData>& SaveData)
|
|||||||
// 清空现有数据
|
// 清空现有数据
|
||||||
ActiveQuestsMap.Empty();
|
ActiveQuestsMap.Empty();
|
||||||
CompletedQuestIDs.Empty();
|
CompletedQuestIDs.Empty();
|
||||||
|
LoadAllQuests();
|
||||||
// 注意:这里需要从资产管理器或配置中加载QuestAsset
|
|
||||||
// 暂时留空,需要根据项目的资产加载方式实现
|
|
||||||
// 建议在GameInstance或ProjectSettings中维护一个QuestAsset列表
|
|
||||||
|
|
||||||
for (const FQuestSaveData& Data : SaveData)
|
for (const FQuestSaveData& Data : SaveData)
|
||||||
{
|
{
|
||||||
@ -261,9 +284,28 @@ void UQuestManager::LoadFromSaveData(const TArray<FQuestSaveData>& SaveData)
|
|||||||
{
|
{
|
||||||
CompletedQuestIDs.Add(Data.QuestID);
|
CompletedQuestIDs.Add(Data.QuestID);
|
||||||
}
|
}
|
||||||
|
else if (Data.QuestState == EQuestState::InProgress)
|
||||||
|
{
|
||||||
|
for (auto questAsset: QuestAssets)
|
||||||
|
{
|
||||||
|
if (questAsset->QuestID == Data.QuestID)
|
||||||
|
{
|
||||||
|
FQuestRuntimeData RuntimeData = CreateRuntimeData(questAsset);
|
||||||
|
for (int i =0; i < RuntimeData.ObjectiveProgress.Num(); i++)
|
||||||
|
{
|
||||||
|
RuntimeData.ObjectiveProgress[i].CurrentProgress = Data.ObjectiveProgress[i];
|
||||||
|
RuntimeData.ObjectiveProgress[i].bCompleted = Data.ObjectiveCompleted[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
RuntimeData.State = EQuestState::InProgress;
|
||||||
|
ActiveQuestsMap.Add(questAsset->QuestID, RuntimeData);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: 从资产ID加载QuestAsset并恢复进度
|
|
||||||
// 需要实现资产查找逻辑
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -48,6 +48,8 @@ public:
|
|||||||
virtual void Deinitialize() override;
|
virtual void Deinitialize() override;
|
||||||
|
|
||||||
// ========== 任务操作 ==========
|
// ========== 任务操作 ==========
|
||||||
|
/** 加载本地所有任务 */
|
||||||
|
void LoadAllQuests();
|
||||||
|
|
||||||
/** 接受任务 */
|
/** 接受任务 */
|
||||||
UFUNCTION(BlueprintCallable, Category = "Quest")
|
UFUNCTION(BlueprintCallable, Category = "Quest")
|
||||||
@ -128,4 +130,7 @@ private:
|
|||||||
/** 已完成的任务ID列表 */
|
/** 已完成的任务ID列表 */
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
TSet<int32> CompletedQuestIDs;
|
TSet<int32> CompletedQuestIDs;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
TArray<UQuestAsset*> QuestAssets;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user