For me
[Unity] 6) Addressable 본문
설정
Addressable을 사용하기 위해서는 먼저
Window - Pacakage Manager 에서
다음과 같이 사용할 수 있도록 한다
사용 할 시 다음과 같이 에셋 폴더가 만들어짐
사용 방법
1. Addressable을 사용하기 위해서 Prefab, Sound 등 리소스를 포함하는 폴더 @Resources를 만듬
(기존의 Resources 로드 방식을 사용하지 않기 위함)
2. 테스트를 위해 Test라는 빈 Prefab 생성
Addressable을 누르고 AssetManagement - Addressables - Groups를 눌러 생성
3. 자신이 원하는 이름으로 변경
이와같이 설정하면, 경로를 수정하더라도 전혀 영향을 받지 않음
사용 이유
- 에셋 빌드 및 배포 단순화
- 개발 편의성 증가
- 효율적인 에셋 관리 기능
즉, 적은 아트 리소스를 추가할 때 새로운 apk를 만들고 배포하고 검사하는 시간이 걸리는 것을 무시하고,
패치 버전만 바꿔치는 것이 가능
아트 리소스를 나누어 관리하여 바뀐 리소스만 업데이트 할 수 있음
로드
기존방법
다음과 같이 Resoureces 파일을 통해 로드를 진행
로딩을 해야 다음 줄로 넘어가기 때문에, Resource의 크기가 크다면 딜레이 발생
GameObject obj = Resources.Load("TestPrefab");
아트 리소스의 로딩 때문에 끊김 없이 진행하기 위해서는 비동기 로딩이 필요함
비동기란?
코드가 끝날때 까지 코드의 실행을 멈추지 않고 다음 코드를 실행하는 것
https://adrianmejia.com/asynchronous-vs-synchronous-handling-concurrency-in-javascript/
What every programmer should know about Synchronous vs. Asynchronous Code
There are multiple ways of handling concurrency on programming languages. Some languages use various threads, while others use the asynchronous model. We are going to explore the latter in detail and provide examples to distinguish between synchronous vs.
adrianmejia.com
방법
Completed 를 사용하여 로딩이 완료 된다면 람다식 내의 TODO 실행
Release 를 통해 해주어야 메모리 상에서 사라짐 ( C++ Reference Count와 유사 )
using UnityEngine.AddressableAssets;
{
AsyncOperationHandle<GameObject> handle = Addressables.LoadAssetAsync<GameObject>("TestPrefab");
handle.Completed += (op) =>
{
GameObject go = op.Result;
//TODO
Addressable.Release(handle);
}
}
'Unity > 이론' 카테고리의 다른 글
[Unity] 7) Action<T>, Func<T,T> (0) | 2023.03.03 |
---|---|
[Unity] 5) Nullable (0) | 2023.03.01 |
[Unity] 4) Reflection 과 Attribute (0) | 2023.02.28 |
[Unity] 3) Exception (0) | 2023.02.28 |
[Unity] 2) Delegate 와 Event (0) | 2023.02.28 |