public bool BuildAssetBundles(ABBuildInfo info) { if (info == null) { Debug.Log("Error in build"); return(false); } var manifest = BuildScript.GetManifest(); BuildScript.RemoveUnusedAssetBundleNames(); var assets = manifest.assets; var assetBundleNames = manifest.bundles; var dirs = manifest.dirs; var map = new Dictionary <string, List <string> >(); foreach (var item in manifest.bundles) { map[item] = new List <string>(); } foreach (var item in assets) { var assetPath = dirs[item.dir] + "/" + item.name; map[assetBundleNames[item.bundle]].Add(assetPath); } List <AssetBundleBuild> builds = new List <AssetBundleBuild>(); foreach (var item in map) { builds.Add(new AssetBundleBuild() { assetBundleName = item.Key, assetNames = item.Value.ToArray() }); } var buildManifest = BuildPipeline.BuildAssetBundles(info.outputDirectory, builds.ToArray(), info.options, info.buildTarget); if (buildManifest == null) { Debug.Log("Error in build"); return(false); } foreach (var assetBundleName in buildManifest.GetAllAssetBundles()) { if (info.onBuild != null) { info.onBuild(assetBundleName); } } return(true); }
private void BuildAssetBundleWithBuildMap() { ClearAssetBundleNames(); if (mBuildMap.Count == 0) { return; } SetAssetBundleNames(); if (!Directory.Exists(mAbBuildInfo.outputDirectory)) { Directory.CreateDirectory(mAbBuildInfo.outputDirectory); } Caching.ClearCache(); var buildManifest = BuildPipeline.BuildAssetBundles(mAbBuildInfo.outputDirectory, mAbBuildInfo.options, mAbBuildInfo.buildTarget); if (buildManifest == null) { Debug.Log("Error in build"); return; } if (mAbBuildInfo.isEncrypt) { EncryptAssetBundle(buildManifest); } var assetBundleUpdateInfo = GenerateAssetBundleUpdateInfo(buildManifest); ClearExtensionManifestFile(); if (mAbBuildInfo.mergeOneFile) { if (!Directory.Exists(mAbBuildInfo.GetExtraOutPutDirectory())) { Directory.CreateDirectory(mAbBuildInfo.GetExtraOutPutDirectory()); } MergeAssetBundle(assetBundleUpdateInfo); File.Copy(mAbBuildInfo.outputDirectory + "/" + AssetBundleVersionInfo.FILE_NAME, mAbBuildInfo.GetExtraOutPutDirectory() + "/" + AssetBundleVersionInfo.FILE_NAME); File.Copy(mAbBuildInfo.outputDirectory + "/" + AssetBundleUpdateInfo.FILE_NAME, mAbBuildInfo.GetExtraOutPutDirectory() + "/" + AssetBundleUpdateInfo.FILE_NAME); } foreach (string assetBundleName in buildManifest.GetAllAssetBundles()) { if (mAbBuildInfo.onBuild != null) { mAbBuildInfo.onBuild(assetBundleName); } } }