Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Downloading Asset Bundles in Unity3D

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 1
    Comment on it

    After building the Asset Bundles we have to use them.There are two ways to download an AssetBundle:
    Non-caching: This is done by creating a new WWW object. These AssetBundles are not cached to Unity's Cache folder.
    Caching: This is done by creating the WWW.LoadFromCacheOrDownload call. The AssetBundles are cached to Unity's Cache folder in the local storage device.
    WebPlayer shared cache up to 50 MB of cached AssetBundles.
    PC/Mac Standalone applications and iOS/Android applications shared cache upto 4 GB.
    Example of Non- Catching Download:

    using System;
        using UnityEngine;
        using System.Collections;
        class NonCachingLoadExample : MonoBehaviour
        {
            public string BundleURL;
            public string AssetName;
            IEnumerator Start()
            {
               using (WWW www = new WWW(BundleURL))
               {
                   yield return www;
                   if (www.error != null)
                       throw new Exception("WWW download had an error:" + www.error);
                   AssetBundle bundle = www.assetBundle;
                   if (AssetName == "")
                       Instantiate(bundle.mainAsset);
                   else
                       Instantiate(bundle.Load(AssetName));
                            bundle.Unload(false);
               }
           }
        }


    In most of the cases we use WWW.LoadFromCacheOrDownload to download Asset Bundles so here is an example of Caching:
    using System;
        using UnityEngine;
        using System.Collections;
        public class CachingLoadExample : MonoBehaviour
        {
            public string BundleURL;
            public string AssetName;
            public int version;
            void Start()
            {
                StartCoroutine (DownloadAndCache());
            }
            IEnumerator DownloadAndCache ()
            {
                while (!Caching.ready)
                    yield return null;
                using(WWW www = WWW.LoadFromCacheOrDownload (BundleURL, version)){
                    yield return www;
                    if (www.error != null)
                        throw new Exception("WWW download had an error:" + www.error);
                    AssetBundle bundle = www.assetBundle;
                    if (AssetName == "")
                        Instantiate(bundle.mainAsset);
                    else
                        Instantiate(bundle.Load(AssetName));
                            bundle.Unload(false);
                }
            }
        }

    Use this simple code to download Asset Bundles.

    Blog Asset Bundles Unity3d

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: