이전 페이지 : https://dean83.tistory.com/208
리소스 관리 - Addressable (5) - Label 및 다중로딩
이전 페이지 : https://dean83.tistory.com/207 리소스 관리 - Addressable (4) - Scene 이전 페이지 : https://dean83.tistory.com/206 리소스 관리 - Addressable (3) - Sprite 이전 페이지 : https://dean83.tistory.com/205 리소스 관리 -
dean83.tistory.com
라벨을 통해 원하는 오브젝트 들을 한번에 가져오는 방법을 알아봤다.
그러나 이 경우 동시에 라벨에 해당하는 모든 리소스를 불러오기 때문에 메모리가 낭비될 수 있다.
해서, 또 다른 방법으로는 리소스의 주소를 리턴받고, 해당 주소중 원하는 항목의 1개 리소스를 불러올 수 있다.
만일 동일 라벨에 있는 아이템중 랜덤으로 1개를 골라야 하는 상황이라면 매우 유용하게 사용할 수 있다.
- Addressable 리소스 중, 해당 라벨에 속하는 리소스 주소들을 리턴
- 해당 주소중 선택된 1개의 주소로 부터 리소스를 로딩
이렇게 하면 라벨에 속하는 모든 리소스를 불러오는 것보다 효율적으로 메모리를 사용할 수 있다.
private AsyncOperationHandle<IList<IResourceLocation>> m_keyHandle;
private AsyncOperationHandle<GameObject> m_selected;
private List<string> m_keys = new List<string>() {"lb1", "lb2", ... };
....
m_keyHandle = Addressables.LoadResourceLocationsAsync(m_keys, Addressables.MergeMode.Union);
m_keyHandle.Completed += OnLocationComplete;
...
void OnLocationComplete(AsyncOperationHandle<IList<IResourceLocation>> obj)
{
IList<IResourceLocation> results = obj.Result;
...
//만일 2번째 항목을 선택 하였다면,
m_selected = Addressables.LoadAssetAsync<GameObject>(results[1]);
m_selected += OnLoadCompleted;
}
...
void OnLoadCompleted(AsyncOperationHandle<GameObject> obj)
{
...
...Instantiate(obj.Result);
}
...
void OnDisable()
{
m_keyHandle.Completed -= OnLocationComplete;
m_selected -= OnLoadCompleted;
}'Unity' 카테고리의 다른 글
| [WebGL] 전체화면 구동 (모바일 포함) (0) | 2024.02.06 |
|---|---|
| 리소스 관리 - Addressable (7) - AssetLabelReference (0) | 2024.02.05 |
| 리소스 관리 - Addressable (5) - Label 및 다중로딩 (0) | 2024.02.02 |
| 리소스 관리 - Addressable (4) - Scene (0) | 2024.02.02 |
| 리소스 관리 - Addressable (3) - Sprite (0) | 2024.02.02 |