Unity
리소스 관리 - Addressable (7) - AssetLabelReference
Dean83
2024. 2. 5. 11:33
이전글 : https://dean83.tistory.com/209
이전글에 Label을 이용한 리소스를 가져오는 법을 살펴봤다.
실제 개발을 해보니 문자열을 넣어야 하는점이 휴먼에러를 불러올 수 있겠단 생각이 들었고, 찾아보니
AssetLabelReference 라는 타입이 있었다.
Addressable 에서 추가된 라벨들을 설정 할 수 있는 타입이다.
스크립트에서 해당 변수를 추가 한 후 Inspector에서 드롭다운으로 라벨을 선택해 주면 된다.
이후, 해당 라벨명을 통해 Addressables.Load시 인자값으로 라벨명을 넣어주면 된다.
[SerializeField]
private AssetLabelReference backgroundLabel;
private AsyncOperationHandle<IList<IResourceLocation>> backgrounds;
....
backgrounds = Addressables.LoadResourceLocationsAsync(backgroundLabel.labelString, typeof(Sprite));
backgrounds.Completed += Backgrounds_Completed;
....