无法加载 AssetBundle,因为 "it is not compatible with the newer version of the Unity runtime"
Cannot load AssetBundle because "it is not compatible with the newer version of the Unity runtime"
我正在尝试从文件加载 AssetBundle,但是出现以下错误:
The AssetBundle 'path\to\file' could not be loaded because it is not compatible with this newer version of the Unity runtime. Rebuild the AssetBundle to fix this error.
我构建了我的 AssetBundle,如 Unity wiki 所示:
using UnityEditor;
namespace Editor
{
public class CreateAssetBundles
{
[MenuItem("Assets/Build AssetBundles")]
private static void BuildAllAssetBundles()
{
BuildPipeline.BuildAssetBundles("Assets/AssetBundles",
BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
}
}
}
这会生成一个外观正确的 AssetBundle,清单文件看起来也不错。
我使用以下代码加载 AssetBundle:
var assetBundle = AssetBundle.LoadFromFile(path);
AssetBundle 和游戏都是使用相同版本的 Unity 构建的,版本 2017.3.1f1(64 位)。我也尝试过使用最新的可用测试版来构建两者,但这并没有解决问题。
将 BuildTarget 更改为 BuildTarget.StandaloneWindows64 也无法解决问题。
Unity 文档在 AssetBundles 上有点过时,自 Unity 2017 以来,他们引入了一个全新的 assetbundle 系统,该系统更易于使用,并与改进的 UI 一起工作,称为 AssetBundle Browser
我自己在使用 assetbundle 从 Unity 5.x 切换到 2017.x 时遇到了问题,它实际上要求我使用新的 assetbundle 系统,然后 build/load 通过它到让他们重新工作。
获取Assetbundle浏览器:
- 从 Unity GitHub
下载 AssetBundle 浏览器
- 将下载的文件添加到您的 Unity 项目
- 转到Window
- AssetBundle 浏览器
构建资产包:
在这里您会看到两个选项卡,"configure" 和 "Build"。 Select 通过将对象的预制件拖到配置选项卡中,您想要构建的资产包。你会收到一个问题,询问你是想将其构建为一个大包还是多个单独的包,select 随你喜欢。
如果多个 bundle 共享相同的资源,浏览器也会发出警告,并建议制作一个包含所有共享资源的单独 bundle,这取决于你的 bundle 的数量和大小,这可以节省相当多的 space。
然后,如果您转到 "Build tab",您可以 select 您要构建的平台和输出路径,以及一些其他选项,例如压缩类型。然后您所要做的就是单击 "Build" 来构建与 unity 2017.x
兼容的新资产包
正在加载 Assetbundle:
从文件加载 assetbundle 就像使用以下代码一样简单:AssetBundle myAssetBundle = AssetBundle.LoadFromFile(path);
您还可以从内存中加载资产包(以字节为单位)或直接从流中加载。
新的 AssetBundle 浏览器的另一个好处是您可以根据需要对其进行自定义。所有文件都可以在 /Assets/Editor/AssetBundleBrowser/
中找到。例如,我包含了在构建完成后自动将所有包上传到 FTP 的功能。
编辑:Unity AssetBundle 浏览器工具适用于 5.6 或更高版本。
我正在尝试从文件加载 AssetBundle,但是出现以下错误:
The AssetBundle 'path\to\file' could not be loaded because it is not compatible with this newer version of the Unity runtime. Rebuild the AssetBundle to fix this error.
我构建了我的 AssetBundle,如 Unity wiki 所示:
using UnityEditor;
namespace Editor
{
public class CreateAssetBundles
{
[MenuItem("Assets/Build AssetBundles")]
private static void BuildAllAssetBundles()
{
BuildPipeline.BuildAssetBundles("Assets/AssetBundles",
BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
}
}
}
这会生成一个外观正确的 AssetBundle,清单文件看起来也不错。
我使用以下代码加载 AssetBundle:
var assetBundle = AssetBundle.LoadFromFile(path);
AssetBundle 和游戏都是使用相同版本的 Unity 构建的,版本 2017.3.1f1(64 位)。我也尝试过使用最新的可用测试版来构建两者,但这并没有解决问题。
将 BuildTarget 更改为 BuildTarget.StandaloneWindows64 也无法解决问题。
Unity 文档在 AssetBundles 上有点过时,自 Unity 2017 以来,他们引入了一个全新的 assetbundle 系统,该系统更易于使用,并与改进的 UI 一起工作,称为 AssetBundle Browser
我自己在使用 assetbundle 从 Unity 5.x 切换到 2017.x 时遇到了问题,它实际上要求我使用新的 assetbundle 系统,然后 build/load 通过它到让他们重新工作。
获取Assetbundle浏览器:
- 从 Unity GitHub 下载 AssetBundle 浏览器
- 将下载的文件添加到您的 Unity 项目
- 转到Window
- AssetBundle 浏览器
构建资产包:
在这里您会看到两个选项卡,"configure" 和 "Build"。 Select 通过将对象的预制件拖到配置选项卡中,您想要构建的资产包。你会收到一个问题,询问你是想将其构建为一个大包还是多个单独的包,select 随你喜欢。
如果多个 bundle 共享相同的资源,浏览器也会发出警告,并建议制作一个包含所有共享资源的单独 bundle,这取决于你的 bundle 的数量和大小,这可以节省相当多的 space。
然后,如果您转到 "Build tab",您可以 select 您要构建的平台和输出路径,以及一些其他选项,例如压缩类型。然后您所要做的就是单击 "Build" 来构建与 unity 2017.x
兼容的新资产包正在加载 Assetbundle:
从文件加载 assetbundle 就像使用以下代码一样简单:AssetBundle myAssetBundle = AssetBundle.LoadFromFile(path);
您还可以从内存中加载资产包(以字节为单位)或直接从流中加载。
新的 AssetBundle 浏览器的另一个好处是您可以根据需要对其进行自定义。所有文件都可以在 /Assets/Editor/AssetBundleBrowser/
中找到。例如,我包含了在构建完成后自动将所有包上传到 FTP 的功能。
编辑:Unity AssetBundle 浏览器工具适用于 5.6 或更高版本。