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.從而導致打不出包

推薦直接使用接口:abBuild.assetNames = AssetDatabase.GetAssetPathsFromAssetBundle(assetLabel);

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM