37 virtual void Destroy()
override;
39 template<
typename AssetType>
42 virtual FAssetHandle ImportAsset(
const std::filesystem::path& Filepath)
override;
43 virtual void RemoveAsset(
const FAssetHandle Handle)
override;
48 virtual bool ReloadData(
const FAssetHandle Handle)
override;
50 virtual bool IsAssetHandleValid(
const FAssetHandle Handle)
const override;
51 virtual bool IsAssetLoaded(
const FAssetHandle Handle)
const override;
53 virtual bool IsMemoryAsset(
const FAssetHandle Handle)
const override
55 return MemoryAssets.contains(Handle);
58 virtual bool LoadAssetRegistry()
override;
59 virtual void WriteRegistryToDisk()
override;
63 virtual const FAssetMetadata& GetMetadata(
const std::filesystem::path& InFilePath)
const override;
65 virtual FAssetHandle GetAssetHandleFromFilePath(
const std::filesystem::path& InFilePath)
const override;
66 virtual EAssetType GetAssetTypeFromExtension(
const std::string& Extension)
const override;
67 virtual EAssetType GetAssetTypeFromPath(
const std::filesystem::path& InFilePath)
const override;
69 virtual std::unordered_set<FAssetHandle> GetAllAssetsWithType(
const EAssetType AssetType)
override;
70 virtual std::size_t GetAllAssetsWithType(
const EAssetType AssetType, std::unordered_set<FAssetHandle>& AssetsOfType)
override;
72 std::filesystem::path GetFileSystemPath(
const FAssetMetadata& Metadata)
const;
73 std::filesystem::path GetFileSystemPath(
const FAssetHandle Handle)
const;
74 std::filesystem::path GetRelativePath(
const std::filesystem::path& InFilePath)
const;
82 return Asset->As<T>();
85 LK_CORE_ERROR_TAG(
"RuntimeAssetManager",
"Failed to find asset with path: {}", InFilePath);
89 template<
typename T,
typename... TArgs>
90 TObjectPtr<T> CreateNewAsset(
const std::string& FileName,
const std::string& DirectoryPath, TArgs&&... Args)
92 static_assert(std::is_base_of_v<LAsset, T>,
"CreateNewAsset only works for Assets derived from LAsset");
97 if (DirectoryPath.empty() || DirectoryPath ==
".")
99 Metadata.FilePath = FileName;
103 Metadata.FilePath = GetRelativePath(DirectoryPath +
"/" + FileName);
106 Metadata.bIsDataLoaded =
true;
107 Metadata.Type = T::GetStaticType();
109 AssetRegistry[Metadata.Handle] = Metadata;
110 WriteRegistryToDisk();
113 Asset->Handle = Metadata.Handle;
114 LoadedAssets[Asset->Handle] = Asset;
115 LAssetImporter::Serialize(Metadata, Asset);
120 virtual const std::unordered_map<FAssetHandle, TObjectPtr<LAsset>>& GetLoadedAssets()
const override
125 virtual const std::unordered_map<FAssetHandle, TObjectPtr<LAsset>>& GetMemoryOnlyAssets()
const override
132 const std::vector<std::pair<std::string, TObjectPtr<LTexture2D>>>& GetTextures2D()
const;
134 FORCEINLINE
const LAssetRegistry& GetAssetRegistry()
const {
return AssetRegistry; }
139 void LoadBaseMaterials();
140 void LoadPrimitiveShapes();
151 bool bAssetRegistryValid =
false;
153 std::unordered_map<FAssetHandle, TObjectPtr<LAsset>> LoadedAssets{};
154 std::unordered_map<FAssetHandle, TObjectPtr<LAsset>> MemoryAssets{};
156 std::unordered_map<std::string, TObjectPtr<LTexture2D>> Texture2DMap{};
Definition EditorAssetManager.h:14