如何将 assetbundle 下载到 IOS/Android 的 app 文件夹中并从中获取所需的模型?
How to download an assetbundle into the app folder for IOS/Android and get the required model from it?
大约 5 个模型在 AssetBundle 中被命名为 'kitchen',大约 3 个模型被命名为 'furniture'。然后我使用以下代码将它们创建到本地路径中:
[MenuItem("Assets/Build Home Assets")]
static void BuildKitchenAssets()
{
BuildPipeline.BuildAssetBundles("/Users/ar/Desktop/HomeBundles",BuildAssetBundleOptions.ChunkBasedCompression,BuildTarget.iOS);
}
后来,我将这些文件上传到服务器。文件夹结构如下图所示:
现在我要将文件下载到手持设备文件夹 (IOS/Android)。这就是我要实现的:
我想将它们动态添加到列表中(汉堡模型)。有几个疑问。我想要一种有效的方法来做到这一点。我是否应该将所有 assetbundle 文件从文件夹结构下载到设备路径?如果已经下载,请不要再次下载该捆绑包。同时,如果我向 'kitchen' assetbundle 添加了新模型,它必须检查并更新包。
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 the internet at the start and download.Then no need to download again.
// Also check if there is any change in assetbundle.
}
使用新的Addressables feature。它将自动处理下载到适当的位置。
大约 5 个模型在 AssetBundle 中被命名为 'kitchen',大约 3 个模型被命名为 'furniture'。然后我使用以下代码将它们创建到本地路径中:
[MenuItem("Assets/Build Home Assets")]
static void BuildKitchenAssets()
{
BuildPipeline.BuildAssetBundles("/Users/ar/Desktop/HomeBundles",BuildAssetBundleOptions.ChunkBasedCompression,BuildTarget.iOS);
}
后来,我将这些文件上传到服务器。文件夹结构如下图所示:
现在我要将文件下载到手持设备文件夹 (IOS/Android)。这就是我要实现的:
我想将它们动态添加到列表中(汉堡模型)。有几个疑问。我想要一种有效的方法来做到这一点。我是否应该将所有 assetbundle 文件从文件夹结构下载到设备路径?如果已经下载,请不要再次下载该捆绑包。同时,如果我向 'kitchen' assetbundle 添加了新模型,它必须检查并更新包。
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 the internet at the start and download.Then no need to download again.
// Also check if there is any change in assetbundle.
}
使用新的Addressables feature。它将自动处理下载到适当的位置。