private void EncryptFiles(string[] allAssetBundles) { Log($"开始加密资源文件"); // 初始化加密器 InitAssetEncrypter(); int progressBarCount = 0; foreach (string assetName in allAssetBundles) { string path = $"{OutputPath}/{assetName}"; if (AssetEncrypterCheck(path)) { byte[] fileData = File.ReadAllBytes(path); // 通过判断文件合法性,规避重复加密一个文件。 if (EditorTools.CheckBundleFileValid(fileData)) { byte[] bytes = AssetEncrypterEncrypt(fileData); File.WriteAllBytes(path, bytes); Log($"文件加密完成:{path}"); } } // 进度条 progressBarCount++; EditorUtility.DisplayProgressBar("进度", $"加密资源包:{progressBarCount}/{allAssetBundles.Length}", (float)progressBarCount / allAssetBundles.Length); } EditorUtility.ClearProgressBar(); progressBarCount = 0; }
private List <string> EncryptFiles(AssetBundleManifest unityManifest) { // 初始化加密器 InitAssetEncrypter(); // 加密资源列表 List <string> encryptList = new List <string>(); // 如果没有设置加密类 if (_encrypterType == null) { return(encryptList); } Log($"开始加密资源文件"); int progressBarCount = 0; string[] allAssetBundles = unityManifest.GetAllAssetBundles(); foreach (string assetName in allAssetBundles) { string filePath = $"{OutputDirectory}/{assetName}"; if (InvokeCheckMethod(filePath)) { encryptList.Add(assetName); // 通过判断文件合法性,规避重复加密一个文件 byte[] fileData = File.ReadAllBytes(filePath); if (EditorTools.CheckBundleFileValid(fileData)) { byte[] bytes = InvokeEncryptMethod(fileData); File.WriteAllBytes(filePath, bytes); Log($"文件加密完成:{filePath}"); } } // 进度条 progressBarCount++; EditorUtility.DisplayProgressBar("进度", $"加密资源包:{progressBarCount}/{allAssetBundles.Length}", (float)progressBarCount / allAssetBundles.Length); } EditorUtility.ClearProgressBar(); return(encryptList); }
/// <summary> /// 加密文件 /// </summary> private List <string> EncryptFiles(IAssetEncrypter encrypter, AssetBundleManifest unityManifest, AssetBundleBuilder.BuildParametersContext buildParameters) { // 加密资源列表 List <string> encryptList = new List <string>(); // 如果没有设置加密类 if (encrypter == null) { return(encryptList); } BuildLogger.Log($"开始加密资源文件"); string[] allAssetBundles = unityManifest.GetAllAssetBundles(); int progressValue = 0; foreach (string bundleName in allAssetBundles) { string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}"; if (encrypter.Check(filePath)) { encryptList.Add(bundleName); // 注意:通过判断文件合法性,规避重复加密一个文件 byte[] fileData = File.ReadAllBytes(filePath); if (EditorTools.CheckBundleFileValid(fileData)) { byte[] bytes = encrypter.Encrypt(fileData); File.WriteAllBytes(filePath, bytes); BuildLogger.Log($"文件加密完成:{filePath}"); } } // 进度条 EditorTools.DisplayProgressBar("加密资源包", ++progressValue, allAssetBundles.Length); } EditorTools.ClearProgressBar(); return(encryptList); }