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); } }
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(); }
/// <summary> /// 删除未使用的AB,可能是上次打包出来的,而这一次没生成的 /// </summary> /// <param name="all"></param> protected void RemoveUnused(List <AssetTarget> all) { HashSet <string> usedSet = new HashSet <string>(); for (int i = 0; i < all.Count; i++) { AssetTarget target = all[i]; if (target.needSelfExport) { usedSet.Add(target.bundleName); } } DirectoryInfo di = new DirectoryInfo(AssetBundleUtil.GetBundleDir()); FileInfo[] abFiles = di.GetFiles("*.ab"); for (int i = 0; i < abFiles.Length; i++) { FileInfo fi = abFiles[i]; if (usedSet.Add(fi.Name)) { XDebug.Log("Remove unused AB : ", fi.Name); fi.Delete(); File.Delete(fi.FullName + ".manifest"); } } }
public void AddRootTargets(FileInfo file) { AssetTarget target = AssetBundleUtil.Load(file); if (target == null) { XDebug.LogError(file); } target.exportType = AssetBundleExportType.Root; }
public AssetTarget(Object o, FileInfo f, string ap) { asset = o; file = f; assetPath = ap; bundleShortName = file.Name.ToLower(); bundleName = XCommon.singleton.XHash(AssetBundleUtil.ConvertToABName(assetPath)) + ".ab"; bundleSavePath = Path.Combine(AssetBundleUtil.GetBundleDir(), bundleName); _isFileChanged = true; _metaHash = "0"; }
public string GetHash() { if (type == AssetType.Builtin) { return("0000000000"); } else { return(AssetBundleUtil.GetFileHash(file.FullName)); } }
public void Analyze() { if (_isAnalyzed) { return; } _isAnalyzed = true; _cacheInfo = AssetBundleUtil.GetCacheInfo(assetPath); _isFileChanged = _cacheInfo == null || !_cacheInfo.fileHash.Equals(GetHash()) || !_cacheInfo.metaHash.Equals(_metaHash); if (_cacheInfo != null) { _bundleCrc = _cacheInfo.bundleCrc; if (_isFileChanged) { XDebug.Log("File was changed : ", assetPath); } } Object[] deps = EditorUtility.CollectDependencies(new Object[] { asset }); var res = from s in deps let path = AssetDatabase.GetAssetPath(s) where !path.StartsWith("Assets/Resources") && !(s is MonoScript) select path; var paths = res.Distinct().ToArray(); for (int i = 0; i < paths.Length; i++) { if (!File.Exists(paths[i]) && !paths[i].Contains("unity_builtin_extra")) { XDebug.Log("invalid:", paths[i]); continue; } FileInfo fi = new FileInfo(paths[i]); AssetTarget target = AssetBundleUtil.Load(fi); if (target == null) { continue; } AddDepend(target); target.Analyze(); } }
public void End() { AssetBundleUtil.SaveCache(); AssetBundleUtil.ClearCache(); EditorUtility.ClearProgressBar(); }
public void Begin() { EditorUtility.DisplayProgressBar("Loading", "Loading...", 0.1f); AssetBundleUtil.Init(); }
void InitDirs() { new DirectoryInfo(AssetBundleUtil.GetBundleDir()).Create(); new FileInfo(AssetBundleUtil.GetCacheFile()).Directory.Create(); }