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

    목차 표시/숨기기

    사전 로드 종속성

    콘텐츠를 원격으로 배포할 때 애플리케이션에 필요한 종속성을 미리 다운로드하여 성능을 개선할 수 있습니다. 예를 들어, 게임을 처음 시작할 때 필수 콘텐츠를 다운로드하여 사용자가 게임플레이 도중 콘텐츠 다운로드를 기다릴 필요가 없도록 할 수 있습니다.

    다운로드 종속성

    Addressables.DownloadDependenciesAsync 메서드를 사용하여 어드레서블 키를 로드하는 데 필요한 모든 종속성을 앱과 함께 설치된 로컬 콘텐츠 또는 다운로드 캐시에서 사용할 수 있도록 하십시오.

    
    string key = "assetKey";
    
    // Check the download size
    AsyncOperationHandle<long> getDownloadSize = Addressables.GetDownloadSizeAsync(key);
    yield return getDownloadSize;
    
    //If the download size is greater than 0, download all the dependencies.
    if (getDownloadSize.Result > 0)
    {
        AsyncOperationHandle downloadDependencies = Addressables.DownloadDependenciesAsync(key);
        yield return downloadDependencies;
    }
    
    

    [!팁] 사전 다운로드하려는 에셋이 있는 경우 preload처럼 동일한 레이블을 에셋에 할당하여 Addressables.DownloadDependenciesAsync를 호출할 때 키로 활용할 수 있습니다. 어드레서블은 아직 사용할 수 없는 경우 해당 레이블이 있는 에셋이 포함된 모든 에셋 번들과 에셋의 종속성이 포함된 모든 번들을 다운로드합니다.

    진행 상황에 대한 업데이트 받기

    AsyncOperationHandle 인스턴스는 진행 상황에 대한 업데이트를 받을 수 있도록 다음과 같은 방법을 제공합니다.

    • AsyncOperationHandle.PercentComplete: 완료된 하위 작업의 백분율을 보고합니다. 예를 들어 특정 작업이 6개의 하위 작업을 사용하여 작업을 수행하는 경우, PercentComplete는 그 중 3개의 작업이 완료되면 전체 작업이 50% 완료되었음을 나타냅니다. 이때 각 작업이 로드하는 데이터의 양은 중요하지 않습니다.
    • AsyncOperationHandle.GetDownloadStatus: 총 다운로드 크기에 대한 백분율을 보고하는 DownloadStatus 구조체를 반환합니다. 예를 들어 특정 작업이 6개의 하위 작업을 사용하지만 첫 번째 작업이 총 다운로드 크기의 50%를 차지하는 경우, GetDownloadStatus는 첫 번째 작업이 완료되면 작업이 50% 완료된 것으로 나타냅니다.

    다음 예시는 GetDownloadStatus를 사용하여 다운로드 중 상태를 확인하고 진행 이벤트를 디스패치하는 방법을 보여 줍니다.

    
    using System.Collections;
    using UnityEngine;
    using UnityEngine.AddressableAssets;
    using UnityEngine.Events;
    using UnityEngine.ResourceManagement.AsyncOperations;
    
    internal class PreloadWithProgress : MonoBehaviour
    {
        public string preloadLabel = "preload";
        public UnityEvent<float> ProgressEvent;
        public UnityEvent<bool> CompletionEvent;
        private AsyncOperationHandle downloadHandle;
    
        IEnumerator Start()
        {
            downloadHandle = Addressables.DownloadDependenciesAsync(preloadLabel, false);
            float progress = 0;
    
            while (downloadHandle.Status == AsyncOperationStatus.None)
            {
                float percentageComplete = downloadHandle.GetDownloadStatus().Percent;
                if (percentageComplete > progress * 1.1) // Report at most every 10% or so
                {
                    progress = percentageComplete; // More accurate %
                    ProgressEvent.Invoke(progress);
                }
    
                yield return null;
            }
    
            CompletionEvent.Invoke(downloadHandle.Status == AsyncOperationStatus.Succeeded);
            Addressables.Release(downloadHandle); //Release the operation handle
        }
    }
    
    

    하나 이상의 에셋을 로드하기 위해 얼마나 많은 데이터를 다운로드해야 하는지 알아보려는 경우 Addressables.GetDownloadSizeAsync를 호출할 수 있습니다.

    
    AsyncOperationHandle<long> getDownloadSize =
        Addressables.GetDownloadSizeAsync(key);
    
    

    완료된 작업의 Result는 다운로드해야 하는 바이트의 수입니다. 어드레서블이 이미 필요한 모든 에셋 번들을 캐시한 경우 Result는 0입니다.

    Result 오브젝트를 읽고 나면 항상 다운로드 작업 핸들을 해제하십시오. 다운로드 작업의 결과에 액세스할 필요가 없는 경우 다음 예시와 같이 autoReleaseHandle 파라미터를 true로 설정하여 핸들을 자동으로 해제할 수 있습니다.

    
    using System.Collections;
    using UnityEngine;
    using UnityEngine.AddressableAssets;
    
    internal class Preload : MonoBehaviour
    {
        public IEnumerator Start()
        {
            yield return Addressables.DownloadDependenciesAsync("preload", true);
        }
    }
    
    

    종속성 캐시 삭제

    어드레서블에 의해 캐시된 에셋 번들을 삭제하려는 경우 Addressables.ClearDependencyCacheAsync를 호출하십시오. 이 메서드는 키로 식별된 에셋과 해당 에셋의 종속성이 포함된 번들을 포함하는 캐시된 에셋 번들을 지웁니다.

    ClearDependencyCacheAsync는 지정된 키와 관련된 에셋 번들만 지웁니다. 콘텐츠 카탈로그를 업데이트하여 키가 더 이상 존재하지 않거나 동일한 에셋 번들에 더 이상 종속되지 않는 경우, 해당 번들은 캐시 설정에 따라 만료될 때까지 캐시에 남아 있습니다.

    에셋 번들을 모두 삭제하려면 UnityEngine.Caching 클래스의 메서드를 사용할 수 있습니다.

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