导出AB包首先要确定导出的文件路径,导出的平台。不同的平台:Windows、Mac、Android、iOS等等导出的AB包都是不一样的。
导出的方法体如下:
private static void Export(BuildTarget platform)
{
//项目Assets目录的路径
string path = Application.dataPath;
path = path.Substring(0,Application.dataPath.Length-6) + "ab/two";
//防止路径不存在
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//导出AB包核心代码
//参数1:ab包文件存储路径
//参数2:导出选项
//参数3:平台(不同平台的ab包不一样)
BuildPipeline.BuildAssetBundles(
path,
BuildAssetBundleOptions.ChunkBasedCompression|BuildAssetBundleOptions.ForceRebuildAssetBundle,
platform);
Debug.Log(path);
}
还需要对编辑器扩展,可以在编辑器中“一键导出”:
[MenuItem("AB包导出/Windows")]
public static void ForWindow