public static void CopyAssetBundle(string dpath) { if (Directory.Exists(Application.streamingAssetsPath)) { Directory.Delete(Application.streamingAssetsPath, true); } Directory.CreateDirectory(Application.streamingAssetsPath); DirectoryInfo ndir = new DirectoryInfo(dpath); FileInfo[] files = ndir.GetFiles("*.*", SearchOption.AllDirectories); for (int i = 0; i < files.Length; ++i) { EditorUtility.DisplayProgressBar("copy assets", string.Format("正在拷贝资源 {0}/{1}", i, files.Length), (float)i / (float)files.Length); FileInfo f = files[i]; if (!f.Name.EndsWith(".manifest")) { string name = f.FullName.Replace("\\", "/"); name = name.Substring(name.IndexOf(dpath) + dpath.Length); string path = f.Directory.FullName.Replace("\\", "/"); path = path.Substring(path.IndexOf(dpath) + dpath.Length); if (!Directory.Exists(Application.streamingAssetsPath + path)) { Directory.CreateDirectory(Application.streamingAssetsPath + path); } FileEncrypt.Encrypt(f.FullName, Application.streamingAssetsPath + name); } } EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); }
public bool MergePatch(string patch, PatchInfo info, ref Dictionary <string, string> localbundles) { int ret = -1; string bundleName = patch.Replace(".patch", ""); string fullpatch = Application.persistentDataPath + "/" + info.version + "/" + patch; string fullbundle = Application.persistentDataPath + "/" + info.version + "/" + bundleName; try { if (patch == bundleName) { ret = 0; } else { string old_file = ""; if (localbundles.ContainsKey(bundleName)) { old_file = GetBundlePathFromPackage(Application.persistentDataPath + "/" + localbundles[bundleName] + "/" + bundleName, fullbundle, false); } else { #if UNITY_ANDROID && !UNITY_EDITOR old_file = GetBundlePathFromPackage(bundleName, fullbundle, true); #else old_file = GetBundlePathFromPackage(Application.streamingAssetsPath + "/" + bundleName, fullbundle, false); #endif } if (!string.IsNullOrEmpty(old_file)) { ret = BSPatch.bspatch_merge(old_file, fullbundle, fullpatch); } } } catch (Exception ex) { Debug.LogError(ex); return(false); } if (ret == 0) { FileEncrypt.Encrypt(fullbundle, fullbundle); if (!localbundles.ContainsKey(bundleName)) { localbundles.Add(bundleName, info.version); } else { localbundles[bundleName] = info.version; } return(true); } return(false); }
static void BuildData() { ResmapUtility.canAuto2Resmap = false; //不自动导入到resmap中 // 创建文件夹 Directory.CreateDirectory(ORIGINABPATH); DeleteFiles("data_"); //删除旧文件 // 重命名assetbundle FileInfo oldFile = new FileInfo(ORIGINABPATH + "/assetbundle"); if (oldFile.Exists) { oldFile.MoveTo(ORIGINABPATH + "/Tmp"); } ABNameUtility.ClearAllABNames(); EditorUtility.DisplayProgressBar("打包前准备", "正在生成resmap文件...", 0.1f); //重新生成Resmap文件 ResmapUtility.AddAllAsset(); EditorUtility.DisplayProgressBar("打包前准备", "正在处理Data文件...", 0.3f); ABNameUtility.SetDataABNames(); EditorUtility.DisplayProgressBar("打包", "正在打包Data文件...", 0.8f); FileEncrypt.Encrypt();//加密Txt AssetDatabase.Refresh(); BuildPipeline.BuildAssetBundles(ORIGINABPATH, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); AssetDatabase.Refresh(); ABNameUtility.ClearDataABNames(); EditorUtility.DisplayProgressBar("打包", "Data文件加密中...", 0.9f); EncryptAB("data_"); FileEncrypt.Decrypt();//还原Txt EditorUtility.ClearProgressBar(); // 删除新assetbundle UnityEditor.FileUtil.DeleteFileOrDirectory(ORIGINABPATH + "/assetbundle"); // 还原文件 if (oldFile.Exists) { oldFile.MoveTo(ORIGINABPATH + "/assetbundle"); } AssetDatabase.Refresh(); }
static void BuildAll() { ResmapUtility.canAuto2Resmap = false; //不自动导入到resmap中 // 创建文件夹 Directory.CreateDirectory(ORIGINABPATH); if (Directory.Exists(ABPATH)) { FileUtil.DeleteFileOrDirectory(ABPATH); } //记录所有的ab包,打包后,对无用的资源进行删除 EditorUtility.DisplayProgressBar("打包前准备", "收集已有AB资源...", 0.05f); Dictionary <string, ABInfo> _infoDic = new Dictionary <string, ABInfo>(); string[] files = Directory.GetFiles(ORIGINABPATH); for (int i = 0; i < files.Length; i++) { string path = files[i]; if (path.EndsWith(".meta") || path.EndsWith(".manifest")) { continue; } string fileName = Path.GetFileNameWithoutExtension(path); if (fileName.Equals("assetbundle")) { continue; } _infoDic.Add(fileName, new ABInfo() { abName = fileName, path = path }); } ABNameUtility.ClearAllABNames(); EditorUtility.DisplayProgressBar("打包前准备", "开始处理多语言资源...", 0.1f); MultiLngResDetach.StartDeal(); EditorUtility.DisplayProgressBar("打包前准备", "正在重新生成Resmap文件...", 0.2f); ResmapUtility.AddAllAsset(); EditorUtility.DisplayProgressBar("打包前准备", "Lua文件加密中...", 0.25f); LuaEncode.StartEncode(EditorUserBuildSettings.activeBuildTarget); EditorUtility.DisplayProgressBar("打包前准备", "配置文件加密中...", 0.3f); FileEncrypt.Encrypt(); AssetDatabase.Refresh(); EditorUtility.DisplayProgressBar("开始打包", "正在自动设置AB名...", 0.4f); ABNameUtility.SetAllABNames(); // 打包 EditorUtility.DisplayProgressBar("打包", "AB打包中...", 0.6f); AssetBundleManifest manifest = BuildPipeline.BuildAssetBundles(ORIGINABPATH, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); string[] bundles = manifest.GetAllAssetBundles(); for (int i = 0; i < bundles.Length; i++) { if (_infoDic.ContainsKey(bundles[i])) { _infoDic.Remove(bundles[i]); } } //删除老旧的ab包 foreach (KeyValuePair <string, ABInfo> pair in _infoDic) { ABInfo info = pair.Value; UnityEditor.FileUtil.DeleteFileOrDirectory(info.path); UnityEditor.FileUtil.DeleteFileOrDirectory(info.path + ".manifest"); } EditorUtility.DisplayProgressBar("收尾", "配置文件还原中...", 0.75f); FileEncrypt.Decrypt();//还原txt EditorUtility.DisplayProgressBar("收尾", "Lua文件还原中...", 0.8f); LuaEncode.EndEncode(); EditorUtility.DisplayProgressBar("收尾", "多语言资源还原中...", 0.85f); MultiLngResDetach.Revert(); EditorUtility.DisplayProgressBar("收尾", "清除AB名...", 0.9f); ABNameUtility.ClearAllABNames(); EditorUtility.ClearProgressBar(); AssetDatabase.Refresh(); ResmapUtility.canAutoToResmap = true; }