Update AssetBundleBuilder
parent
0c14e95679
commit
a6c6da62d3
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
@ -27,11 +28,21 @@ namespace YooAsset.Editor
|
||||||
// 构建参数
|
// 构建参数
|
||||||
private int _buildVersion;
|
private int _buildVersion;
|
||||||
private BuildTarget _buildTarget;
|
private BuildTarget _buildTarget;
|
||||||
private ECompressOption _compressOption = ECompressOption.Uncompressed;
|
private ECompressOption _compressOption;
|
||||||
private bool _appendExtension = false;
|
private bool _appendExtension = false;
|
||||||
private bool _forceRebuild = false;
|
private bool _forceRebuild = false;
|
||||||
private string _buildinTags = string.Empty;
|
private string _buildinTags = string.Empty;
|
||||||
|
|
||||||
|
// 加密类相关
|
||||||
|
private List<Type> _encryptionServicesClassTypes;
|
||||||
|
private string[] _encryptionServicesClassNames;
|
||||||
|
private int _encryptionServicesSelectIndex = -1;
|
||||||
|
|
||||||
|
// 冗余类相关
|
||||||
|
private List<Type> _redundancyServicesClassTypes;
|
||||||
|
private string[] _redundancyServicesClassNames;
|
||||||
|
private int _redundancyServicesSelectIndex = -1;
|
||||||
|
|
||||||
// GUI相关
|
// GUI相关
|
||||||
private bool _isInit = false;
|
private bool _isInit = false;
|
||||||
private GUIStyle _centerStyle;
|
private GUIStyle _centerStyle;
|
||||||
|
@ -52,8 +63,12 @@ namespace YooAsset.Editor
|
||||||
EditorGUILayout.LabelField("Build Output", pipelineOutputDirectory);
|
EditorGUILayout.LabelField("Build Output", pipelineOutputDirectory);
|
||||||
|
|
||||||
// 构建参数
|
// 构建参数
|
||||||
_buildVersion = EditorGUILayout.IntField("Build Version", _buildVersion, GUILayout.MaxWidth(250));
|
_buildVersion = EditorGUILayout.IntField("Build Version", _buildVersion, GUILayout.MaxWidth(300));
|
||||||
_compressOption = (ECompressOption)EditorGUILayout.EnumPopup("Compression", _compressOption, GUILayout.MaxWidth(250));
|
_compressOption = (ECompressOption)EditorGUILayout.EnumPopup("Compression", _compressOption, GUILayout.MaxWidth(300));
|
||||||
|
if (_encryptionServicesClassNames.Length > 0)
|
||||||
|
_encryptionServicesSelectIndex = EditorGUILayout.Popup("Encryption Services", _encryptionServicesSelectIndex, _encryptionServicesClassNames, GUILayout.MaxWidth(300));
|
||||||
|
if (_redundancyServicesClassNames.Length > 0)
|
||||||
|
_redundancyServicesSelectIndex = EditorGUILayout.Popup("Redundancy Services", _redundancyServicesSelectIndex, _redundancyServicesClassNames, GUILayout.MaxWidth(300));
|
||||||
_appendExtension = GUILayout.Toggle(_appendExtension, "Append Extension", GUILayout.MaxWidth(120));
|
_appendExtension = GUILayout.Toggle(_appendExtension, "Append Extension", GUILayout.MaxWidth(120));
|
||||||
_forceRebuild = GUILayout.Toggle(_forceRebuild, "Force Rebuild", GUILayout.MaxWidth(120));
|
_forceRebuild = GUILayout.Toggle(_forceRebuild, "Force Rebuild", GUILayout.MaxWidth(120));
|
||||||
if (_forceRebuild)
|
if (_forceRebuild)
|
||||||
|
@ -104,6 +119,12 @@ namespace YooAsset.Editor
|
||||||
_buildVersion = appVersion.Revision;
|
_buildVersion = appVersion.Revision;
|
||||||
_buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
_buildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||||
|
|
||||||
|
_encryptionServicesClassTypes = GetEncryptionServicesClassTypes();
|
||||||
|
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToArray();
|
||||||
|
|
||||||
|
_redundancyServicesClassTypes = GetRedundancyServicesClassTypes();
|
||||||
|
_redundancyServicesClassNames = _redundancyServicesClassTypes.Select(t => t.FullName).ToArray();
|
||||||
|
|
||||||
// 读取配置
|
// 读取配置
|
||||||
LoadSettingsFromPlayerPrefs();
|
LoadSettingsFromPlayerPrefs();
|
||||||
}
|
}
|
||||||
|
@ -119,6 +140,8 @@ namespace YooAsset.Editor
|
||||||
buildParameters.OutputRoot = defaultOutputRoot;
|
buildParameters.OutputRoot = defaultOutputRoot;
|
||||||
buildParameters.BuildTarget = _buildTarget;
|
buildParameters.BuildTarget = _buildTarget;
|
||||||
buildParameters.BuildVersion = _buildVersion;
|
buildParameters.BuildVersion = _buildVersion;
|
||||||
|
buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
|
||||||
|
buildParameters.RedundancyServices = CreateRedundancyServicesInstance();
|
||||||
buildParameters.CompressOption = _compressOption;
|
buildParameters.CompressOption = _compressOption;
|
||||||
buildParameters.AppendFileExtension = _appendExtension;
|
buildParameters.AppendFileExtension = _appendExtension;
|
||||||
buildParameters.ForceRebuild = _forceRebuild;
|
buildParameters.ForceRebuild = _forceRebuild;
|
||||||
|
@ -126,6 +149,32 @@ namespace YooAsset.Editor
|
||||||
_assetBuilder.Run(buildParameters);
|
_assetBuilder.Run(buildParameters);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Type> GetEncryptionServicesClassTypes()
|
||||||
|
{
|
||||||
|
List<Type> classTypes = AssemblyUtility.GetAssignableTypes(AssemblyUtility.UnityDefaultAssemblyEditorName, typeof(IEncryptionServices));
|
||||||
|
return classTypes;
|
||||||
|
}
|
||||||
|
private IEncryptionServices CreateEncryptionServicesInstance()
|
||||||
|
{
|
||||||
|
if (_encryptionServicesSelectIndex < 0)
|
||||||
|
return null;
|
||||||
|
var classType = _encryptionServicesClassTypes[_encryptionServicesSelectIndex];
|
||||||
|
return (IEncryptionServices)Activator.CreateInstance(classType);
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<Type> GetRedundancyServicesClassTypes()
|
||||||
|
{
|
||||||
|
List<Type> classTypes = AssemblyUtility.GetAssignableTypes(AssemblyUtility.UnityDefaultAssemblyEditorName, typeof(IRedundancyServices));
|
||||||
|
return classTypes;
|
||||||
|
}
|
||||||
|
private IRedundancyServices CreateRedundancyServicesInstance()
|
||||||
|
{
|
||||||
|
if (_redundancyServicesSelectIndex < 0)
|
||||||
|
return null;
|
||||||
|
var classType = _redundancyServicesClassTypes[_redundancyServicesSelectIndex];
|
||||||
|
return (IRedundancyServices)Activator.CreateInstance(classType);
|
||||||
|
}
|
||||||
|
|
||||||
#region 配置相关
|
#region 配置相关
|
||||||
private const string StrEditorCompressOption = "StrEditorCompressOption";
|
private const string StrEditorCompressOption = "StrEditorCompressOption";
|
||||||
private const string StrEditorAppendExtension = "StrEditorAppendExtension";
|
private const string StrEditorAppendExtension = "StrEditorAppendExtension";
|
||||||
|
|
|
@ -40,6 +40,16 @@ namespace YooAsset.Editor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool AppendFileExtension = false;
|
public bool AppendFileExtension = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加密类
|
||||||
|
/// </summary>
|
||||||
|
public IEncryptionServices EncryptionServices;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 冗余类
|
||||||
|
/// </summary>
|
||||||
|
public IRedundancyServices RedundancyServices;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 强制重新构建整个项目,如果为FALSE则是增量打包
|
/// 强制重新构建整个项目,如果为FALSE则是增量打包
|
||||||
|
|
|
@ -53,6 +53,16 @@ namespace YooAsset.Editor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ShadersBundleName;
|
public string ShadersBundleName;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 加密服务类名称
|
||||||
|
/// </summary>
|
||||||
|
public string EncryptionServicesClassName;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 冗余服务类名称
|
||||||
|
/// </summary>
|
||||||
|
public string RedundancyServicesClassName;
|
||||||
|
|
||||||
// 构建参数
|
// 构建参数
|
||||||
public bool ForceRebuild;
|
public bool ForceRebuild;
|
||||||
public string BuildinTags;
|
public string BuildinTags;
|
||||||
|
|
|
@ -33,7 +33,11 @@ namespace YooAsset.Editor
|
||||||
buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension;
|
buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension;
|
||||||
buildReport.Summary.AutoCollectShaders = AssetBundleCollectorSettingData.Setting.AutoCollectShaders;
|
buildReport.Summary.AutoCollectShaders = AssetBundleCollectorSettingData.Setting.AutoCollectShaders;
|
||||||
buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
|
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.ForceRebuild = buildParameters.Parameters.ForceRebuild;
|
||||||
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
|
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
|
||||||
|
|
|
@ -26,40 +26,23 @@ namespace YooAsset.Editor
|
||||||
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
|
||||||
var buildMapContext = context.GetContextObject<TaskGetBuildMap.BuildMapContext>();
|
var buildMapContext = context.GetContextObject<TaskGetBuildMap.BuildMapContext>();
|
||||||
|
|
||||||
var encrypter = CreateAssetEncrypter();
|
|
||||||
List<string> encryptList = EncryptFiles(encrypter, buildParameters, buildMapContext);
|
|
||||||
|
|
||||||
EncryptionContext encryptionContext = new EncryptionContext();
|
EncryptionContext encryptionContext = new EncryptionContext();
|
||||||
encryptionContext.EncryptList = encryptList;
|
encryptionContext.EncryptList = EncryptFiles(buildParameters, buildMapContext);
|
||||||
context.SetContextObject(encryptionContext);
|
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>
|
||||||
/// 加密文件
|
/// 加密文件
|
||||||
/// </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>();
|
List<string> encryptList = new List<string>();
|
||||||
|
|
||||||
// 如果没有设置加密类
|
// 如果没有设置加密类
|
||||||
if (encrypter == null)
|
if (encryptionServices == null)
|
||||||
return encryptList;
|
return encryptList;
|
||||||
|
|
||||||
UnityEngine.Debug.Log($"开始加密资源文件");
|
UnityEngine.Debug.Log($"开始加密资源文件");
|
||||||
|
@ -68,7 +51,7 @@ namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
var bundleName = bundleInfo.BundleName;
|
var bundleName = bundleInfo.BundleName;
|
||||||
string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}";
|
string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}";
|
||||||
if (encrypter.Check(filePath))
|
if (encryptionServices.Check(filePath))
|
||||||
{
|
{
|
||||||
encryptList.Add(bundleName);
|
encryptList.Add(bundleName);
|
||||||
|
|
||||||
|
@ -76,7 +59,7 @@ namespace YooAsset.Editor
|
||||||
byte[] fileData = File.ReadAllBytes(filePath);
|
byte[] fileData = File.ReadAllBytes(filePath);
|
||||||
if (EditorTools.CheckBundleFileValid(fileData))
|
if (EditorTools.CheckBundleFileValid(fileData))
|
||||||
{
|
{
|
||||||
byte[] bytes = encrypter.Encrypt(fileData);
|
byte[] bytes = encryptionServices.Encrypt(fileData);
|
||||||
File.WriteAllBytes(filePath, bytes);
|
File.WriteAllBytes(filePath, bytes);
|
||||||
UnityEngine.Debug.Log($"文件加密完成:{filePath}");
|
UnityEngine.Debug.Log($"文件加密完成:{filePath}");
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,7 +189,7 @@ namespace YooAsset.Editor
|
||||||
buildMapContext.AssetFileCount = buildAssetDic.Values.Count;
|
buildMapContext.AssetFileCount = buildAssetDic.Values.Count;
|
||||||
|
|
||||||
// 4. 移除零依赖的资源
|
// 4. 移除零依赖的资源
|
||||||
var redundancy = CreateAssetRedundancy();
|
var redundancyServices = buildParameters.Parameters.RedundancyServices;
|
||||||
List<BuildAssetInfo> undependentAssets = new List<BuildAssetInfo>();
|
List<BuildAssetInfo> undependentAssets = new List<BuildAssetInfo>();
|
||||||
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
|
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);
|
undependentAssets.Add(buildAssetInfo);
|
||||||
buildMapContext.RedundancyAssetList.Add(buildAssetInfo.AssetPath);
|
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]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
public interface IAssetEncrypter
|
public interface IEncryptionServices
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 检测是否需要加密
|
/// 检测是否需要加密
|
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
public interface IAssetRedundancy
|
public interface IRedundancyServices
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 检测是否冗余
|
/// 检测是否冗余
|
Loading…
Reference in New Issue