public void Export() { List <AssetBundleBuild> list = new List <AssetBundleBuild>(); //标记所有 asset bundle name var all = AssetBundleUtil.GetAll(); for (int i = 0; i < all.Count; i++) { AssetTarget target = all[i]; if (target.needSelfExport) { AssetBundleBuild build = new AssetBundleBuild(); build.assetBundleName = target.bundleName; build.assetNames = new string[] { target.assetPath }; list.Add(build); } } string bundleSavePath = AssetBundleUtil.GetBundleDir(); //开始打包 BuildPipeline.BuildAssetBundles(bundleSavePath, list.ToArray(), BuildAssetBundleOptions.UncompressedAssetBundle, EditorUserBuildSettings.activeBuildTarget); AssetBundle ab = AssetBundle.LoadFromFile(bundleSavePath + "/AssetBundles"); AssetBundleManifest manifest = ab.LoadAsset("AssetBundleManifest") as AssetBundleManifest; //hash for (int i = 0; i < all.Count; i++) { AssetTarget target = all[i]; if (target.needSelfExport) { Hash128 hash = manifest.GetAssetBundleHash(target.bundleName); if (target.bundleCrc != hash.ToString()) { if (AssetBundleBuildPanel.ABUpdateOpen) { string savePath = Path.Combine(Path.GetTempPath(), target.bundleName); string downloadPath = Path.Combine(Path.Combine(AssetBundleBuildPanel.TargetFolder, "AssetBundles"), target.bundleName); File.Copy(savePath, downloadPath, true); XMetaResPackage pack = new XMetaResPackage(); pack.buildinpath = target.bundleShortName; pack.download = string.Format("AssetBundles/{0}", target.bundleName); pack.Size = (uint)(new FileInfo(downloadPath)).Length; if (pack.Size != (new FileInfo(downloadPath)).Length) { EditorUtility.DisplayDialog("Bundle ", target.bundleShortName + " is lager than UINTMAX!!!", "OK"); } AssetBundleBuildPanel.assetBundleUpdate.Add(pack); File.Copy(savePath, bundleSavePath, true); } } target.bundleCrc = hash.ToString(); } } SaveDepAll(all); ab.Unload(true); RemoveUnused(all); AssetDatabase.RemoveUnusedAssetBundleNames(); AssetDatabase.Refresh(); }
public void Analyze() { var all = AssetBundleUtil.GetAll(); int total = all.Count; int count = 0; foreach (AssetTarget target in all) { target.Analyze(); EditorUtility.DisplayProgressBar(string.Format("Analyze...({0}/{1})", count, total), target.assetPath, ++count / total); } all = AssetBundleUtil.GetAll(); total = all.Count; count = 0; foreach (AssetTarget target in all) { target.Merge(); EditorUtility.DisplayProgressBar(string.Format("Merge...({0}/{1})", count, total), target.assetPath, ++count / total); } all = AssetBundleUtil.GetAll(); total = all.Count; count = 0; foreach (AssetTarget target in all) { target.BeforeExport(); EditorUtility.DisplayProgressBar(string.Format("BeforeExport...({0}/{1})", count, total), target.assetPath, ++count / total); } }