/// <summary> /// 第一次运行时,将资源列表和资源包全部导出 /// </summary> /// <param name="UpdateReoures">更新资源的委托</param> /// <returns></returns> IEnumerator ExportFileReources(Action UpdateReoures = null) { string filePath = BuildPath.FileStreamFolder + filelist; //内部路径 string[] bundleList = null; //资源列表的资源信息 AssetBundleManifest manifest = null; //下载资源列表到外部路径 using (WWW wwwManifest = new WWW(filePath)) { yield return(wwwManifest); if (!string.IsNullOrEmpty(wwwManifest.error)) { Debug.Log("获取AssetBundleManifest出错!"); } else { AssetBundle manifestBundle = wwwManifest.assetBundle; manifest = manifestBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); //获取总的Manifest string outPath = BuildPath.ResourceFolder + filelist; //外部路径 SaveBytes(outPath, wwwManifest.bytes); //保存总的Manifest到外部路径 bundleList = manifest.GetAllAssetBundles(); //获取所有的资源信息 manifestBundle.Unload(false); //释放掉 } } if (bundleList == null) { yield return(null); } else { if (manifest != null) { for (int i = 0; i < bundleList.Length; i++) { Debug.Log("sss"); yield return(DownloadResource(bundleList[i], manifest.GetAssetBundleHash(bundleList[i]))); //等待返回下载结果 } } } yield return(new WaitForSeconds(1f)); //资源全部导出后等待1s if (UpdateReoures != null) { UpdateReoures.Invoke(); } }
/// <summary> /// 导出两个版本的差异包 /// zip格式差异包将放在新版本目录下 /// </summary> /// <param name="oldVer">旧版本.</param> /// <param name="newVer">新版本.</param> private void genVersionPatch() { string oldManifestPath = m_absolutePath + "/" + m_oldVersion + "/" + m_selectedTarget + "/" + m_selectedTarget; string newManifestPath = m_absolutePath + "/" + m_newVersion + "/" + m_selectedTarget + "/" + m_selectedTarget; string[] oldBundleList = new string[0]; string[] newBundleList = new string[0]; AssetBundleManifest oldManifest = null; AssetBundleManifest newManifest = null; if (File.Exists(oldManifestPath)) { AssetBundle oldBundle = AssetBundle.LoadFromFile(oldManifestPath); oldManifest = oldBundle.LoadAsset <AssetBundleManifest> ("AssetBundleManifest"); oldBundle.Unload(false); // 同时加载两个MainBundle会报错,所以需要先unload oldBundleList = oldManifest.GetAllAssetBundles(); } if (File.Exists(newManifestPath)) { AssetBundle newBundle = AssetBundle.LoadFromFile(newManifestPath); newManifest = newBundle.LoadAsset <AssetBundleManifest> ("AssetBundleManifest"); newBundle.Unload(false); // 同时加载两个MainBundle会报错,所以需要先unload newBundleList = newManifest.GetAllAssetBundles(); } // 得到当前版本新增的包列表 List <string> patchFiles = new List <string> (newBundleList.Except(oldBundleList)); foreach (var bundleName in oldBundleList) { var oldHash = oldManifest.GetAssetBundleHash(bundleName); var newHash = newManifest.GetAssetBundleHash(bundleName); if (oldHash != newHash) { patchFiles.Add(bundleName); } } patchFiles.Add(newManifestPath); // manifest必须更新 string zipPath = m_absolutePath + "/" + m_selectedTarget + "_patch_" + m_oldVersion + "_" + m_newVersion + ".zip"; string fileRoot = m_absolutePath + "/" + m_newVersion + "/" + m_selectedTarget; FZipHelper.Zip(zipPath, fileRoot, patchFiles); UnityEngine.Debug.Log("导出 " + m_newVersion + " 版本与 " + m_oldVersion + " 版本的差异包成功"); }
/// <summary> /// 查看AssetBundleManifest的AssetBundle列表 /// </summary> void LookAssetBundleManifest_AssetBundleList() { AssetBundle assetBundleMain = AssetBundle.LoadFromFile(assetbundleMain); AssetBundleManifest assetBundleManifest = assetBundleMain.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); string[] assetBundles = assetBundleManifest.GetAllAssetBundles(); assetBundleMain.Unload(true); string path = "../Logs/AssetBundleManifest的AssetBundle列表.txt"; CheckPath(path); File.WriteAllText(path, String.Join("\n", assetBundles)); Shell.RevealInFinder(path); }
private void ParseManifestFile(AssetBundleManifest abm_, Dictionary <string, Hash128> dict_) { if (abm_ == null) { return; } string[] abList = abm_.GetAllAssetBundles(); foreach (string abName in abList) { //Utility.Log("Parse version file add ab: " + abName + " , hashcode:" + abm_.GetAssetBundleHash(abName)); dict_.Add(abName, abm_.GetAssetBundleHash(abName)); } }
/// <summary> /// 需要更新的资源 /// </summary> public void Diff() { foreach (var r in mRemoteManifest.GetAllAssetBundles()) { var cachePath = AssetSys.CacheRoot + r; var rh = mRemoteManifest.GetAssetBundleHash(r); var l = mLocalManifest.Find(i => i.Name == r); if (!File.Exists(cachePath) || l == null || l.Hash != rh.ToString()) { AppLog.d(Tag, "diff: {0}:[{1} {2}]", r, rh, (l != null ? l.Hash : "")); mDiffList.Add(r); } } }
/// <summary> /// 第一次运行时,将资源列表和资源包全部导出 /// </summary> /// <param name="UpdateReoures">更新资源的委托</param> /// <returns></returns> IEnumerator ExportFileReources(Action UpdateReoures = null) { string filePath = BuildPath._Instance.FileStreamFolder + filelist; //内部路径 string[] bundleList = null; //资源列表的资源信息 //下载资源列表到外部路径 using (WWW wwwManifest = new WWW(filePath)) { yield return(wwwManifest); if (!string.IsNullOrEmpty(wwwManifest.error)) { Debug.Log("获取AssetBundleManifest出错!"); } else { AssetBundle manifestBundle = wwwManifest.assetBundle; AssetBundleManifest manifest = manifestBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); //获取总的Manifest string outPath = BuildPath._Instance.ResourceFolder + filelist; //外部路径 SaveBytes(outPath, wwwManifest.bytes); //保存总的Manifest到外部路径 bundleList = manifest.GetAllAssetBundles(); //获取所有的资源信息 manifestBundle.Unload(false); //释放掉 } } if (bundleList == null) { yield return(null); } else { for (int i = 0; i < bundleList.Length; i++) { yield return(StartCoroutine(DownloadResource(bundleList[i]))); //等待返回下载结果 ShowMessage.text = "第一次运行,解压资源..." + (int)((float)i * 100 / bundleList.Length) + "%" + '\n' + "解压不耗费流量"; } ShowMessage.text = "解压完成,等待初始化..."; yield return(new WaitForSeconds(1f)); //资源全部导出后等待1s if (UpdateReoures != null) { UpdateReoures.Invoke(); } } }
/// <summary> /// 获取需要更新的文件 /// </summary> /// <returns></returns> private List <string> GetUpdateFileName() { if (oldManifest == null) { if (newManifest != null) { return(new List <string>(newManifest.GetAllAssetBundles())); } else { return(new List <string>()); } } List <string> updateFileNames = new List <string>(); int newHashCode = newManifest.GetHashCode(); int oldHashCode = oldManifest.GetHashCode(); if (newHashCode == oldHashCode) { updateFileNames = new List <string>(); } else { string[] newAssets = newManifest.GetAllAssetBundles(); string[] oldAssets = oldManifest.GetAllAssetBundles(); Dictionary <string, Hash128> oldHashs = new Dictionary <string, Hash128>(); foreach (string name in oldAssets) { oldHashs.Add(name, oldManifest.GetAssetBundleHash(name)); } foreach (string name in newAssets) { if (oldHashs.ContainsKey(name)) { Hash128 newHash = newManifest.GetAssetBundleHash(name); if (newHash != oldHashs[name]) { updateFileNames.Add(name); } } else { updateFileNames.Add(name); } } } return(updateFileNames); }
//移除无用资源. 比如删除未使用的AB,可能是上次打包出来的,而这一次没生成的 protected void RemoveUnused(AssetBundleManifest manifest) { HashSet <string> needfiles = new HashSet <string>(); string[] abs = manifest.GetAllAssetBundles(); foreach (var ab in abs) { needfiles.Add(ab); needfiles.Add(ab + ".manifest"); } //主文件与目录同名 needfiles.Add(pathResolver.BundleSaveDirName); needfiles.Add(pathResolver.BundleSaveDirName + ".manifest"); // needfiles.Add(pathResolver.AssetBundleFileList); // DirectoryInfo rootdi = new DirectoryInfo(pathResolver.BundleSavePath); int rootpathLength = rootdi.FullName.Length + 1; FileInfo[] allfile = rootdi.GetFiles("*", SearchOption.AllDirectories); foreach (FileInfo fi in allfile) { //不移除目录的meta if (fi.FullName.EndsWith(".meta") && Directory.Exists(fi.FullName.Substring(0, fi.FullName.Length - 5))) { continue; } string fn = fi.FullName.Replace('\\', '/').Substring(rootpathLength); string ffn = fn; if (fn.EndsWith(".meta")) { ffn = fn.Substring(0, fn.Length - ".meta".Length); } if (!needfiles.Contains(ffn)) { Debug.Log("Delete unused file: " + fn); fi.Delete(); } } //删除空目录 AssetBundleUtils.KillEmptyDirectoryWithMeta(pathResolver.BundleSavePath); }
public static uint CreateStreamingFileManifest(AssetBundleManifest assetBundleManifest) { var allABs = assetBundleManifest.GetAllAssetBundles(); var bundlesWithVariant = assetBundleManifest.GetAllAssetBundlesWithVariant(); var streamingManifest = ScriptableObject.CreateInstance(typeof(FileManifest)) as FileManifest; //读取 bundlesWithVariant var MyVariant = new string[bundlesWithVariant.Length]; for (int i = 0; i < bundlesWithVariant.Length; i++) { var curSplit = bundlesWithVariant[i].Split('.'); MyVariant[i] = bundlesWithVariant[i]; } //读取abinfo List <ABInfo> allABInfos = new List <ABInfo>(); foreach (var abs in allABs) { var abInfo = new ABInfo(abs, 0, 0, 0); var dependencies = assetBundleManifest.GetAllDependencies(abs); abInfo.dependencies = dependencies; allABInfos.Add(abInfo); } //fill data streamingManifest.allAbInfo = allABInfos; streamingManifest.allAssetBundlesWithVariant = bundlesWithVariant; streamingManifest.appNumVersion = CodeVersion.APP_NUMBER; streamingManifest.newAppNumVersion = CodeVersion.APP_NUMBER; streamingManifest.version = CodeVersion.APP_VERSION; //create asset string tmpPath = EditorUtils.GetAssetTmpPath();// Path.Combine(Application.dataPath, BuildScript.TmpPath); EditorUtils.CheckDirectory(tmpPath); var crc32filename = CUtils.GetAssetName(Common.CRC32_FILELIST_NAME); string assetPath = "Assets/" + EditorUtils.TmpPath + crc32filename + ".asset"; AssetDatabase.CreateAsset(streamingManifest, assetPath); //build assetbundle string crc32outfilename = CUtils.GetRightFileName(Common.CRC32_FILELIST_NAME); BuildScript.BuildABs(new string[] { assetPath }, null, crc32outfilename, DefaultBuildAssetBundleOptions); streamingManifest.WriteToFile("Assets/" + EditorUtils.TmpPath + "BuildStreamingAssetsManifest.txt"); Debug.LogFormat("FileManifest Path = {0}/{1};", CUtils.realStreamingAssetsPath, crc32outfilename); return(0); }
public static void InstateObj() { AssetBundle assetBundle = AssetBundle.LoadFromFile(Application.dataPath + "/StreamingAssets/StreamingAssets"); AssetBundleManifest assetBundleManifest = assetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); Debug.LogError(assetBundle); Debug.LogWarning(assetBundleManifest); string[] bundles = assetBundleManifest.GetAllAssetBundles(); for (int i = 0; i < bundles.Length; i++) { Debug.Log(bundles[i]); // AssetBundle elem = elmebundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest"); } }
// Load AssetBundleManifest. public void Initialize(string manifestName, Action initOK) { m_BaseDownloadingURL = Util.GetRelativePath(); LoadAsset <AssetBundleManifest>(manifestName, new string[] { "AssetBundleManifest" }, delegate(UObject[] objs) { if (objs.Length > 0) { m_AssetBundleManifest = objs[0] as AssetBundleManifest; m_AllManifest = m_AssetBundleManifest.GetAllAssetBundles(); } if (initOK != null) { initOK(); } }); }
/// <summary> /// 获取Manifest的依赖文件 /// </summary> private void Manifest() { AssetBundle manifesAB = AssetBundle.LoadFromFile(Application.dataPath + "/AssetBundle/AssetBundle"); AssetBundleManifest manifest = manifesAB.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); string[] l = manifest.GetAllAssetBundles(); foreach (var item in l) { string[] depends = manifest.GetAllDependencies(item); foreach (var a in depends) { Debug.Log(a); } } }
public static bool CircleCheck(AssetBundleManifest manifest) { Dictionary <string, bool> resultMap = new Dictionary <string, bool>(); List <string> currentLine = new List <string>(); string[] assetNames = manifest.GetAllAssetBundles(); foreach (string name in assetNames) { if (!CircleCheckDFS(name, currentLine, resultMap, manifest)) { return(false); } } return(true); }
public static void CheckCircularReference() { string path = Application.streamingAssetsPath + "/" + "AssetBundles" + "/" + "AssetBundles"; AssetBundle bundle = AssetBundle.LoadFromFile(path); AssetBundleManifest manifest = (AssetBundleManifest)bundle.LoadAsset("AssetBundleManifest"); string[] names = manifest.GetAllAssetBundles(); foreach (var item in names) { CircularReferenceSet set = new CircularReferenceSet(); set.name = item; m_CheckCircularReference(set, manifest); } bundle.Unload(true); }
public Dictionary <string, Hash128> LoadABManifest(string path) { AssetBundle assetBundle = AssetBundle.LoadFromFile(path); AssetBundleManifest manifest = assetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); string[] bundlesName = manifest.GetAllAssetBundles(); Dictionary <string, Hash128> bundlesHash = new Dictionary <string, Hash128>(); for (int i = 0; i < bundlesName.Length; i++) { Hash128 hash = manifest.GetAssetBundleHash(bundlesName[i]); bundlesHash.Add(bundlesName[i], hash); } return(bundlesHash); }
public void LoadFromAssetbundle(AssetBundle assetbundle) { if (assetbundle == null) { Logger.LogError("Manifest LoadFromAssetbundle assetbundle null!"); return; } manifest = assetbundle.LoadAsset <AssetBundleManifest>(assetName); string[] allAssetBundles = manifest.GetAllAssetBundles(); foreach (var assetBundle in allAssetBundles) { assetBundlesNames.Add(assetBundle, true); } }
private void LoadBundles() { string[] bundles = manifest.GetAllAssetBundles(); foreach (string bundle in bundles) { //me fijo si son assetbundles, si lo son los agrego al diccionario AssetBundle assetbundle = AssetBundle.LoadFromFile(Path.Combine(Reg.assetBundleDataPath, bundle)); if (assetbundle != null) { assetBundles.Add(new FileName(bundle), assetbundle); } } }
//下载并读取Manifest文件 IEnumerator LoadManifest() { WWW www = new WWW(address + manifestAssetBundleName); yield return(www); Debug.Log(www.assetBundle.LoadAllAssets()[0].name); manifest = www.assetBundle.LoadAsset("AssetBundleManifest") as AssetBundleManifest; string[] abs = manifest.GetAllAssetBundles(); foreach (string s in abs) { Debug.Log(s); } www.Dispose(); }
/// <summary></summary> public IEnumerator GetBundlesInfo() { if (Manifest == null) { yield break; } string[] arrBundles = Manifest.GetAllAssetBundles(); for (int i = 0; i < arrBundles.Length; i++) { dicBundlesInfo.Add(arrBundles[i], Manifest.GetAssetBundleHash(arrBundles[i]).ToString()); } yield return(null); }
public static void ExportAssetBundles() { BuildAssetBundleOptions options = BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.DeterministicAssetBundle; // BuildPipeline.BuildAssetBundles(Application.streamingAssetsPath + "/", options, EditorUserBuildSettings.activeBuildTarget); AssetBundleManifest assetBundleManifest = BuildPipeline.BuildAssetBundles(bundlePath, options, BuildTarget.Android); Debug.Log("********************************Build asset bundles finished"); if (assetBundleManifest.GetAllAssetBundles() != null) { CSVWriter csvWriter = new CSVWriter(resourccePath + "/needNotPackage/assetBundlesInfo.csv"); foreach (string asset in assetBundleManifest.GetAllAssetBundles()) { //Debug.Log(asset + " "); foreach (string d in assetBundleManifest.GetAllDependencies(asset)) { //Debug.Log(" " + d); } string[] strs = { asset, assetBundleManifest.GetAssetBundleHash(asset).ToString() }; csvWriter.writeNext(strs); } csvWriter.close(); } }
private void GenerateUnhashToHashMap(AssetBundleManifest manifest) { unhashedToHashedBundleNameMap.Clear(); var allBundles = manifest.GetAllAssetBundles(); for (int i = 0; i < allBundles.Length; i++) { var indexOfHashSplit = allBundles[i].LastIndexOf('_'); if (indexOfHashSplit < 0) { continue; } unhashedToHashedBundleNameMap[allBundles[i].Substring(0, indexOfHashSplit)] = allBundles[i]; } }
public void Initialize(string manifestName, Action callback) { LoadAsset(manifestName, new string[] { "AssetBundleManifest" }, typeof(AssetBundleManifest), delegate(Object[] objs) { if (objs.Length > 0) { m_assetBundleManifest = objs[0] as AssetBundleManifest; m_allManifest = m_assetBundleManifest.GetAllAssetBundles(); } if (callback != null) { callback(); } }); }
public static void DisposeFiles(string folder) { List <string> old_abs = EditorCommon.GetAllFiles(folder, "*.ab"); List <string> abs = EditorCommon.GetAllFiles(folder, "*" + ResourceConst.BundleExtensions); if (abs == null || abs.Count < 1) { return; } foreach (string old_ab in old_abs) { if (!abs.Contains(old_ab)) { abs.Add(old_ab); } } string fielName = Path.GetFileNameWithoutExtension(folder); string path = string.Format("{0}/{1}", folder, fielName); AssetBundleManifest abm = GetAssetBundleManifest(path); if (abm == null) { return; } string[] files = abm.GetAllAssetBundles(); foreach (string file in files) { string bundlePath = string.Format("{0}/{1}", folder, file); if (abs.Contains(bundlePath)) { abs.Remove(bundlePath); } } for (int i = 0; i < abs.Count; i++) { string ab = abs[i]; System.IO.File.Delete(ab); System.IO.File.Delete(string.Format("{0}.manifest", ab)); ShowProgress(i, abs.Count, "删除无用文件:", ab); } EditorUtility.ClearProgressBar(); }
//获取需要下载的文件列表 private List <string> getDownloadFileName() { if (curManifest == null) { if (onlineManifest == null) { return(new List <string>()); } else { return(new List <string>(onlineManifest.GetAllAssetBundles())); } } List <string> tempList = new List <string>(); var curHashCode = curManifest.GetHashCode(); var onlineHashCode = onlineManifest.GetHashCode(); if (curHashCode != onlineHashCode) { // 比对筛选 var curABList = curManifest.GetAllAssetBundles(); var onlineABList = onlineManifest.GetAllAssetBundles(); Dictionary <string, Hash128> curABHashDic = new Dictionary <string, Hash128>(); foreach (var iter in curABList) { curABHashDic.Add(iter, curManifest.GetAssetBundleHash(iter)); } foreach (var iter in onlineABList) { if (curABHashDic.ContainsKey(iter)) //本地有该文件 但与服务器不同 { Hash128 onlineHash = onlineManifest.GetAssetBundleHash(iter); if (onlineHash != curABHashDic[iter]) { tempList.Add(iter); } } else { tempList.Add(iter); } } } return(tempList); }
IEnumerator LoadXml() { //callback action 有些问题,这里相当于过早回调,导致下一次加载启动了,然后又执行了go.destroy把第二次加载的www干掉了,导致加载停止 www = new WWW(XmlPath); yield return(www); Debug.LogError("www返回:" + XmlPath); if (null != www.error) { Debug.Log("加载xmlBundle www error:" + www.error); } string[] names = www.assetBundle.GetAllAssetNames(); //for (int i = 0; i < names.Length; i++) //{ // Debug.Log("---[" + i + "]------>" + names[i]); //} Dictionary <string, string> tempDic = new Dictionary <string, string>(); AssetBundleManifest xml = (AssetBundleManifest)www.assetBundle.LoadAsset("assetbundlemanifest");//这个名称永远固定,无论bundle名是什么,asset名都是这个 string[] bundleNames = xml.GetAllAssetBundles(); for (int i = 0; i < bundleNames.Length; i++) { string hash = xml.GetAssetBundleHash(bundleNames[i]).ToString(); string path = RelePath + "/" + bundleNames[i]; //Debug.LogError("---i:" + i + " relepath:" + path + " hash:" + hash); tempDic.Add(path, hash); } //ninfo 编辑器下用完不关下回就不能二次载入 www.assetBundle.Unload(true); www.Dispose(); www = null; DestroyImmediate(go); go = null; ProcessXmlAction(tempDic); }
/// <summary> /// 不管怎么说,先加载Mainfest总不会错的 /// </summary> public void LoadMainfest() { ///PC暂定为Android /// MacOS为iOS string subPath = ""; #if UNITY_EDITOR_OSX || UNITY_IPHONE subPath = "/iOS"; #elif UNITY_EDITOR_WIN || UNITY_ANDROID subPath = "/Android"; #endif string path = AssetBundlePathConfig.Instance.Path + subPath; _dependsDataList.Clear(); AssetBundle ab = AssetBundle.LoadFromFile(path); if (ab == null) { Debug.LogError("LoadMainfest ab NULL error !"); } else { AssetBundleManifest mainfest = ab.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); if (mainfest == null) { Debug.LogError("LoadMainfest NULL error !"); } else { foreach (var assetName in mainfest.GetAllAssetBundles()) { //DebugTool.Log(assetName); string hashName = assetName.Replace(".cao", ""); string[] dps = mainfest.GetAllDependencies(assetName); for (int i = 0; i < dps.Length; i++) { dps[i] = dps[i].Replace(".cao", ""); } _dependsDataList.Add(hashName, dps); } ab.Unload(true); ab = null; Debug.Log("AssetBundleLoadMgr dependsCount=" + _dependsDataList.Count); bLoadMainfest = true; } } }
public static void BuildAssetBundles() { // Choose the output path according to the build target. string outputPath = Path.Combine(Utility.AssetBundlesOutputPath, Utility.GetPlatformName()); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } //@TODO: use append hash... (Make sure pipeline works correctly with it.) try { foreach (string f in Directory.EnumerateFiles(outputPath, "*.manifest")) { File.Delete(f); } foreach (string f in Directory.EnumerateFiles(outputPath, "*.engagebundle")) { File.Delete(f); } } catch { } AssetBundleManifest mani = BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); ///UPDATE CHANGED ENGAGE 1.0.3 (JAN 20, 2019) - USE ASSETBUNDLES DIRECTLY, NO EXTRA COMPRESSION ROUTINE foreach (string bund in mani.GetAllAssetBundles()) { Debug.Log("Saving " + bund); try { if (File.Exists(Path.Combine(outputPath, bund + ".engagebundle"))) { File.Delete(Path.Combine(outputPath, bund + ".engagebundle")); } File.Move(Path.Combine(outputPath, bund), Path.Combine(outputPath, bund + ".engagebundle")); Debug.Log("Saved " + bund + " successfully"); } catch (System.Exception e) { Debug.Log("Problem compressing bundle " + e); } } }
/// <summary> /// 获取资源包列表 /// </summary> private List <PatchBundle> GetAllPatchBundle(AssetBundleBuilder.BuildParametersContext buildParameters, TaskGetBuildMap.BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext, AssetBundleManifest unityManifest) { List <PatchBundle> result = new List <PatchBundle>(); // 加载DLC DLCManager dlcManager = new DLCManager(); dlcManager.LoadAllDLC(); // 加载旧补丁清单 PatchManifest oldPatchManifest = AssetBundleBuilder.LoadPatchManifestFile(buildParameters); // 获取加密列表 List <string> encryptList = encryptionContext.EncryptList; string[] allAssetBundles = unityManifest.GetAllAssetBundles(); foreach (var bundleName in allAssetBundles) { string path = $"{buildParameters.OutputDirectory}/{bundleName}"; string hash = HashUtility.FileMD5(path); string crc = HashUtility.FileCRC32(path); long size = FileUtility.GetFileSize(path); int version = buildParameters.BuildVersion; string[] assets = buildMapContext.GetCollectAssetPaths(bundleName); string[] depends = unityManifest.GetDirectDependencies(bundleName); string[] dlcLabels = dlcManager.GetAssetBundleDLCLabels(bundleName); // 创建标记位 bool isEncrypted = encryptList.Contains(bundleName); int flags = PatchBundle.CreateFlags(isEncrypted); // 注意:如果文件没有变化使用旧版本号 if (oldPatchManifest.Bundles.TryGetValue(bundleName, out PatchBundle oldElement)) { if (oldElement.Hash == hash) { version = oldElement.Version; } } PatchBundle newElement = new PatchBundle(bundleName, hash, crc, size, version, flags, assets, depends, dlcLabels); result.Add(newElement); } return(result); }
public static void GenerateAssetBundle(BuildTarget target, bool isCompress) { // Load manifest txt or assetbundle string manifestPathName = Path.Combine(AssetBundleConfig.AssetBundlesRoot, new DirectoryInfo(AssetBundleConfig.AssetBundlesRoot).Name).Replace("\\", "/").ToLower(); AssetBundle bundle = AssetBundle.LoadFromFile(manifestPathName); AssetBundleManifest u3dManifest = bundle.LoadAsset("AssetBundleManifest") as AssetBundleManifest; List <AssetBundleInfo> assetBundles = new List <AssetBundleInfo>(); if (u3dManifest != null) { foreach (var item in u3dManifest.GetAllAssetBundles()) { string itemPath = Path.Combine(AssetBundleConfig.AssetBundlesRoot, item).Replace("\\", "/").ToLower(); AssetBundleInfo info = new AssetBundleInfo(); info.relativePath = item; info.dependencies = u3dManifest.GetAllDependencies(item); info.MD5 = GetMD5HashFromFile(itemPath); AssetBundle subAssetBundle = AssetBundle.LoadFromFile(itemPath); if (subAssetBundle == null) { throw new System.Exception(item + "is not existed! CreateManifest()"); } info.allAssetsName = subAssetBundle.GetAllAssetNames(); SetAssetNames(info.allAssetsName); // This would be used as key to query assetbundle file. assetBundles.Add(info); subAssetBundle.Unload(true); } } bundle.Unload(true); CheckRepeatedAssetName(assetBundles); //create my manifest string tempPath = "Assets/assetsmanifest.json"; CustomAssetBundleManifest.JsonSerialize(assetBundles, tempPath, isCompress); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); //AssetImporter.GetAtPath(tempPath).assetBundleName = AssetBundleConfig.ManifestRelativePath; AssetBundleBuild[] buildManifests = new AssetBundleBuild[1]; buildManifests[0].assetNames = new string[] { tempPath }; buildManifests[0].assetBundleName = AssetBundleConfig.ManifestRelativePath; BuildPipeline.BuildAssetBundles(AssetBundleConfig.AssetBundlesRoot, buildManifests, BuildAssetBundleOptions.UncompressedAssetBundle, target); #if !LEAVE_CFG_FILE FileUtil.DeleteFileOrDirectory(AssetBundleConfig.DstDir + "AssetBundle"); FileUtil.DeleteFileOrDirectory(tempPath); #endif }
//アセットバンドルマニフェストの情報を追加 public void AddAssetBundleManifest(string rootUrl, AssetBundleManifest manifest) { foreach (string name in manifest.GetAllAssetBundles()) { Hash128 assetBundleHash = manifest.GetAssetBundleHash(name); string path = FilePathUtil.Combine(rootUrl, name); try { dictionary.Add(path, new AssetBundleInfo(path, assetBundleHash)); } catch { Debug.LogError(path + "is already contains in assetbundleManger"); } } }