[유니티 공식 메뉴얼](https://docs.unity3d.com/Packages/com.unity.addressables@1.19/manual/index.html)
Addressables | Addressables | 1.19.19
Addressables The Addressables system provides tools and scripts to organize and package content for your application and an API to load and release assets at runtime. When you make an asset "Addressable," you can use that asset's address to load it from an
docs.unity3d.com
[유니티 블로그](https://blog.unity.com/kr/games/addressable-asset-system)
어드레서블 에셋 시스템 | Unity Blog
어드레서블의 주된 기능은 로드할 대상이 되는 에셋과 에셋이 로드되는 위치 및 방식을 분리하는 것입니다. 씬, 프리팹, 텍스트 에셋을 비롯한 모든 에셋을 어드레서블(위치 지정 가능)로 표시
blog.unity.com
어드레서블 에셋 시스템을 사용하려면 유니티 패키지 매니저에서 설치를 해야 한다.
설치를 한 뒤 Asset을 보면 어드레서블 토글이 뜬다.
토글을 활성화 하면 해당 에셋의 주소값이 나온다. 수정을 해줄 수도 있다.
밑의 스크립트는 이미지 형식의 오브젝트 주소값을 통해 에셋을 불러오는 기능을 한다. (에셋을 로드함)
/***************LoadWithAddress***************/
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UI;
[RequireComponent(typeof(Image))] // 이미지가 없으면 얘는 못쓴다
internal class LoadWithAddress : MonoBehaviour
{
public string address;
private Image image;
private AsyncOperationHandle<Sprite> handle;
private void Start()
{
image = GetComponent<Image>();
AsyncOperationHandle<Sprite> handle = Addressables.LoadAssetAsync<Sprite>(address);
handle.Completed += Handle_Completed; // 다 끝났을 때 뒤의 함수를 실행 시켜주겠다
}
private void Handle_Completed(AsyncOperationHandle<Sprite> operation)
{
if(operation.Status == AsyncOperationStatus.Succeeded)
{
//Instantiate(reference.Asset, transform);
image.sprite = operation.Result;
image.SetNativeSize();
}
else
{
Debug.LogError($"Asset For {address} failed to load.");
}
}
private void OnDestroy()
{
Addressables.Release(handle);
}
}
'Unity, C#' 카테고리의 다른 글
[Unity C#] OnTrigger와 OnCollision의 차이 (0) | 2023.02.18 |
---|---|
[Unity C#] 코루틴(Coroutine) (0) | 2023.02.14 |
[C#] 암호화, 복호화 (0) | 2022.11.07 |
[Unity C#] 변수와 자료형, 대입 연산자, 조건문, 반복문 (0) | 2022.10.11 |
[22.09.21] Unity 스크립트에서 Scene Popup하기 (0) | 2022.09.21 |