{!See https://docs.google.com/document/d/1takg_GmIBBKKTj-GHZCwzxohpQz7Bhekivkk72kYMtE/edit for reference implementation of OneTrust, dataLayer and GTM} {!OneTrust Cookies Consent} {!OneTrust Cookies Consent end} {!dataLayer initialization push} {!dataLayer initialization push end} {!Google Tag Manager} {!Google Tag Manager end} 에셋 로드 | Addressables | 1.21.17
docs.unity3d.com
"{0}"의 검색 결과

    목차 표시/숨기기

    에셋 로드

    런타임에 하나 이상의 에셋을 로드하기 위해 LoadAssetAsync 또는 LoadAssetsAsync를 사용할 수 있습니다.

    단일 에셋 로드

    LoadAssetAsync 메서드를 사용하여 단일 어드레서블 에셋을 로드할 수 있으며, 일반적으로 주소를 키로 사용합니다.

    
    using System.Collections;
    using UnityEngine;
    using UnityEngine.AddressableAssets;
    using UnityEngine.ResourceManagement.AsyncOperations;
    
    internal class LoadAddress : MonoBehaviour
    {
        public string key;
        AsyncOperationHandle<GameObject> opHandle;
    
        public IEnumerator Start()
        {
            opHandle = Addressables.LoadAssetAsync<GameObject>(key);
            yield return opHandle;
    
            if (opHandle.Status == AsyncOperationStatus.Succeeded)
            {
                GameObject obj = opHandle.Result;
                Instantiate(obj, transform);
            }
        }
    
        void OnDestroy()
        {
            Addressables.Release(opHandle);
        }
    }
    
    

    LoadAssetAsync를 호출할 때 주소뿐만 아니라 레이블이나 다른 키 유형을 사용할 수 있습니다. 그러나 키가 둘 이상의 에셋으로 확인되면 가장 먼저 발견된 에셋만 로드됩니다. 예를 들어, 여러 에셋에 레이블을 적용한 상태에서 이 메서드를 호출하면 어드레서블은 해당 에셋 중 가장 먼저 찾은 에셋을 반환합니다.

    여러 에셋 로드

    한 번의 작업으로 두 개 이상의 어드레서블 에셋을 로드하려면 LoadAssetsAsync 메서드를 사용합니다. 이 메서드를 사용할 때는 레이블과 같은 단일 키 또는 키 목록을 지정할 수 있습니다.

    여러 키를 지정하는 경우 병합 모드를 지정하여 각 키와 일치하는 에셋이 결합되는 방식을 설정할 수 있습니다.

    • Union: 임의의 키와 일치하는 에셋을 포함합니다.
    • Intersection: 모든 키와 일치하는 에셋을 포함합니다.
    • UseFirst: 유효한 위치로 확인되는 첫 번째 키의 에셋만 포함합니다.
    
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.AddressableAssets;
    using UnityEngine.ResourceManagement.AsyncOperations;
    
    internal class LoadMultiple : MonoBehaviour
    {
        // Label strings to load
        public List<string> keys = new List<string>() {"characters", "animals"};
    
        // Operation handle used to load and release assets
        AsyncOperationHandle<IList<GameObject>> loadHandle;
    
        // Load Addressables by Label
        public IEnumerator Start()
        {
            float x = 0, z = 0;
            loadHandle = Addressables.LoadAssetsAsync<GameObject>(
                keys,
                addressable =>
                {
                    //Gets called for every loaded asset
                    Instantiate<GameObject>(addressable,
                        new Vector3(x++ * 2.0f, 0, z * 2.0f),
                        Quaternion.identity,
                        transform);
    
                    if (x > 9)
                    {
                        x = 0;
                        z++;
                    }
                }, Addressables.MergeMode.Union, // How to combine multiple labels 
                false); // Whether to fail and release if any asset fails to load
    
            yield return loadHandle;
        }
    
        private void OnDestroy()
        {
            Addressables.Release(loadHandle);
            // Release all the loaded assets associated with loadHandle
            // Note that if you do not make loaded addressables a child of this object,
            // then you will need to devise another way of releasing the handle when
            // all the individual addressables are destroyed.
        }
    }
    
    

    로딩 오류를 처리하는 방법을 지정하려면 releaseDependenciesOnFailure 파라미터를 사용합니다. true인 경우 단일 에셋을 로드하는 동안 오류가 발생하면 작업이 실패합니다. 작업과 로드된 모든 에셋이 해제됩니다.

    false인 경우 가능한 모든 오브젝트가 로드되며 작업이 해제되지 않습니다. 실패하면 작업은 여전히 Failed 상태로 완료됩니다. 또한 반환되는 에셋 목록에는 실패한 에셋이 표시되는 null 값이 포함됩니다.

    사용할 하나의 세트로 로드해야 하는 에셋 그룹을 로드할 경우 releaseDependenciesOnFailure를 true로 설정합니다. 예를 들어 게임 레벨의 에셋을 로드하는 경우 필요한 에셋 중 일부만 로드하는 것이 아니라 전체적으로 작업이 실패할 수 있습니다.

    문서 개요
    맨 위로
    Copyright © 2023 Unity Technologies — 상표 및 이용약관
    • 법률정보
    • 개인정보처리방침
    • 쿠키
    • 내 개인정보 판매 금지
    • Your Privacy Choices (Cookie Settings)