Unity AssetBundle 指定AssetLabel打包 AssetBundleBuild

之前介绍了一种打包的方式(这里叫方式一),好像有很久了,之前博客有介绍也看了看,发现了一个问题。

方式一会对整个项目中,所有打了AssetLable的项进行打包,就是说有多少标签就打多少bundle。那么问题来了如果项目过大,一次性打所有的bundle势必会浪费很多时间那问题来了,

有没有什么方式可以只打部分bundle呢,答案是有的:

这里介绍一个类:AssetBundleBuild。先记住它,别管。然后我们看下面这个方法:

BuildPipeline.BuildAssetBundles ();它其中一个重载是这样的(下面一行),另一个在之前的博客中有不说了
BuildPipeline.BuildAssetBundles (string, AssetBundleBuild[], BuildAssetBundleOptions, BuildTarget);

注意这个 AssetBundleBuild 了嘛?嗯,它可以帮助我们实现我们的目标

AssetBundleBuild abBuild = new AssetBundleBuild();

 abBuild.assetBundleName = 目标; // 就是我们要的目标AssetLabel
  // 这个包中的所有资源的名字;
 abBuild.assetNames = getAllFiles(path)

注意这里的assetsNames 需要有 后缀名,且其路径从Asset开始,如:

Assets/Game/BBBB/XXXX/LLLL/HHHH/BXLH.png

路径错了会出警报:No AssetBundle has been set for this build.从而导致打不出包

之前的博客:https://www.cnblogs.com/BXLH/p/10496265.html

猜你喜欢

转载自www.cnblogs.com/BXLH/p/11648852.html