Update AssetBundleBuilder

pull/51/head
hevinci 2022-10-19 15:54:59 +08:00
parent 2fb77c1bf8
commit 958cdd25a5
9 changed files with 48 additions and 26 deletions

View File

@ -257,7 +257,6 @@ namespace YooAsset.Editor
buildParameters.BuildMode = AssetBundleBuilderSettingData.Setting.BuildMode; buildParameters.BuildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
buildParameters.BuildPackage = AssetBundleBuilderSettingData.Setting.BuildPackage; buildParameters.BuildPackage = AssetBundleBuilderSettingData.Setting.BuildPackage;
buildParameters.VerifyBuildingResult = true; buildParameters.VerifyBuildingResult = true;
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
buildParameters.EncryptionServices = CreateEncryptionServicesInstance(); buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption; buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption;
buildParameters.OutputNameStyle = AssetBundleBuilderSettingData.Setting.OutputNameStyle; buildParameters.OutputNameStyle = AssetBundleBuilderSettingData.Setting.OutputNameStyle;

View File

@ -15,7 +15,6 @@ namespace YooAsset.Editor
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget; buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.BuildMode = EBuildMode.SimulateBuild; buildParameters.BuildMode = EBuildMode.SimulateBuild;
buildParameters.BuildPackage = packageName; buildParameters.BuildPackage = packageName;
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
AssetBundleBuilder builder = new AssetBundleBuilder(); AssetBundleBuilder builder = new AssetBundleBuilder();
var buildResult = builder.Run(buildParameters); var buildResult = builder.Run(buildParameters);

View File

@ -166,7 +166,7 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 计算主资源或共享资源的完整包名 /// 计算主资源或共享资源的完整包名
/// </summary> /// </summary>
public void CalculateFullBundleName() public void CalculateFullBundleName(bool uniqueBundleName, string packageName)
{ {
if (CollectorType == ECollectorType.None) if (CollectorType == ECollectorType.None)
{ {
@ -177,15 +177,22 @@ namespace YooAsset.Editor
{ {
string shareBundleName = YooAssetSettingsData.GetUnityShadersBundleFullName(); string shareBundleName = YooAssetSettingsData.GetUnityShadersBundleFullName();
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower(); _shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
return; }
else
{
if (_referenceBundleNames.Count > 1)
{
IPackRule packRule = PackDirectory.StaticPackRule;
var bundleName = packRule.GetBundleName(new PackRuleData(AssetPath));
var shareBundleName = $"share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
}
} }
if (_referenceBundleNames.Count > 1) if (uniqueBundleName)
{ {
IPackRule packRule = PackDirectory.StaticPackRule; if (string.IsNullOrEmpty(_shareBundleName) == false)
var bundleName = packRule.GetBundleName(new PackRuleData(AssetPath)); _shareBundleName = $"{packageName.ToLower()}_{_shareBundleName}";
var shareBundleName = $"share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
} }
} }
else else

View File

@ -14,6 +14,16 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public int AssetFileCount; public int AssetFileCount;
/// <summary>
/// 是否启用可寻址资源定位
/// </summary>
public bool EnableAddressable;
/// <summary>
/// 资源包名唯一化
/// </summary>
public bool UniqueBundleName;
/// <summary> /// <summary>
/// 资源包列表 /// 资源包列表
/// </summary> /// </summary>

View File

@ -19,7 +19,8 @@ namespace YooAsset.Editor
AssetBundleCollectorSettingData.Setting.CheckConfigError(); AssetBundleCollectorSettingData.Setting.CheckConfigError();
// 2. 获取所有收集器收集的资源 // 2. 获取所有收集器收集的资源
List<CollectAssetInfo> allCollectAssets = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName); var buildResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName);
List<CollectAssetInfo> allCollectAssets = buildResult.CollectAssets;
// 3. 剔除未被引用的依赖资源 // 3. 剔除未被引用的依赖资源
List<CollectAssetInfo> removeDependList = new List<CollectAssetInfo>(); List<CollectAssetInfo> removeDependList = new List<CollectAssetInfo>();
@ -72,9 +73,13 @@ namespace YooAsset.Editor
} }
} }
} }
context.AssetFileCount = buildAssetDic.Count;
// 6. 填充主动收集资源的依赖列表 // 6. 记录关键信息
context.AssetFileCount = buildAssetDic.Count;
context.EnableAddressable = buildResult.EnableAddressable;
context.UniqueBundleName = buildResult.UniqueBundleName;
// 7. 填充主动收集资源的依赖列表
foreach (var collectAssetInfo in allCollectAssets) foreach (var collectAssetInfo in allCollectAssets)
{ {
var dependAssetInfos = new List<BuildAssetInfo>(collectAssetInfo.DependAssets.Count); var dependAssetInfos = new List<BuildAssetInfo>(collectAssetInfo.DependAssets.Count);
@ -88,13 +93,13 @@ namespace YooAsset.Editor
buildAssetDic[collectAssetInfo.AssetPath].SetAllDependAssetInfos(dependAssetInfos); buildAssetDic[collectAssetInfo.AssetPath].SetAllDependAssetInfos(dependAssetInfos);
} }
// 7. 计算完整的资源包名 // 8. 计算完整的资源包名
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic) foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
{ {
pair.Value.CalculateFullBundleName(); pair.Value.CalculateFullBundleName(buildResult.UniqueBundleName, buildResult.PackageName);
} }
// 8. 移除不参与构建的资源 // 9. 移除不参与构建的资源
List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>(); List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>();
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic) foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
{ {
@ -107,7 +112,7 @@ namespace YooAsset.Editor
buildAssetDic.Remove(removeValue.AssetPath); buildAssetDic.Remove(removeValue.AssetPath);
} }
// 9. 构建资源包 // 10. 构建资源包
var allBuildinAssets = buildAssetDic.Values.ToList(); var allBuildinAssets = buildAssetDic.Values.ToList();
if (allBuildinAssets.Count == 0) if (allBuildinAssets.Count == 0)
throw new Exception("构建的资源列表不能为空"); throw new Exception("构建的资源列表不能为空");

View File

@ -72,11 +72,6 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public bool VerifyBuildingResult = false; public bool VerifyBuildingResult = false;
/// <summary>
/// 启用可寻址资源定位
/// </summary>
public bool EnableAddressable = false;
/// <summary> /// <summary>
/// 加密类 /// 加密类
/// </summary> /// </summary>

View File

@ -53,6 +53,11 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public bool EnableAddressable; public bool EnableAddressable;
/// <summary>
/// 资源包名唯一化
/// </summary>
public bool UniqueBundleName;
/// <summary> /// <summary>
/// 加密服务类名称 /// 加密服务类名称
/// </summary> /// </summary>

View File

@ -21,6 +21,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private void CreatePatchManifestFile(BuildContext context) private void CreatePatchManifestFile(BuildContext context)
{ {
var buildMapContext = context.GetContextObject<BuildMapContext>();
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildParameters = buildParametersContext.Parameters; var buildParameters = buildParametersContext.Parameters;
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
@ -28,7 +29,7 @@ namespace YooAsset.Editor
// 创建新补丁清单 // 创建新补丁清单
PatchManifest patchManifest = new PatchManifest(); PatchManifest patchManifest = new PatchManifest();
patchManifest.FileVersion = YooAssetSettings.PatchManifestFileVersion; patchManifest.FileVersion = YooAssetSettings.PatchManifestFileVersion;
patchManifest.EnableAddressable = buildParameters.EnableAddressable; patchManifest.EnableAddressable = buildMapContext.EnableAddressable;
patchManifest.OutputNameStyle = (int)buildParameters.OutputNameStyle; patchManifest.OutputNameStyle = (int)buildParameters.OutputNameStyle;
patchManifest.PackageName = buildParameters.BuildPackage; patchManifest.PackageName = buildParameters.BuildPackage;
patchManifest.HumanReadableVersion = buildParameters.HumanReadableVersion; patchManifest.HumanReadableVersion = buildParameters.HumanReadableVersion;
@ -125,7 +126,6 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private List<PatchAsset> GetAllPatchAsset(BuildContext context, PatchManifest patchManifest) private List<PatchAsset> GetAllPatchAsset(BuildContext context, PatchManifest patchManifest)
{ {
var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
List<PatchAsset> result = new List<PatchAsset>(1000); List<PatchAsset> result = new List<PatchAsset>(1000);
@ -135,7 +135,7 @@ namespace YooAsset.Editor
foreach (var assetInfo in assetInfos) foreach (var assetInfo in assetInfos)
{ {
PatchAsset patchAsset = new PatchAsset(); PatchAsset patchAsset = new PatchAsset();
if (buildParameters.Parameters.EnableAddressable) if (buildMapContext.EnableAddressable)
patchAsset.Address = assetInfo.Address; patchAsset.Address = assetInfo.Address;
else else
patchAsset.Address = string.Empty; patchAsset.Address = string.Empty;

View File

@ -46,7 +46,9 @@ namespace YooAsset.Editor
buildReport.Summary.BuildPipeline = buildParameters.BuildPipeline; buildReport.Summary.BuildPipeline = buildParameters.BuildPipeline;
buildReport.Summary.BuildMode = buildParameters.BuildMode; buildReport.Summary.BuildMode = buildParameters.BuildMode;
buildReport.Summary.BuildPackage = buildParameters.BuildPackage; buildReport.Summary.BuildPackage = buildParameters.BuildPackage;
buildReport.Summary.EnableAddressable = buildParameters.EnableAddressable; buildReport.Summary.EnableAddressable = buildMapContext.EnableAddressable;
buildReport.Summary.UniqueBundleName = buildMapContext.UniqueBundleName;
buildReport.Summary.EncryptionServicesClassName = buildParameters.EncryptionServices == null ? buildReport.Summary.EncryptionServicesClassName = buildParameters.EncryptionServices == null ?
"null" : buildParameters.EncryptionServices.GetType().FullName; "null" : buildParameters.EncryptionServices.GetType().FullName;