본문 바로가기
Unity

AsyncOperationHandle와 코루틴

by hyoomi 2022. 2. 26.

AsyncOperationHandle implements IEnumerator so it can be yielded in coroutines:

public IEnumerator Start()
{
    AsyncOperationHandle<Texture2D> handle = Addressables.Load<Texture2D>("mytexture");
    yield return handle;
    if (handle.Status == AsyncOperationStatus.Succeeded)
    {
        Texture2D texture = handle.Result;
        // Texture ready for use...

        // Done. Release resource
        Addressables.ReleaseHandle(handle);
    }
}

 

비동기 작업이 끝날때까지 대기했다가 아랫줄부터 실행.(Load 수행 완료 시)

 

[출처] https://docs.unity3d.com/Packages/com.unity.addressables@0.7/manual/AddressableAssetsAsyncOperationHandle.html

댓글