/// <summary> /// 删除未使用的AB,可能是上次打包出来的,而这一次没生成的 /// </summary> /// <param name="all"></param> protected void RemoveUnused(List <FastAssetTarget> all) { HashSet <string> usedSet = new HashSet <string>(); for (int i = 0; i < all.Count; i++) { FastAssetTarget target = all[i]; if (target.needSelfExport) { usedSet.Add(target.bundleName); } } DirectoryInfo di = new DirectoryInfo(pathResolver.BundleSavePath); FileInfo[] abFiles = di.GetFiles("*" + FastContent.BundleSuffix); for (int i = 0; i < abFiles.Length; i++) { FileInfo fi = abFiles[i]; if (usedSet.Add(fi.Name)) { Debug.Log("Remove unused AB : " + fi.Name); fi.Delete(); //for U5X File.Delete(fi.FullName + ".manifest"); } } }
public static FastAssetTarget Load(FileInfo file, System.Type t) { FastAssetTarget target = null; string fullPath = file.FullName; int index = fullPath.IndexOf("Assets"); if (index != -1) { string assetPath = fullPath.Substring(index); if (_assetPath2target.ContainsKey(assetPath)) { target = _assetPath2target[assetPath]; } else { Object o = null; if (t == null) { o = AssetDatabase.LoadMainAssetAtPath(assetPath); } else { o = AssetDatabase.LoadAssetAtPath(assetPath, t); } if (o != null) { int instanceId = o.GetInstanceID(); if (_object2target.ContainsKey(instanceId)) { target = _object2target[instanceId]; } else { target = new FastAssetTarget(o, file, assetPath); string key = string.Format("{0}/{1}", assetPath, instanceId); _assetPath2target[key] = target; _object2target[instanceId] = target; } } } } return(target); }
public override void Export() { base.Export(); List <AssetBundleBuild> list = new List <AssetBundleBuild>(); //标记所有 asset bundle name var all = FastAssetBundleUtils.GetAll(); for (int i = 0; i < all.Count; i++) { FastAssetTarget target = all[i]; if (target.needSelfExport) { AssetBundleBuild build = new AssetBundleBuild(); build.assetBundleName = target.bundleName; build.assetNames = new string[] { target.assetPath }; list.Add(build); } } //开始打包 BuildPipeline.BuildAssetBundles(pathResolver.BundleSavePath, list.ToArray(), BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); AssetBundle ab = AssetBundle.LoadFromFile(pathResolver.BundleSavePath + pathResolver.BundleName); AssetBundleManifest manifest = ab.LoadAsset("AssetBundleManifest") as AssetBundleManifest; //hash for (int i = 0; i < all.Count; i++) { FastAssetTarget target = all[i]; if (target.needSelfExport) { Hash128 hash = manifest.GetAssetBundleHash(target.bundleName); target.bundleCrc = hash.ToString(); } } ab.Unload(true); this.RemoveUnused(all); AssetDatabase.RemoveUnusedAssetBundleNames(); AssetDatabase.Refresh(); }
public void AddRootTargets(DirectoryInfo bundleDir, string[] partterns = null, SearchOption searchOption = SearchOption.AllDirectories) { if (partterns == null) { partterns = new string[] { "*.*" } } ; for (int i = 0; i < partterns.Length; i++) { FileInfo[] prefabs = bundleDir.GetFiles(partterns[i], searchOption); foreach (FileInfo file in prefabs) { if (file.Extension.Contains("meta")) { continue; } FastAssetTarget target = FastAssetBundleUtils.Load(file); target.exportType = FastAssetBundleExportType.Root; } } }