How to download an assetbundle into the app folder for IOS/Android and get the required model from it?

半世苍凉 提交于 2019-12-13 17:25:31

问题


Around 5 models were given the name 'kitchen' and around 3 models the name 'furniture' in AssetBundle.Then I created them into the local path using the following code.

 [MenuItem("Assets/Build Home Assets")]
static void BuildKitchenAssets()
{
    BuildPipeline.BuildAssetBundles("/Users/ar/Desktop/HomeBundles",BuildAssetBundleOptions.ChunkBasedCompression,BuildTarget.iOS);
}

Later I uploaded these files into a server.The folder structure is given in the image below.

Now I am looking to download the files into the handheld device folder(IOS/Android).This is what I want to implement.I want to dynamically add them into a list(hamburger model).There are a few doubts.I want an efficient way to do this.Should I download all the assetbundle files from the folder structure to the device path?If already downloaded, dont download the bundle again.At the same time if I have added new models to the 'kitchen' assetbundle it has to check and update the bundle.

void Update()
{

}

IEnumerator GetBundles()
{
   using(UnityWebRequest uwr=UnityWebRequestAssetBundle.GetAssetBundle(url,XXXXXXXX,0))
    {
        yield return uwr.SendWebRequest();


        if (uwr.error != null)
        {
            throw new Exception("WWW download error: "+uwr.error);
        }
        AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(uwr);
        if(AssetName==" ")
        {
            Instantiate(bundle.mainAsset);
        }
        else
        {
            //GameObject go=bundle.LoadAsset<GameObject>(AssetName);
            GameObject go = bundle.LoadAsset(AssetName) as GameObject;
            Instantiate(go);
        }


    }



    //How to save them into device folder.For App purpose so need to connect
   //to internet at the start and download.Then no need to download again.
  // Also check if there is any change in assetbundle.

}

回答1:


Use the new Addressables feature. It will handle downloading to the appropriate place automatically.



来源:https://stackoverflow.com/questions/59086302/how-to-download-an-assetbundle-into-the-app-folder-for-ios-android-and-get-the-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!