Update AssetBundleBuilder

This commit is contained in:
hevinci
2022-03-19 00:41:50 +08:00
parent 3689a39a47
commit 7bd09080ef
15 changed files with 337 additions and 216 deletions
@@ -45,7 +45,7 @@ namespace YooAsset.Editor
}
// 验证构建结果
if (buildParametersContext.Parameters.IsVerifyBuildingResult)
if (buildParametersContext.Parameters.VerifyBuildingResult)
{
VerifyingBuildingResult(context, unityManifest);
}
@@ -15,7 +15,7 @@ namespace YooAsset.Editor
{
// 注意:我们只有在强制重建的时候才会拷贝
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
if(buildParameters.Parameters.IsForceRebuild)
if(buildParameters.Parameters.ForceRebuild)
{
// 清空流目录
AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
@@ -56,7 +56,7 @@ namespace YooAsset.Editor
// 加载旧补丁清单
PatchManifest oldPatchManifest = null;
if (buildParameters.Parameters.IsForceRebuild == false)
if (buildParameters.Parameters.ForceRebuild == false)
{
oldPatchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
}
@@ -36,11 +36,11 @@ namespace YooAsset.Editor
AppendData(content, $"构建时间:{DateTime.Now}");
AppendData(content, $"构建平台:{buildParameters.Parameters.BuildTarget}");
AppendData(content, $"构建版本:{buildParameters.Parameters.BuildVersion}");
AppendData(content, $"冗余机制:{buildParameters.Parameters.ApplyRedundancy}");
AppendData(content, $"自动分包:{buildParameters.Parameters.EnableAutoCollect}");
AppendData(content, "");
AppendData(content, $"--着色器--");
AppendData(content, $"IsCollectAllShaders:{AssetBundleCollectorSettingData.Setting.IsCollectAllShaders}");
AppendData(content, $"IsCollectAllShaders:{AssetBundleCollectorSettingData.Setting.AutoCollectShaders}");
AppendData(content, $"ShadersBundleName:{AssetBundleCollectorSettingData.Setting.ShadersBundleName}");
AppendData(content, "");
@@ -54,12 +54,12 @@ namespace YooAsset.Editor
AppendData(content, "");
AppendData(content, $"--构建参数--");
AppendData(content, $"CompressOption:{buildParameters.Parameters.CompressOption}");
AppendData(content, $"IsForceRebuild:{buildParameters.Parameters.IsForceRebuild}");
AppendData(content, $"IsForceRebuild:{buildParameters.Parameters.ForceRebuild}");
AppendData(content, $"BuildinTags:{buildParameters.Parameters.BuildinTags}");
AppendData(content, $"IsAppendHash:{buildParameters.Parameters.IsAppendHash}");
AppendData(content, $"IsDisableWriteTypeTree:{buildParameters.Parameters.IsDisableWriteTypeTree}");
AppendData(content, $"IsIgnoreTypeTreeChanges:{buildParameters.Parameters.IsIgnoreTypeTreeChanges}");
AppendData(content, $"IsDisableLoadAssetByFileName : {buildParameters.Parameters.IsDisableLoadAssetByFileName}");
AppendData(content, $"IsAppendHash:{buildParameters.Parameters.AppendHash}");
AppendData(content, $"IsDisableWriteTypeTree:{buildParameters.Parameters.DisableWriteTypeTree}");
AppendData(content, $"IsIgnoreTypeTreeChanges:{buildParameters.Parameters.IgnoreTypeTreeChanges}");
AppendData(content, $"IsDisableLoadAssetByFileName : {buildParameters.Parameters.DisableLoadAssetByFileName}");
AppendData(content, "");
AppendData(content, $"--构建信息--");
@@ -22,22 +22,37 @@ namespace YooAsset.Editor
BuildReport buildReport = new BuildReport();
// 概述信息
buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion;
buildReport.Summary.BuildTime = DateTime.Now.ToString();
buildReport.Summary.BuildSeconds = 0;
buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget;
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion;
buildReport.Summary.ApplyRedundancy = buildParameters.Parameters.ApplyRedundancy;
buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension;
buildReport.Summary.IsCollectAllShaders = AssetBundleCollectorSettingData.Setting.IsCollectAllShaders;
buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
buildReport.Summary.IsForceRebuild = buildParameters.Parameters.IsForceRebuild;
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption;
buildReport.Summary.IsAppendHash = buildParameters.Parameters.IsAppendHash;
buildReport.Summary.IsDisableWriteTypeTree = buildParameters.Parameters.IsDisableWriteTypeTree;
buildReport.Summary.IsIgnoreTypeTreeChanges = buildParameters.Parameters.IsIgnoreTypeTreeChanges;
buildReport.Summary.IsDisableLoadAssetByFileName = buildParameters.Parameters.IsDisableLoadAssetByFileName;
{
buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion;
buildReport.Summary.BuildTime = DateTime.Now.ToString();
buildReport.Summary.BuildSeconds = 0;
buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget;
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion;
buildReport.Summary.EnableAutoCollect = buildParameters.Parameters.EnableAutoCollect;
buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension;
buildReport.Summary.AutoCollectShaders = AssetBundleCollectorSettingData.Setting.AutoCollectShaders;
buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
// 构建参数
buildReport.Summary.ForceRebuild = buildParameters.Parameters.ForceRebuild;
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption;
buildReport.Summary.AppendHash = buildParameters.Parameters.AppendHash;
buildReport.Summary.DisableWriteTypeTree = buildParameters.Parameters.DisableWriteTypeTree;
buildReport.Summary.IgnoreTypeTreeChanges = buildParameters.Parameters.IgnoreTypeTreeChanges;
buildReport.Summary.DisableLoadAssetByFileName = buildParameters.Parameters.DisableLoadAssetByFileName;
// 构建结果
buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount;
buildReport.Summary.AllBundleTotalCount = GetAllBundleCount(patchManifest);
buildReport.Summary.AllBundleTotalSize = GetAllBundleSize(patchManifest);
buildReport.Summary.BuildinBundleTotalCount = GetBuildinBundleCount(patchManifest);
buildReport.Summary.BuildinBundleTotalSize = GetBuildinBundleSize(patchManifest);
buildReport.Summary.EncryptedBundleTotalCount = GetEncryptedBundleCount(patchManifest);
buildReport.Summary.EncryptedBundleTotalSize = GetEncryptedBundleSize(patchManifest);
buildReport.Summary.RawBundleTotalCount = GetRawBundleCount(patchManifest);
buildReport.Summary.RawBundleTotalSize = GetRawBundleSize(patchManifest);
}
// 资源对象列表
buildReport.AssetInfos = new List<ReportAssetInfo>(patchManifest.AssetList.Count);
@@ -85,7 +100,7 @@ namespace YooAsset.Editor
private List<string> GetDependBundles(PatchManifest patchManifest, PatchAsset patchAsset)
{
List<string> dependBundles = new List<string>(patchAsset.DependIDs.Length);
foreach(int index in patchAsset.DependIDs)
foreach (int index in patchAsset.DependIDs)
{
string dependBundleName = patchManifest.BundleList[index].BundleName;
dependBundles.Add(dependBundleName);
@@ -99,12 +114,12 @@ namespace YooAsset.Editor
private List<string> GetDependAssets(TaskGetBuildMap.BuildMapContext buildMapContext, string bundleName, string assetPath)
{
List<string> result = new List<string>();
if(buildMapContext.TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
if (buildMapContext.TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
{
BuildAssetInfo findAssetInfo = null;
foreach(var buildinAsset in bundleInfo.BuildinAssets)
foreach (var buildinAsset in bundleInfo.BuildinAssets)
{
if(buildinAsset.AssetPath == assetPath)
if (buildinAsset.AssetPath == assetPath)
{
findAssetInfo = buildinAsset;
break;
@@ -114,7 +129,7 @@ namespace YooAsset.Editor
{
throw new Exception($"Not found asset {assetPath} in bunlde {bundleName}");
}
foreach(var dependAssetInfo in findAssetInfo.AllDependAssetInfos)
foreach (var dependAssetInfo in findAssetInfo.AllDependAssetInfos)
{
result.Add(dependAssetInfo.AssetPath);
}
@@ -125,5 +140,79 @@ namespace YooAsset.Editor
}
return result;
}
private int GetAllBundleCount(PatchManifest patchManifest)
{
return patchManifest.BundleList.Count;
}
private long GetAllBundleSize(PatchManifest patchManifest)
{
long fileBytes = 0;
foreach (var patchBundle in patchManifest.BundleList)
{
fileBytes += patchBundle.SizeBytes;
}
return fileBytes;
}
private int GetBuildinBundleCount(PatchManifest patchManifest)
{
int fileCount = 0;
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.IsBuildin)
fileCount++;
}
return fileCount;
}
private long GetBuildinBundleSize(PatchManifest patchManifest)
{
long fileBytes = 0;
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.IsBuildin)
fileBytes += patchBundle.SizeBytes;
}
return fileBytes;
}
private int GetEncryptedBundleCount(PatchManifest patchManifest)
{
int fileCount = 0;
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.IsEncrypted)
fileCount++;
}
return fileCount;
}
private long GetEncryptedBundleSize(PatchManifest patchManifest)
{
long fileBytes = 0;
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.IsEncrypted)
fileBytes += patchBundle.SizeBytes;
}
return fileBytes;
}
private int GetRawBundleCount(PatchManifest patchManifest)
{
int fileCount = 0;
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.IsRawFile)
fileCount++;
}
return fileCount;
}
private long GetRawBundleSize(PatchManifest patchManifest)
{
long fileBytes = 0;
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.IsRawFile)
fileBytes += patchBundle.SizeBytes;
}
return fileBytes;
}
}
}
@@ -11,6 +11,12 @@ namespace YooAsset.Editor
{
public class BuildMapContext : IContextObject
{
/// <summary>
/// 参与构建的资源总数
/// 说明:包括主动收集的资源以及其依赖的所有资源
/// </summary>
public int AssetFileCount;
/// <summary>
/// 资源包列表
/// </summary>
@@ -179,7 +185,10 @@ namespace YooAsset.Editor
}
EditorTools.ClearProgressBar();
// 3. 移除零依赖的资源
// 3. 记录参与构建的资源总数
buildMapContext.AssetFileCount = buildAssetDic.Values.Count;
// 4. 移除零依赖的资源
var redundancy = CreateAssetRedundancy();
List<BuildAssetInfo> undependentAssets = new List<BuildAssetInfo>();
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
@@ -196,18 +205,15 @@ namespace YooAsset.Editor
}
// 冗余扩展
if(redundancy != null)
if (redundancy != null && redundancy.Check(buildAssetInfo.AssetPath))
{
if(redundancy.Check(buildAssetInfo.AssetPath))
{
undependentAssets.Add(buildAssetInfo);
buildMapContext.RedundancyAssetList.Add(buildAssetInfo.AssetPath);
continue;
}
undependentAssets.Add(buildAssetInfo);
buildMapContext.RedundancyAssetList.Add(buildAssetInfo.AssetPath);
continue;
}
// 冗余机制
if (buildParameters.Parameters.ApplyRedundancy)
// 如果没有开启自动分包,没有被收集到的资源会造成冗余
if (buildParameters.Parameters.EnableAutoCollect == false)
{
if (AssetBundleCollectorSettingData.HasCollector(buildAssetInfo.AssetPath) == false)
{
@@ -221,7 +227,7 @@ namespace YooAsset.Editor
buildAssetDic.Remove(assetInfo.AssetPath);
}
// 4. 设置资源包名
// 5. 设置资源包名
progressValue = 0;
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
{
@@ -235,7 +241,7 @@ namespace YooAsset.Editor
}
EditorTools.ClearProgressBar();
// 4. 构建资源包
// 6. 构建资源包
var allAssets = buildAssetDic.Values.ToList();
if (allAssets.Count == 0)
throw new Exception("构建的资源列表不能为空");
@@ -29,7 +29,7 @@ namespace YooAsset.Editor
throw new Exception("配置的资源收集路径为空");
// 增量更新时候的必要检测
if (buildParameters.Parameters.IsForceRebuild == false)
if (buildParameters.Parameters.ForceRebuild == false)
{
// 检测历史版本是否存在
if (AssetBundleBuilderHelper.HasAnyPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot) == false)
@@ -52,7 +52,7 @@ namespace YooAsset.Editor
}
// 如果是强制重建
if (buildParameters.Parameters.IsForceRebuild)
if (buildParameters.Parameters.ForceRebuild)
{
// 删除平台总目录
string platformDirectory = $"{buildParameters.Parameters.OutputRoot}/{buildParameters.Parameters.BuildTarget}";