이번 게시글에서는 Addressable Asset을 활용하여 Runtime에 Resource를 다운로드하는 것을 해보겠습니다.
종종 게임들을 보다보면 실제 설치 파일의 용량은 상대적으로 적은데 앱을 실행하다 보면 리소스를 다운로드할지 확인을 하며 다운로드하는 앱을 실행하고 다운로드하는 경우가 있습니다. 오늘은 이것에 대해 알아보겠습니다.
Check Lists
1. 변경된 리소스 파일이 있는지 확인합니다.
2. 변경된 리소스 파일이 있으면 Dependency를 다운로드 합니다.
3. 여기서 Dependency란 무엇일까요?
4. Dependency를 다운로드한 이후에 Addressable.Load 하여 Resource를 사용합니다.
1. 변경된 리소스 파일이 있는지 확인. (GetDownloadSizeAsync)
Method GetDownloadSizeAsync | Addressables | 1.20.5
Method GetDownloadSizeAsync GetDownloadSizeAsync(Object) Determines the required download size, dependencies included, for the specified key. Cached assets require no download and thus their download size will be 0. The Result of the operation is the downl
docs.unity3d.com
public async void DownloadAudioResource()
{
AsyncOperationHandle<long> handle = Addressables.GetDownloadSizeAsync("Assets/AssetStore/AS_Casual_Island_Game_Sounds_FREE/Jingles/Jingle_2.wav");
while (!handle.IsDone)
{
await Task.Yield();
}
if (handle.Result > 0 )
{
Debug.Log($"Download 받을것이 있음.{handle.Result}Bytes");
}
}
대략 1.2MB의 새로운 Resource가 있는 것을 알 수 있습니다.
여기서 동시에 여러 Labels의 Dependency를 다운로드하고 싶을 때는 아래와 같습니다.
MultiLabels GetDownloadSizeAsync, DownloadDependenciesAsync
여기서 Addressables.MergeMode란?
Addressables.MergeMode
Enum Addressables.MergeMode | Package Manager UI website
Enum Addressables.MergeMode Enumerates the supported modes of merging the results of requests. If keys (A, B) mapped to results ([1,2,4],[3,4,5])... UseFirst (or None) takes the results from the first key -- [1,2,4] Union takes results of each key and coll
docs.unity3d.com
Addressable의 DownloadDependenciesAsync를 할 때 다중 Label의 Addressables을 다운로드할 때 다운로드하는 방식에 대한 설정으로 아래와 같은 enum을 가지고 있습니다.
- None : Mode를 지정하지 않다. 이렇게 넣게 되면 다중 Download에서는 error가 나는 것을 확인할 수 있다.
- UseFirst : 가장 첫 번째 Label에 매칭되는 bundle을 다운로드한다. 그 뒤에 매칭되는 bundle은 다운로드하지 않음.
- Union : 각 Label의 매칭되는 bundle 모두를 다운로드한다.
- Intersection : 각 Label or key에 매칭되는 bundle 중 교집합만 다운로드한다.
만약 Key(Label) List = {"Prefab", "Audio" }
None : Error
UseFirst : A, B, C Download
Union : A, B, C, D, E Download
Intersection : C Download
위와 같이 다운로드가 되는 것을 알 수 있습니다.
Dependency Download 구체적으로 무엇인가?
특정 애셋을 로드할 때 해당 애셋이 필요로 하는 다른 애셋들을 함께 다운로드하는 것을 의미합니다.
Prefab Asset을 Instance 하기 위해서는 Prefab 내부의 Material, Texture, Audio 등을 참조하고 있으면, 해당 Prefab을 Load 하기 위해서는 Prefab이 참조하고 있는 다른 에셋도 같이 로드되기 위해 의존성을 다운로드한다고 생각하면 됩니다.
To do List
1. 추가적인 빌드 없이 bundle 파일만 변경된 것을 확인하여 Load가 가능한지 확인.
2. Addressables downlaod Progressbar 만들기
'Unity' 카테고리의 다른 글
Unity Git hub Actions - 1 (개념 정리) (0) | 2025.02.25 |
---|---|
Addressable Asset (6) - Download Progress 처리 (0) | 2025.02.16 |
C# 델리게이트(Delegate) in Unity (0) | 2025.01.29 |
Unity Runtime Memory 관리 - 1 (1) | 2025.01.12 |
Unity Localization (2) (1) | 2025.01.04 |