Update AssetBundleBuilder
This commit is contained in:
@@ -33,7 +33,11 @@ namespace YooAsset.Editor
|
||||
buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension;
|
||||
buildReport.Summary.AutoCollectShaders = AssetBundleCollectorSettingData.Setting.AutoCollectShaders;
|
||||
buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
|
||||
|
||||
buildReport.Summary.EncryptionServicesClassName = buildParameters.Parameters.EncryptionServices == null ?
|
||||
"null" : buildParameters.Parameters.EncryptionServices.GetType().FullName;
|
||||
buildReport.Summary.RedundancyServicesClassName = buildParameters.Parameters.RedundancyServices == null ?
|
||||
"null" : buildParameters.Parameters.RedundancyServices.GetType().FullName;
|
||||
|
||||
// 构建参数
|
||||
buildReport.Summary.ForceRebuild = buildParameters.Parameters.ForceRebuild;
|
||||
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
|
||||
|
||||
@@ -26,40 +26,23 @@ namespace YooAsset.Editor
|
||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<TaskGetBuildMap.BuildMapContext>();
|
||||
|
||||
var encrypter = CreateAssetEncrypter();
|
||||
List<string> encryptList = EncryptFiles(encrypter, buildParameters, buildMapContext);
|
||||
|
||||
EncryptionContext encryptionContext = new EncryptionContext();
|
||||
encryptionContext.EncryptList = encryptList;
|
||||
encryptionContext.EncryptList = EncryptFiles(buildParameters, buildMapContext);
|
||||
context.SetContextObject(encryptionContext);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建加密类
|
||||
/// </summary>
|
||||
/// <returns>如果没有定义类型,则返回NULL</returns>
|
||||
private IAssetEncrypter CreateAssetEncrypter()
|
||||
{
|
||||
var types = AssemblyUtility.GetAssignableTypes(AssemblyUtility.UnityDefaultAssemblyEditorName, typeof(IAssetEncrypter));
|
||||
if (types.Count == 0)
|
||||
return null;
|
||||
if (types.Count != 1)
|
||||
throw new Exception($"Found more {nameof(IAssetEncrypter)} types. We only support one.");
|
||||
|
||||
UnityEngine.Debug.Log($"创建实例类 : {types[0].FullName}");
|
||||
return (IAssetEncrypter)Activator.CreateInstance(types[0]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加密文件
|
||||
/// </summary>
|
||||
private List<string> EncryptFiles(IAssetEncrypter encrypter, AssetBundleBuilder.BuildParametersContext buildParameters, TaskGetBuildMap.BuildMapContext buildMapContext)
|
||||
private List<string> EncryptFiles(AssetBundleBuilder.BuildParametersContext buildParameters, TaskGetBuildMap.BuildMapContext buildMapContext)
|
||||
{
|
||||
var encryptionServices = buildParameters.Parameters.EncryptionServices;
|
||||
|
||||
// 加密资源列表
|
||||
List<string> encryptList = new List<string>();
|
||||
|
||||
// 如果没有设置加密类
|
||||
if (encrypter == null)
|
||||
if (encryptionServices == null)
|
||||
return encryptList;
|
||||
|
||||
UnityEngine.Debug.Log($"开始加密资源文件");
|
||||
@@ -68,7 +51,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
var bundleName = bundleInfo.BundleName;
|
||||
string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}";
|
||||
if (encrypter.Check(filePath))
|
||||
if (encryptionServices.Check(filePath))
|
||||
{
|
||||
encryptList.Add(bundleName);
|
||||
|
||||
@@ -76,7 +59,7 @@ namespace YooAsset.Editor
|
||||
byte[] fileData = File.ReadAllBytes(filePath);
|
||||
if (EditorTools.CheckBundleFileValid(fileData))
|
||||
{
|
||||
byte[] bytes = encrypter.Encrypt(fileData);
|
||||
byte[] bytes = encryptionServices.Encrypt(fileData);
|
||||
File.WriteAllBytes(filePath, bytes);
|
||||
UnityEngine.Debug.Log($"文件加密完成:{filePath}");
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ namespace YooAsset.Editor
|
||||
buildMapContext.AssetFileCount = buildAssetDic.Values.Count;
|
||||
|
||||
// 4. 移除零依赖的资源
|
||||
var redundancy = CreateAssetRedundancy();
|
||||
var redundancyServices = buildParameters.Parameters.RedundancyServices;
|
||||
List<BuildAssetInfo> undependentAssets = new List<BuildAssetInfo>();
|
||||
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
|
||||
{
|
||||
@@ -205,7 +205,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
// 冗余扩展
|
||||
if (redundancy != null && redundancy.Check(buildAssetInfo.AssetPath))
|
||||
if (redundancyServices != null && redundancyServices.Check(buildAssetInfo.AssetPath))
|
||||
{
|
||||
undependentAssets.Add(buildAssetInfo);
|
||||
buildMapContext.RedundancyAssetList.Add(buildAssetInfo.AssetPath);
|
||||
@@ -300,21 +300,5 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建冗余类
|
||||
/// </summary>
|
||||
/// <returns>如果没有定义类型,则返回NULL</returns>
|
||||
private IAssetRedundancy CreateAssetRedundancy()
|
||||
{
|
||||
var types = AssemblyUtility.GetAssignableTypes(AssemblyUtility.UnityDefaultAssemblyEditorName, typeof(IAssetRedundancy));
|
||||
if (types.Count == 0)
|
||||
return null;
|
||||
if (types.Count != 1)
|
||||
throw new Exception($"Found more {nameof(IAssetRedundancy)} types. We only support one.");
|
||||
|
||||
UnityEngine.Debug.Log($"创建实例类 : {types[0].FullName}");
|
||||
return (IAssetRedundancy)Activator.CreateInstance(types[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user