Version: 5.5
에셋 번들 다운로드(Downloading AssetBundles)
로드된 에셋 번들(AssetBundles) 추적(Track)

에셋 번들에서 오브젝트 로드 및 언로드(Loading and unloading objects from an AssetBundle)

다운로드한 데이터에서 에셋 번들 오브젝트를 만든 후 다음 세 가지 메서드를 사용하여 번들에 포함된 오브젝트를 로드할 수 있습니다.

  • [AssetBundle.LoadAsset](ScriptRef : AssetBundle.LoadAsset.html)를 사용하면 이름 식별자를 파라미터로 사용하여 오브젝트가 로드됩니다. 이 이름은 프로젝트 뷰에 표시되는 이름입니다. 원할 경우 오브젝트 타입을 인수로 로드 메서드에 전달하여 특정 타입의 오브젝트만 로드할 수 있습니다.

  • AssetBundle.LoadAssetAsync는 위에서 설명한 Load 메서드와 똑같이 작동하지만, 에셋 로드 중에 메인 스레드를 차단하지 않습니다. 큰 에셋을 로드하거나 여러 에셋을 동시에 로드할 때 애플리케이션이 일시중지되지 않게 하는 데 유용합니다.

  • AssetBundle.LoadAllAssets를 사용하면 에셋 번들에 포함된 모든 오브젝트가 로드됩니다. AssetBundle.Load와 마찬가지로, 원할 경우 오브젝트를 타입별로 필터링할 수 있습니다.

에셋을 언로드하려면 AssetBundle.Unload를 사용해야 합니다. 이 메서드는 Unity에 모든 데이터(로드된 에셋의 오브젝트를 포함)를 언로드할지 아니면 다운로드된 번들에서 압축된 데이터만 언로드할지 알리는 불린 파라미터를 사용합니다. 애플리케이션에서 에셋 번들의 오브젝트를 몇 개 사용 중인 경우 메모리를 일부 확보하려면 거짓(false)을 전달하여 압축된 데이터를 메모리에서 언로드할 수 있습니다. 에셋 번들에서 모든 것을 완전히 언로드하려면 참(true)을 전달해야 합니다. 그러면 에셋 번들에서 로드된 에셋이 제거됩니다.

에셋 번들에서 비동기식으로 오브젝트 로드(Loading objects from an AssetBundles asynchronously)

AssetBundle.LoadAssetAsync 메서드를 사용하여 오브젝트를 비동기식으로 로드하여 애플리케이션에서 끊김 현상이 발생할 가능성을 줄일 수 있습니다.

using UnityEngine;

// Note: This example does not check for errors. Please look at the example in the DownloadingAssetBundles section for more information
IEnumerator Start () {
    while (!Caching.ready)
        yield return null;
    // Start a download of the given URL
    WWW www = WWW.LoadFromCacheOrDownload (url, 1);

    // Wait for download to complete
    yield return www;

    // Load and retrieve the AssetBundle
    AssetBundle bundle = www.assetBundle;

    // Load the object asynchronously
    AssetBundleRequest request = bundle.LoadAssetAsync ("myObject", typeof(GameObject));

    // Wait for completion
    yield return request;

    // Get the reference to the loaded object
    GameObject obj = request.asset as GameObject;

        // Unload the AssetBundles compressed contents to conserve memory
        bundle.Unload(false);

        // Frees the memory from the web stream
        www.Dispose();
}

에셋 번들 다운로드(Downloading AssetBundles)
로드된 에셋 번들(AssetBundles) 추적(Track)