问题
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