Files
YooAsset/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskEncryption.cs

50 lines
1.9 KiB
C#
Raw Normal View History

2022-03-01 10:44:12 +08:00
using System;
using System.Linq;
using System.IO;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset.Editor
{
2023-12-21 19:29:26 +08:00
public class TaskEncryption
{
/// <summary>
/// 加密文件
/// </summary>
public void EncryptingBundleFiles(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
{
var encryptionServices = buildParametersContext.Parameters.EncryptionServices;
if (encryptionServices == null)
return;
2022-03-01 10:44:12 +08:00
2023-12-21 19:29:26 +08:00
if (encryptionServices.GetType() == typeof(EncryptionNone))
return;
2023-03-03 11:51:48 +08:00
2023-12-21 19:29:26 +08:00
int progressValue = 0;
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
foreach (var bundleInfo in buildMapContext.Collection)
{
EncryptFileInfo fileInfo = new EncryptFileInfo();
fileInfo.BundleName = bundleInfo.BundleName;
fileInfo.FileLoadPath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
2023-12-21 19:29:26 +08:00
var encryptResult = encryptionServices.Encrypt(fileInfo);
if (encryptResult.Encrypted)
{
string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}.encrypt";
FileUtility.WriteAllBytes(filePath, encryptResult.EncryptedData);
bundleInfo.EncryptedFilePath = filePath;
bundleInfo.Encrypted = true;
BuildLogger.Log($"Bundle file encryption complete: {filePath}");
}
else
{
bundleInfo.Encrypted = false;
}
2022-03-01 10:44:12 +08:00
2023-12-21 19:29:26 +08:00
// 进度条
EditorTools.DisplayProgressBar("Encrypting bundle", ++progressValue, buildMapContext.Collection.Count);
}
EditorTools.ClearProgressBar();
}
}
2022-03-01 10:44:12 +08:00
}