{!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}"의 검색 결과

    목차 표시/숨기기

    어드레서블 에셋 사용

    어드레서블 에셋을 로드 및 사용하려면 다음 작업을 수행할 수 있습니다.

    • 에셋을 참조하는 AssetReference 사용
    • 주소 문자열 사용
    • 에셋에 할당된 레이블 사용

    어드레서블 에셋 로드에 대한 자세한 내용은 에셋 로드를 참조하십시오.

    어드레서블 에셋 로드는 비동기 작업을 사용합니다. Unity 스크립트에서 비동기 프로그래밍에 접근하는 다양한 방법은 작업을 참조하십시오.

    [!팁] Addressables Sample 저장소에서 어드레서블 에셋을 사용하는 방법의 예시를 더 많이 찾을 수 있습니다.

    AssetReference 사용

    AssetReference를 사용하려면 AssetReference 필드를 MonoBehaviour 또는 ScriptableObject에 추가합니다. 이러한 유형의 오브젝트를 생성하고 나면 오브젝트의 인스펙터 창에 있는 필드에 에셋을 할당할 수 있습니다.

    [!참고] 비 어드레서블 에셋을 AssetReference 필드에 할당하면 Unity가 자동으로 해당 에셋을 어드레서블로 만들고 기본 어드레서블 그룹에 추가합니다. AssetReference를 사용하면 그 자체로 어드레서블이 아닌 씬에서도 어드레서블 에셋을 사용할 수 있습니다.

    Unity는 참조된 에셋을 자동으로 로드하거나 해제하지 않으며, Addressables API를 사용하여 직접 에셋을 로드 및 해제해야 합니다.

    
    using UnityEngine;
    using UnityEngine.AddressableAssets;
    using UnityEngine.ResourceManagement.AsyncOperations;
    
    internal class LoadWithReference : MonoBehaviour
    {
        // Assign in Editor
        public AssetReference reference;
    
        // Start the load operation on start
        void Start()
        {
            AsyncOperationHandle handle = reference.LoadAssetAsync<GameObject>();
            handle.Completed += Handle_Completed;
        }
    
        // Instantiate the loaded prefab on complete
        private void Handle_Completed(AsyncOperationHandle obj)
        {
            if (obj.Status == AsyncOperationStatus.Succeeded)
            {
                Instantiate(reference.Asset, transform);
            }
            else
            {
                Debug.LogError($"AssetReference {reference.RuntimeKey} failed to load.");
            }
        }
    
        // Release asset when parent object is destroyed
        private void OnDestroy()
        {
            reference.ReleaseAsset();
        }
    }
    
    

    AssetReference 로드에 대한 자세한 내용은 AssetReference 로드를 참조하십시오.

    주소별 로드

    주소 문자열을 사용하여 에셋을 로드할 수 있습니다.

    
    using UnityEngine;
    using UnityEngine.AddressableAssets;
    using UnityEngine.ResourceManagement.AsyncOperations;
    
    internal class LoadWithAddress : MonoBehaviour
    {
        // Assign in Editor or in code
        public string address;
    
        // Retain handle to release asset and operation
        private AsyncOperationHandle<GameObject> handle;
    
        // Start the load operation on start
        void Start()
        {
            handle = Addressables.LoadAssetAsync<GameObject>(address);
            handle.Completed += Handle_Completed;
        }
    
        // Instantiate the loaded prefab on complete
        private void Handle_Completed(AsyncOperationHandle<GameObject> operation)
        {
            if (operation.Status == AsyncOperationStatus.Succeeded)
            {
                Instantiate(operation.Result, transform);
            }
            else
            {
                Debug.LogError($"Asset for {address} failed to load.");
            }
        }
    
        // Release asset when parent object is destroyed
        private void OnDestroy()
        {
            Addressables.Release(handle);
        }
    }
    
    

    에셋을 로드하면 해당 에셋을 해제할 수도 있습니다.

    자세한 내용은 단일 에셋 로드를 참조하십시오.

    레이블별 로드

    하나의 작업에서 동일한 레이블이 지정된 여러 에셋을 로드할 수 있습니다.

    
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.AddressableAssets;
    using UnityEngine.ResourceManagement.AsyncOperations;
    
    internal class LoadWithLabels : 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
        void Start()
        {
            float x = 0, z = 0;
            loadHandle = Addressables.LoadAssetsAsync<GameObject>(
                keys, // Either a single key or a List of keys 
                addressable =>
                {
                    //Gets called for every loaded asset
                    if (addressable != null)
                    {
                        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 if any asset fails to load
            loadHandle.Completed += LoadHandle_Completed;
        }
    
        private void LoadHandle_Completed(AsyncOperationHandle<IList<GameObject>> operation)
        {
            if (operation.Status != AsyncOperationStatus.Succeeded)
                Debug.LogWarning("Some assets did not load.");
        }
    
        private void OnDestroy()
        {
            // Release all the loaded assets associated with loadHandle
            Addressables.Release(loadHandle);
        }
    }
    
    

    자세한 내용은 여러 에셋 로드를 참조하십시오.

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