OLS/Source/ols/Public/Systems/OLSAssetManager.h
LongLy 7415b74e8f Added CommonUser Plugins.
Implemented GameplayStackTags
2025-01-13 15:36:08 -07:00

112 lines
3.4 KiB
C++

// © 2024 Long Ly. All rights reserved. Any unauthorized use, reproduction, or distribution of this trademark is strictly prohibited and may result in legal action.
#pragma once
#include "CoreMinimal.h"
#include "Engine/AssetManager.h"
#include "OLSAssetManager.generated.h"
struct FOLSBundles
{
static const FName Equipped;
};
/**
* UOLSAssetManager
*
* Game implementation of the asset manager that overrides functionality and stores game-specific types.
* It is expected that most games will want to override AssetManager as it provides a good place for game-specific loading logic.
* Thi
*/
UCLASS(Config = Game)
class OLS_API UOLSAssetManager : public UAssetManager
{
GENERATED_BODY()
public:
UOLSAssetManager();
// Returns the AssetManager singleton object.
static UOLSAssetManager& Get();
// Returns the asset referenced by a TSoftObjectPtr. This will synchronously load the asset if it's not already loaded.
template<typename AssetType>
static AssetType* GetAsset(const TSoftObjectPtr<AssetType>& assetPointer, bool shouldKeepInMemory = true);
// Returns the subclass referenced by a TSoftClassPtr. This will synchronously load the asset if it's not already loaded.
template<typename AssetType>
static TSubclassOf<AssetType> GetSubclass(const TSoftClassPtr<AssetType>& assetPointer, bool shouldKeepInMemory = true);
// Logs all assets currently loaded and tracked by the asset manager.
static void DumpLoadedAssets();
// @Todo implement this function.
// const class UOLSPawnPrimaryDataAsset& GetGameData();
const class UOLSPawnDataAsset* GetDefaultPawnData() const;
protected:
template <typename GameDataClass>
const GameDataClass& GetOrLoadTypedGameData(const TSoftObjectPtr<GameDataClass>& dataPath);
static UObject* SynchronousLoadAsset(const FSoftObjectPath& assetPath);
static bool ShouldLogAssetLoads();
// Thread safe way of adding a loaded asset to keep in memory.
void AddLoadedAsset(const UObject* Asset);
//~UAssetManager interface
virtual void StartInitialLoading() override;
#if WITH_EDITOR
virtual void PreBeginPIE(bool shouldStartSimulate) override;
#endif
//~End of UAssetManager interface
class UPrimaryDataAsset* LoadGameDataOfClass(
TSubclassOf<UPrimaryDataAsset> dataClass,
const TSoftObjectPtr<UPrimaryDataAsset>& dataClassPath,
FPrimaryAssetType primaryAssetType);
private:
// Flushes the StartupJobs array. Processes all startup work.
void DoAllStartupJobs();
// Sets up the ability system
void InitializeGameplayCueManager();
// Called periodically during loads, could be used to feed the status to a loading screen
void UpdateInitialGameContentLoadPercent(float gameContentPercent);
protected:
// @Todo implement this.
// Global game data asset to use.
// UPROPERTY(Config)
// TSoftObjectPtr<ULyraGameData> LyraGameDataPath;
// Loaded version of the game data
UPROPERTY(Transient)
TMap<TObjectPtr<UClass>, TObjectPtr<UPrimaryDataAsset>> GameDataMap;
// Pawn data used when spawning player pawns if there isn't one set on the player state.
UPROPERTY(Config)
TSoftObjectPtr<class UOLSPawnDataAsset> DefaultPawnData;
private:
// Assets loaded and tracked by the asset manager.
UPROPERTY()
TSet<TObjectPtr<const UObject>> LoadedAssets;
// Used for a scope lock when modifying the list of load assets.
FCriticalSection LoadedAssetsCritical;
private:
// The list of tasks to execute on startup. Used to track startup progress.
TArray<struct FOLSAssetManagerStartupJob> StartupJobs;
};