unity3d - 从服务器获取 AssetBundle list 文件

标签 unity3d manifest assets assetbundle

我是 Unity 的新手,我开始在我的项目中使用 AssetBundle 从服务器下载它们。我使用 UnityWebRequestAssetBundle 下载资源,因为 WWW 已过时。一切正常,我可以从服务器下载 Assets 并将其放入persistentDataPath,我可以毫无问题地将它们加载到场景中。但后来我意识到模型更新时可能有机会,所以我还需要在应用程序中更新它。我知道 assetbundle 中的每个 Assets 都有一个 list 文件,所以当我下载 Assets 时,我也会下载 list 文件。我按照 Unity 文档执行所有操作,但总是收到此错误:

unable to read header from archive file: /manifest/location

list 下载方法如下所示:
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");

我完全迷路了。我通过谷歌,我无法得到它的工作。我不明白为什么它不起作用。我以相同的方式加载 Assets 没有任何问题,Unity 文档说它必须以相同的方式工作。来自 Unity 文档:Loading the manifest itself is done exactly the same as any other Asset from an AssetBundle

最佳答案

您需要加载的文件 AssetBundle.LoadFromFile是在您存储 AssetBundle 的同一文件夹中生成的文件。该文件与存储文件夹的名称相同。例如,如果您生成了一个名为 maps 的 AssetBundle。在名为 bundles 的文件夹中, 一个文件 bundles将与 maps 一起生成.这样,在 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");

关于unity3d - 从服务器获取 AssetBundle list 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55046568/

相关文章:

nginx - docker pull list 未知 blob 错误

android - 找到重复的com.google.android.gms.location.places.zza类

ruby-on-rails - Rails 3.2.11 Assets 管道 : accented characters in javascript get converted to question marks in production

java - 加载资源 LibGDX HTML (GWT) 的良好实践

unity3d - 捷运 | HoloLens - 获取对象内网格的所有三角形

android - 帐户尚未获得批准 Google AdMob

c# - 如何在运行时更改补间动画的 endValueString?

c# - 有没有办法在 Unity 中进行自动化 UI 测试?

php - SugarCRM 按需将 TextField 转换为 DropDown

c# - 如何使用 XAML 语法在 UWP 类库中引用 Assets