AssetManager - osy9611/ProjectPT GitHub Wiki
Unity์์๋ Addressable์ ์ฌ์ฉํด์ ๋ฆฌ์์ค๋ฅผ ๊ด๋ฆฌํ์๋ค. Unreal์ AssetManager์ ๋น๊ตํด ์ฐจ์ด์ ์ ์ ๋ฆฌํ๋ค.
- ๊ธฐ๋ณธ์ ์ผ๋ก Addressable์ ์ด์ฉํด์ ๋ฆฌ์์ค๋ฅผ ๊ด๋ฆฌํ๋ค. (AssetBundle๊ณผ Resource ๋ฐฉ์๋ ์์ง๋ง ํด๋น ๋ถ๋ถ์ ์ด ๊ธ์์ ๋ค๋ฃจ์ง ์๊ฒ ๋ค)
- Addressable์ ์ด์ฉํ ResourceManager๋ฅผ ๊ตฌํํ ๋ ๊ณ ๋ คํ๋ ์ฌํญ
- ๋ฆฌ์์ค ์ค๋ณต ๋ก๋๋ฅผ ๋ฐฉ์งํ๊ธฐ ์ํด์ ๊ฐ AsyncOperationHandle ๊ด๋ฆฌํจ
- ํ๋ฆฌํน ๋ด์์ ์๋ฌต์ ์ผ๋ก ๋ฆฌ์์ค ์ค๋ณต ๋ก๋ฉ๋๋ ๋ฌธ์
-
์ ๋ํฐ์ ๋น์ทํ๊ฒ ๋ฆฌ์์ค๋ฅผ ๋ก๋ฉํ๊ณ ๊ด๋ฆฌํ๋๋ฐ ์ค์ ์ ๋๊ณ ์๋ค.
-
Unreal์ ์์ ์ ์ข ๋ฅ
-
Primary Asset
-
AssetManager๊ฐ ์ง์ ์ ์ผ๋ก ๋ก๋ฉ ๊ฐ๋ฅํ ์์
-
๋ํ์ ์ผ๋ก UWorld ์์ ์ด ์์
-
UWorld์ ๊ฐ์ ๋งต์ ๋ํ ์ ๋ณด๋ ์ธ๋ฆฌ์ผ ์์ง ํ๋ก์ ํธ๋ฅผ ์์ฑํ๋ฉด ๋ํดํธ ์ธํ ์ผ๋ก ์์ ๋งค๋์ ๊ฐ ์ฐธ์กฐํ ์ ์๊ฒ ํด์ค๋ค.

-
-
Secondary Asset
- ์์ ๋งค๋์ ๊ฐ ์ง์ ์ ์ผ๋ก ์ฒ๋ฆฌํ๊ณ ๋ก๋ฉํ์ง ๋ชปํ๋ ์์
- ๋๋ถ๋ถ์ ์์ ์ด Seconary Asset์ด๋ค.
-
-
Secondary Asset์ AssetManager๋ก ๋ก๋ฉํ๊ฒ ๋๋ฉด ์ด๋ป๊ฒ ๋ ๊น?
- AssetManager๋ก ๋ก๋๋ ๊ฐ๋ฅํ๋ค.
- LoadObject์ ๊ฐ์ด ์์ด์ ์ฌ์ฉ์ ํ๊ฒ๋๋ฉด ๋ฌธ์ ๊ฐ ์๊ธฐ๋๊ฑฐ ๊ฐ๋ค. LoadObject์ AssetManager๋ฅผ ๊ฐ์ด ์ฌ์ฉํ๊ฒ ๋๋ฉด ๋์ผํ ์์ ์ด ์ฌ๋ฌ ๋ฒ ๋ก๋๋ ์ ์๋ค.
-
Unity์ Addressable๊ณผ์ ์ฐจ์ด์
๊ธฐ๋ฅ AssetManager Addressables (Unity) ํธ๋ค ๊ด๋ฆฌ FStreamableHandle๋ก ์ถ์ ๊ฐ๋ฅ. ํ์๋ ์๋๋ฉฐ ํ์์ ๋ฐ๋ผ ๊ด๋ฆฌ.AsyncOperationHandle์ ๋ช ์์ ์ผ๋ก ๊ด๋ฆฌ. ๋ฉ๋ชจ๋ฆฌ ํด์ ๋ฅผ ์ํด ํธ๋ค ๋ฆด๋ฆฌ์ฆ ํ์.์ค๋ณต ๋ก๋ฉ ๋ฐฉ์ง ์๋์ผ๋ก ์ค๋ณต ๋ก๋ ๋ฐฉ์ง. ๋์ผ ๋ฆฌ์์ค ์์ฒญ ์ ๊ธฐ์กด ํธ๋ค ์ฌ์ฌ์ฉ. ์๋์ผ๋ก ์ค๋ณต ๋ก๋ ๋ฐฉ์ง. ๋์ผ ๋ฆฌ์์ค ์์ฒญ ์ ํธ๋ค ์ฌ์ฌ์ฉ. ๋น๋๊ธฐ ๋ก๋ ๋ฐฉ์ RequestAsyncLoad๋ก ๋น๋๊ธฐ ๋ก๋ ์ํ. ์๋ฃ ์ ์ฝ๋ฐฑ ํธ์ถ.Addressables.LoadAssetAsync๋ก ๋น๋๊ธฐ ๋ก๋ ์ํ. ํธ๋ค ๋ฐํ.๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ GC๋ก ์๋ ๊ด๋ฆฌ. ํ์ง๋ง ์ธ๋ก๋๋ฅผ ๋ช ์์ ์ผ๋ก ํธ์ถํด์ผ ๋ฉ๋ชจ๋ฆฌ ํด์ ๊ฐ๋ฅ. ํธ๋ค ํด์ ๋ฐ ๋ช ์์ Addressables.Releaseํธ์ถ ํ์.
-
๋๊ธฐ ๋ก๋
template<typename AssetType> AssetType* UPTAssetManager::GetAsset(const TSoftObjectPtr<AssetType>& AssetPointer, bool bKeepMemory) { AssetType* LoadedAsset = nullptr; const FSoftObjectPath& AssetPath = AssetPointer.ToSoftObjectPath(); if (AssetPath.IsValid()) { LoadedAsset = AssetPointer.Get(); if (!LoadedAsset) { LoadedAsset = Cast<AssetType>(SynchronusLoadAsset(AssetPath)); //ensureAlwaysMsgf : ์คํ ์ค์งํ์ง ์๊ณ ์ค๋ฅ ๋ณด๊ณ ensureAlwaysMsgf(LoadedAsset, TEXT("Failed to loaded asset [%s]"), *AssetPointer.ToString()); if (LoadedAsset && bKeepMemory) { //์ฌ๊ธฐ์ AddLoadAsset์ ๋ฉ๋ชจ๋ฆฌ์ ์์ฃผํ๊ธฐ ์ํ ์ฅ์น๋ผ๊ณ ์๊ฐํ๋ฉด ๋จ // - ํ๋ฒ ๋ฑ๋ก๋๋ฉด ์ง์ ๋ด๋ฆฌ์ง ์๋ํ Unloaded๊ฐ ๋์ง ์์(์บ์ฑ๋๋ค๋ ์๋ฏธ) Get().AddLoadedAsset(Cast<UObject>(LoadedAsset)); } } } return LoadedAsset; }
-
๋น๋๊ธฐ ๋ก๋
template <typename AssetType> void UPTAssetManager::GetAssetAsync(const TSoftObjectPtr<AssetType>& AssetPointer, TFunction<void(UObject*)> callback, bool bKeepInMemory) { const FSoftObjectPath& AssetPath = AssetPointer.ToSoftObjectPath(); if (AssetPath.IsValid()) { AssetType* LoadedAsset = nullptr; LoadedAsset = AssetPointer.Get(); if (!LoadedAsset) { AsynchronusLoadAsset(AssetPath, [bKeepInMemory, callback](UObject* result) { if (result && bKeepInMemory) Get().AddLoadedAsset(result); callback(result); }); } } }