如何将Assetbundle下载到IOS/Android的app文件夹中并从中获取所需的模型? [英] How to download an assetbundle into the app folder for IOS/Android and get the required model from it?

查看:295
本文介绍了如何将Assetbundle下载到IOS/Android的app文件夹中并从中获取所需的模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在AssetBundle中,大约有5个模型被命名为厨房",大约3个模型被命名为家具".然后,我使用以下代码将它们创建到本地路径中.

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.

现在我想将文件下载到手持设备文件夹(IOS/Android)中.这是我要实现的.我想将它们动态添加到列表(汉堡模型)中.有一些疑问.我想要一种有效的方法,是否应该将所有assetbundle文件从文件夹结构下载到设备路径? assetbundle,它必须检查并更新捆绑软件.

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.

}

推荐答案

使用新的可寻址功能.它将自动处理下载到适当的位置.

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

这篇关于如何将Assetbundle下载到IOS/Android的app文件夹中并从中获取所需的模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆