|
|
|
|
| #pragma once
|
|
|
| #include "Engine/AssetManager.h"
|
| #include "LyraAssetManagerStartupJob.h"
|
| #include "Templates/SubclassOf.h"
|
| #include "LyraAssetManager.generated.h"
|
|
|
| #define UE_API LYRAGAME_API
|
|
|
| class UPrimaryDataAsset;
|
|
|
| class ULyraGameData;
|
| class ULyraPawnData;
|
|
|
| struct FLyraBundles
|
| {
|
| static const FName Equipped;
|
| };
|
|
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| UCLASS(MinimalAPI, Config = Game)
|
| class ULyraAssetManager : public UAssetManager
|
| {
|
| GENERATED_BODY()
|
|
|
| public:
|
|
|
| UE_API ULyraAssetManager();
|
|
|
|
|
| static UE_API ULyraAssetManager& Get();
|
|
|
|
|
| template<typename AssetType>
|
| static AssetType* GetAsset(const TSoftObjectPtr<AssetType>& AssetPointer, bool bKeepInMemory = true);
|
|
|
|
|
| template<typename AssetType>
|
| static TSubclassOf<AssetType> GetSubclass(const TSoftClassPtr<AssetType>& AssetPointer, bool bKeepInMemory = true);
|
|
|
|
|
| static UE_API void DumpLoadedAssets();
|
|
|
| UE_API const ULyraGameData& GetGameData();
|
| UE_API const ULyraPawnData* GetDefaultPawnData() const;
|
|
|
| protected:
|
| template <typename GameDataClass>
|
| const GameDataClass& GetOrLoadTypedGameData(const TSoftObjectPtr<GameDataClass>& DataPath)
|
| {
|
| if (TObjectPtr<UPrimaryDataAsset> const * pResult = GameDataMap.Find(GameDataClass::StaticClass()))
|
| {
|
| return *CastChecked<GameDataClass>(*pResult);
|
| }
|
|
|
|
|
| return *CastChecked<const GameDataClass>(LoadGameDataOfClass(GameDataClass::StaticClass(), DataPath, GameDataClass::StaticClass()->GetFName()));
|
| }
|
|
|
|
|
| static UE_API UObject* SynchronousLoadAsset(const FSoftObjectPath& AssetPath);
|
| static UE_API bool ShouldLogAssetLoads();
|
|
|
|
|
| UE_API void AddLoadedAsset(const UObject* Asset);
|
|
|
|
|
| UE_API virtual void StartInitialLoading() override;
|
| #if WITH_EDITOR
|
| UE_API virtual void PreBeginPIE(bool bStartSimulate) override;
|
| #endif
|
|
|
|
|
| UE_API UPrimaryDataAsset* LoadGameDataOfClass(TSubclassOf<UPrimaryDataAsset> DataClass, const TSoftObjectPtr<UPrimaryDataAsset>& DataClassPath, FPrimaryAssetType PrimaryAssetType);
|
|
|
| protected:
|
|
|
|
|
| UPROPERTY(Config)
|
| TSoftObjectPtr<ULyraGameData> LyraGameDataPath;
|
|
|
|
|
| UPROPERTY(Transient)
|
| TMap<TObjectPtr<UClass>, TObjectPtr<UPrimaryDataAsset>> GameDataMap;
|
|
|
|
|
| UPROPERTY(Config)
|
| TSoftObjectPtr<ULyraPawnData> DefaultPawnData;
|
|
|
| private:
|
|
|
| UE_API void DoAllStartupJobs();
|
|
|
|
|
| UE_API void InitializeGameplayCueManager();
|
|
|
|
|
| UE_API void UpdateInitialGameContentLoadPercent(float GameContentPercent);
|
|
|
|
|
| TArray<FLyraAssetManagerStartupJob> StartupJobs;
|
|
|
| private:
|
|
|
|
|
| UPROPERTY()
|
| TSet<TObjectPtr<const UObject>> LoadedAssets;
|
|
|
|
|
| FCriticalSection LoadedAssetsCritical;
|
| };
|
|
|
|
|
| template<typename AssetType>
|
| AssetType* ULyraAssetManager::GetAsset(const TSoftObjectPtr<AssetType>& AssetPointer, bool bKeepInMemory)
|
| {
|
| AssetType* LoadedAsset = nullptr;
|
|
|
| const FSoftObjectPath& AssetPath = AssetPointer.ToSoftObjectPath();
|
|
|
| if (AssetPath.IsValid())
|
| {
|
| LoadedAsset = AssetPointer.Get();
|
| if (!LoadedAsset)
|
| {
|
| LoadedAsset = Cast<AssetType>(SynchronousLoadAsset(AssetPath));
|
| ensureAlwaysMsgf(LoadedAsset, TEXT("Failed to load asset [%s]"), *AssetPointer.ToString());
|
| }
|
|
|
| if (LoadedAsset && bKeepInMemory)
|
| {
|
|
|
| Get().AddLoadedAsset(Cast<UObject>(LoadedAsset));
|
| }
|
| }
|
|
|
| return LoadedAsset;
|
| }
|
|
|
| template<typename AssetType>
|
| TSubclassOf<AssetType> ULyraAssetManager::GetSubclass(const TSoftClassPtr<AssetType>& AssetPointer, bool bKeepInMemory)
|
| {
|
| TSubclassOf<AssetType> LoadedSubclass;
|
|
|
| const FSoftObjectPath& AssetPath = AssetPointer.ToSoftObjectPath();
|
|
|
| if (AssetPath.IsValid())
|
| {
|
| LoadedSubclass = AssetPointer.Get();
|
| if (!LoadedSubclass)
|
| {
|
| LoadedSubclass = Cast<UClass>(SynchronousLoadAsset(AssetPath));
|
| ensureAlwaysMsgf(LoadedSubclass, TEXT("Failed to load asset class [%s]"), *AssetPointer.ToString());
|
| }
|
|
|
| if (LoadedSubclass && bKeepInMemory)
|
| {
|
|
|
| Get().AddLoadedAsset(Cast<UObject>(LoadedSubclass));
|
| }
|
| }
|
|
|
| return LoadedSubclass;
|
| }
|
|
|
| #undef UE_API
|
|
|