我是Unity的新手,我开始在我的项目中使用AssetBundle从服务器上下载它们。我使用UnityWebRequestAssetBundle下载资源,因为WWW已经过时了。一切正常,我可以从服务器下载资源,将其放到persistentDataPath中,然后将它们加载到场景中,没有任何问题。但后来我意识到,当模型更新时,可能会有机会,所以我也需要在应用程序中更新它。我知道资产包中的每个资产都有一个清单文件,所以当我下载资产时,我也下载了清单文件。我按照Unity文档做所有的事情,但是我总是得到这个错误:
unable to read header from archive file: /manifest/location清单下载方法如下所示:
IEnumerator GetManifest(string animal)
{
using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle("http://weppage.com/" + asset + ".manifest"))
{
uwr.downloadHandler = new DownloadHandlerFile(path + "/" + asset + ".manifest");
yield return uwr.SendWebRequest();
if ( uwr.isNetworkError || uwr.isHttpError )
{
Debug.Log(uwr.error);
}
}
}然后是下载后的检查方法:
AssetBundle manifestBundle = AssetBundle.LoadFromFile(Path.Combine(path, asset));
AssetBundleManifest manifest = manifestBundle.LoadAsset<AssetBundleManifest>("asset.manifest");我完全迷路了。我通过谷歌搜索,但我不能让它工作。我不明白为什么它不能工作。我以同样的方式加载资产,没有任何问题,Unity文档说它必须以同样的方式工作。来自Unity docs:Loading the manifest itself is done exactly the same as any other Asset from an AssetBundle
发布于 2021-03-05 19:38:48
需要在AssetBundle.LoadFromFile中加载的文件是在存储AssetBundle的同一文件夹中生成的文件。此文件的名称与存储文件夹的名称相同。例如,如果您在名为bundles的文件夹中生成了一个名为maps的AssetBundle,那么将会生成一个包含maps的文件bundles。这样,在AssetBundle.LoadFromFile中,您必须加载文件bundles。在任何情况下,您都必须加载任何.manifest文件。您的代码将如下所示:
IEnumerator GetManifest(string animal)
{
using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle("http://weppage.com/" + asset))
{
uwr.downloadHandler = new DownloadHandlerFile(path + "/" + asset);
yield return uwr.SendWebRequest();
if ( uwr.isNetworkError || uwr.isHttpError )
{
Debug.Log(uwr.error);
}
}
}以及下载后的检查方法:
AssetBundle manifestBundle = AssetBundle.LoadFromFile(Path.Combine(path, "bundles")); //the name of the example file I gave you
AssetBundleManifest manifest = manifestBundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");https://stackoverflow.com/questions/55046568
复制相似问题