15 virtual void Destroy()
override;
17 template<
typename AssetType>
20 virtual FAssetHandle ImportAsset(
const std::filesystem::path& Filepath)
override;
21 virtual void RemoveAsset(
const FAssetHandle Handle)
override;
26 virtual bool ReloadData(
const FAssetHandle Handle)
override;
28 virtual bool IsAssetHandleValid(
const FAssetHandle Handle)
const override;
29 virtual bool IsAssetLoaded(
const FAssetHandle Handle)
const override;
31 virtual bool IsMemoryAsset(
const FAssetHandle Handle)
const override
33 return MemoryAssets.contains(Handle);
36 virtual bool LoadAssetRegistry()
override;
37 virtual void WriteRegistryToDisk()
override;
41 virtual const FAssetMetadata& GetMetadata(
const std::filesystem::path& InFilePath)
const override;
43 virtual FAssetHandle GetAssetHandleFromFilePath(
const std::filesystem::path& InFilePath)
const override;
44 virtual EAssetType GetAssetTypeFromExtension(
const std::string& Extension)
const override;
45 virtual EAssetType GetAssetTypeFromPath(
const std::filesystem::path& InFilePath)
const override;
47 virtual std::unordered_set<FAssetHandle> GetAllAssetsWithType(
const EAssetType AssetType)
override;
48 virtual std::size_t GetAllAssetsWithType(
const EAssetType AssetType, std::unordered_set<FAssetHandle>& AssetsOfType)
override;
50 std::filesystem::path GetFileSystemPath(
const FAssetMetadata& Metadata)
const;
51 std::filesystem::path GetFileSystemPath(
const FAssetHandle Handle)
const;
52 std::filesystem::path GetRelativePath(
const std::filesystem::path& InFilePath)
const;
60 return Asset->As<T>();
63 LK_CORE_ERROR_TAG(
"RuntimeAssetManager",
"Failed to find asset with path: {}", InFilePath);
67 template<
typename T,
typename... TArgs>
68 TObjectPtr<T> CreateNewAsset(
const std::string& FileName,
const std::string& DirectoryPath, TArgs&&... Args)
70 static_assert(std::is_base_of_v<LAsset, T>,
"CreateNewAsset only works for assets derived from LAsset");
74 if (DirectoryPath.empty() || DirectoryPath ==
".")
76 Metadata.FilePath = FileName;
80 Metadata.FilePath = GetRelativePath(DirectoryPath +
"/" + FileName);
83 Metadata.bIsDataLoaded =
true;
84 Metadata.Type = T::GetStaticType();
86 AssetRegistry[Metadata.Handle] = Metadata;
87 WriteRegistryToDisk();
90 Asset->Handle = Metadata.Handle;
91 LoadedAssets[Asset->Handle] = Asset;
92 LAssetImporter::Serialize(Metadata, Asset);
97 virtual const std::unordered_map<FAssetHandle, TObjectPtr<LAsset>>& GetLoadedAssets()
const override
102 virtual const std::unordered_map<FAssetHandle, TObjectPtr<LAsset>>& GetMemoryOnlyAssets()
const override
109 const std::vector<std::pair<std::string, TObjectPtr<LTexture2D>>>& GetTextures2D()
const;
111 FORCEINLINE
const LAssetRegistry& GetAssetRegistry()
const {
return AssetRegistry; }
116 void LoadBaseMaterials();
117 void LoadPrimitiveShapes();
121 bool bAssetRegistryValid =
false;
123 std::unordered_map<FAssetHandle, TObjectPtr<LAsset>> LoadedAssets{};
124 std::unordered_map<FAssetHandle, TObjectPtr<LAsset>> MemoryAssets{};
126 std::unordered_map<std::string, TObjectPtr<LTexture2D>> Texture2DMap{};