Update AssetBundleBuilder

pull/4/head
hevinci 2022-03-16 22:25:55 +08:00
parent 52413ff376
commit feb9a22083
11 changed files with 202 additions and 45 deletions

View File

@ -181,6 +181,7 @@ namespace YooAsset.Editor
new TaskEncryption(), //加密资源文件 new TaskEncryption(), //加密资源文件
new TaskCreatePatchManifest(), //创建清单文件 new TaskCreatePatchManifest(), //创建清单文件
new TaskCreateReadme(), //创建说明文件 new TaskCreateReadme(), //创建说明文件
new TaskCreateReport(), //创建报告文件
new TaskCreatePatchPackage(), //制作补丁包 new TaskCreatePatchPackage(), //制作补丁包
new TaskCopyBuildinFiles(), //拷贝内置文件 new TaskCopyBuildinFiles(), //拷贝内置文件
}; };

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
@ -10,40 +11,29 @@ namespace YooAsset.Editor
[Serializable] [Serializable]
public class BuildReport public class BuildReport
{ {
/// <summary>
/// 构建汇总信息
/// </summary>
public BuildSummary Summary = new BuildSummary();
/// <summary> /// <summary>
/// 资源包列表 /// 资源包列表
/// </summary> /// </summary>
public readonly List<BuildBundleInfo> BundleInfos = new List<BuildBundleInfo>(1000); public List<BuildBundleInfo> BundleInfos;
/// <summary> /// <summary>
/// 冗余的资源列表 /// 冗余的资源列表
/// </summary> /// </summary>
public readonly List<string> RedundancyList = new List<string>(1000); public List<string> RedundancyList;
/// <summary> /// <summary>
/// 检测是否包含BundleName /// 序列化
/// </summary> /// </summary>
public bool IsContainsBundle(string bundleFullName) public static void Serialize(string savePath, BuildReport buildReport)
{ {
return TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo); string json = JsonUtility.ToJson(buildReport, true);
} FileUtility.CreateFile(savePath, json);
/// <summary>
/// 尝试获取资源包类,如果没有返回空
/// </summary>
public bool TryGetBundleInfo(string bundleFullName, out BuildBundleInfo result)
{
foreach (var bundleInfo in BundleInfos)
{
if (bundleInfo.BundleName == bundleFullName)
{
result = bundleInfo;
return true;
}
}
result = null;
return false;
} }
} }
} }

View File

@ -0,0 +1,59 @@
using System;
using UnityEditor;
namespace YooAsset.Editor
{
[Serializable]
public class BuildSummary
{
/// <summary>
/// 引擎版本
/// </summary>
public string UnityVersion;
/// <summary>
/// 构建时间
/// </summary>
public string BuildTime;
/// <summary>
/// 构建耗时(单位:秒)
/// </summary>
public int BuildSeconds;
/// <summary>
/// 构建平台
/// </summary>
public BuildTarget BuildTarget;
/// <summary>
/// 构建版本
/// </summary>
public int BuildVersion;
/// <summary>
/// 是否开启冗余机制
/// </summary>
public bool ApplyRedundancy;
/// <summary>
/// 是否开启文件后缀名
/// </summary>
public bool AppendFileExtension;
#region 着色器
public bool IsCollectAllShaders;
public string ShadersBundleName;
#endregion
#region 构建参数
public bool IsForceRebuild;
public string BuildinTags;
public ECompressOption CompressOption;
public bool IsAppendHash;
public bool IsDisableWriteTypeTree;
public bool IsIgnoreTypeTreeChanges;
public bool IsDisableLoadAssetByFileName;
#endregion
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cc215f5628022c345be919a0e21fcc8c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -31,7 +31,7 @@ namespace YooAsset.Editor
context.SetContextObject(unityManifestContext); context.SetContextObject(unityManifestContext);
// 拷贝原生文件 // 拷贝原生文件
foreach (var bundleInfo in buildMapContext.Report.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
{ {
if (bundleInfo.IsRawFile) if (bundleInfo.IsRawFile)
{ {
@ -62,7 +62,7 @@ namespace YooAsset.Editor
// 1. 过滤掉原生Bundle // 1. 过滤掉原生Bundle
List<BuildBundleInfo> expectBundles = new List<BuildBundleInfo>(buildedBundles.Length); List<BuildBundleInfo> expectBundles = new List<BuildBundleInfo>(buildedBundles.Length);
foreach(var bundleInfo in buildMapContext.Report.BundleInfos) foreach(var bundleInfo in buildMapContext.BundleInfos)
{ {
if (bundleInfo.IsRawFile == false) if (bundleInfo.IsRawFile == false)
expectBundles.Add(bundleInfo); expectBundles.Add(bundleInfo);
@ -77,7 +77,7 @@ namespace YooAsset.Editor
// 3. 正向验证Bundle // 3. 正向验证Bundle
foreach (var bundleName in buildedBundles) foreach (var bundleName in buildedBundles)
{ {
if (buildMapContext.Report.IsContainsBundle(bundleName) == false) if (buildMapContext.IsContainsBundle(bundleName) == false)
{ {
throw new Exception($"Should never get here !"); throw new Exception($"Should never get here !");
} }

View File

@ -61,7 +61,7 @@ namespace YooAsset.Editor
oldPatchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory); oldPatchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
} }
foreach (var bundleInfo in buildMapContext.Report.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
{ {
var bundleName = bundleInfo.BundleName; var bundleName = bundleInfo.BundleName;
string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}"; string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}";
@ -114,7 +114,7 @@ namespace YooAsset.Editor
private List<PatchAsset> GetAllPatchAsset(TaskGetBuildMap.BuildMapContext buildMapContext, PatchManifest patchManifest) private List<PatchAsset> GetAllPatchAsset(TaskGetBuildMap.BuildMapContext buildMapContext, PatchManifest patchManifest)
{ {
List<PatchAsset> result = new List<PatchAsset>(1000); List<PatchAsset> result = new List<PatchAsset>(1000);
foreach (var bundleInfo in buildMapContext.Report.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
{ {
var assetInfos = bundleInfo.GetCollectAssetInfos(); var assetInfos = bundleInfo.GetCollectAssetInfos();
foreach (var assetInfo in assetInfos) foreach (var assetInfo in assetInfos)

View File

@ -77,17 +77,17 @@ namespace YooAsset.Editor
AppendData(content, ""); AppendData(content, "");
AppendData(content, $"--冗余列表--"); AppendData(content, $"--冗余列表--");
for (int i = 0; i < buildMapContext.Report.RedundancyList.Count; i++) for (int i = 0; i < buildMapContext.RedundancyList.Count; i++)
{ {
string redundancyAssetPath = buildMapContext.Report.RedundancyList[i]; string redundancyAssetPath = buildMapContext.RedundancyList[i];
AppendData(content, redundancyAssetPath); AppendData(content, redundancyAssetPath);
} }
AppendData(content, ""); AppendData(content, "");
AppendData(content, $"--构建列表--"); AppendData(content, $"--构建列表--");
for (int i = 0; i < buildMapContext.Report.BundleInfos.Count; i++) for (int i = 0; i < buildMapContext.BundleInfos.Count; i++)
{ {
string bundleName = buildMapContext.Report.BundleInfos[i].BundleName; string bundleName = buildMapContext.BundleInfos[i].BundleName;
AppendData(content, bundleName); AppendData(content, bundleName);
} }

View File

@ -0,0 +1,54 @@
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset.Editor
{
/// <summary>
/// 创建报告文件
/// </summary>
public class TaskCreateReport : IBuildTask
{
void IBuildTask.Run(BuildContext context)
{
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
var buildMapContext = context.GetContextObject<TaskGetBuildMap.BuildMapContext>();
CreateReportFile(buildParameters, buildMapContext);
}
private void CreateReportFile(AssetBundleBuilder.BuildParametersContext buildParameters, TaskGetBuildMap.BuildMapContext buildMapContext)
{
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.BundleInfos = buildMapContext.BundleInfos;
buildReport.RedundancyList = buildMapContext.RedundancyList;
// 删除旧文件
string filePath = $"{buildParameters.PipelineOutputDirectory}/{ResourceSettingData.Setting.ReportFileName}";
if (File.Exists(filePath))
File.Delete(filePath);
BuildReport.Serialize(filePath, buildReport);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bd12814185b4c7044b0afd59f9c1c948
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -64,7 +64,7 @@ namespace YooAsset.Editor
UnityEngine.Debug.Log($"开始加密资源文件"); UnityEngine.Debug.Log($"开始加密资源文件");
int progressValue = 0; int progressValue = 0;
foreach (var bundleInfo in buildMapContext.Report.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
{ {
var bundleName = bundleInfo.BundleName; var bundleName = bundleInfo.BundleName;
string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}"; string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}";
@ -83,7 +83,7 @@ namespace YooAsset.Editor
} }
// 进度条 // 进度条
EditorTools.DisplayProgressBar("加密资源包", ++progressValue, buildMapContext.Report.BundleInfos.Count); EditorTools.DisplayProgressBar("加密资源包", ++progressValue, buildMapContext.BundleInfos.Count);
} }
EditorTools.ClearProgressBar(); EditorTools.ClearProgressBar();

View File

@ -11,14 +11,23 @@ namespace YooAsset.Editor
{ {
public class BuildMapContext : IContextObject public class BuildMapContext : IContextObject
{ {
public BuildReport Report = new BuildReport(); /// <summary>
/// 资源包列表
/// </summary>
public readonly List<BuildBundleInfo> BundleInfos = new List<BuildBundleInfo>(1000);
/// <summary>
/// 冗余的资源列表
/// </summary>
public readonly List<string> RedundancyList = new List<string>(1000);
/// <summary> /// <summary>
/// 添加一个打包资源 /// 添加一个打包资源
/// </summary> /// </summary>
public void PackAsset(BuildAssetInfo assetInfo) public void PackAsset(BuildAssetInfo assetInfo)
{ {
if (Report.TryGetBundleInfo(assetInfo.BundleName, out BuildBundleInfo bundleInfo)) if (TryGetBundleInfo(assetInfo.BundleName, out BuildBundleInfo bundleInfo))
{ {
bundleInfo.PackAsset(assetInfo); bundleInfo.PackAsset(assetInfo);
} }
@ -26,7 +35,7 @@ namespace YooAsset.Editor
{ {
BuildBundleInfo newBundleInfo = new BuildBundleInfo(assetInfo.BundleName); BuildBundleInfo newBundleInfo = new BuildBundleInfo(assetInfo.BundleName);
newBundleInfo.PackAsset(assetInfo); newBundleInfo.PackAsset(assetInfo);
Report.BundleInfos.Add(newBundleInfo); BundleInfos.Add(newBundleInfo);
} }
} }
@ -35,8 +44,8 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public List<BuildAssetInfo> GetAllAssets() public List<BuildAssetInfo> GetAllAssets()
{ {
List<BuildAssetInfo> result = new List<BuildAssetInfo>(Report.BundleInfos.Count); List<BuildAssetInfo> result = new List<BuildAssetInfo>(BundleInfos.Count);
foreach (var bundleInfo in Report.BundleInfos) foreach (var bundleInfo in BundleInfos)
{ {
result.AddRange(bundleInfo.Assets); result.AddRange(bundleInfo.Assets);
} }
@ -48,7 +57,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public string[] GetAssetTags(string bundleFullName) public string[] GetAssetTags(string bundleFullName)
{ {
if (Report.TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo)) if (TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo))
{ {
return bundleInfo.GetAssetTags(); return bundleInfo.GetAssetTags();
} }
@ -60,7 +69,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public string[] GetBuildinAssetPaths(string bundleFullName) public string[] GetBuildinAssetPaths(string bundleFullName)
{ {
if (Report.TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo)) if (TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo))
{ {
return bundleInfo.GetBuildinAssetPaths(); return bundleInfo.GetBuildinAssetPaths();
} }
@ -72,14 +81,36 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public UnityEditor.AssetBundleBuild[] GetPipelineBuilds() public UnityEditor.AssetBundleBuild[] GetPipelineBuilds()
{ {
List<UnityEditor.AssetBundleBuild> builds = new List<UnityEditor.AssetBundleBuild>(Report.BundleInfos.Count); List<UnityEditor.AssetBundleBuild> builds = new List<UnityEditor.AssetBundleBuild>(BundleInfos.Count);
foreach (var bundleInfo in Report.BundleInfos) foreach (var bundleInfo in BundleInfos)
{ {
if (bundleInfo.IsRawFile == false) if (bundleInfo.IsRawFile == false)
builds.Add(bundleInfo.CreatePipelineBuild()); builds.Add(bundleInfo.CreatePipelineBuild());
} }
return builds.ToArray(); return builds.ToArray();
} }
/// <summary>
/// 是否包含资源包
/// </summary>
public bool IsContainsBundle(string bundleFullName)
{
return TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo);
}
private bool TryGetBundleInfo(string bundleFullName, out BuildBundleInfo result)
{
foreach (var bundleInfo in BundleInfos)
{
if (bundleInfo.BundleName == bundleFullName)
{
result = bundleInfo;
return true;
}
}
result = null;
return false;
}
} }
@ -169,7 +200,7 @@ namespace YooAsset.Editor
if(redundancy.Check(buildAssetInfo.AssetPath)) if(redundancy.Check(buildAssetInfo.AssetPath))
{ {
undependentAssets.Add(buildAssetInfo); undependentAssets.Add(buildAssetInfo);
buildMapContext.Report.RedundancyList.Add(buildAssetInfo.AssetPath); buildMapContext.RedundancyList.Add(buildAssetInfo.AssetPath);
continue; continue;
} }
} }
@ -180,7 +211,7 @@ namespace YooAsset.Editor
if (AssetBundleCollectorSettingData.HasCollector(buildAssetInfo.AssetPath) == false) if (AssetBundleCollectorSettingData.HasCollector(buildAssetInfo.AssetPath) == false)
{ {
undependentAssets.Add(buildAssetInfo); undependentAssets.Add(buildAssetInfo);
buildMapContext.Report.RedundancyList.Add(buildAssetInfo.AssetPath); buildMapContext.RedundancyList.Add(buildAssetInfo.AssetPath);
} }
} }
} }
@ -237,7 +268,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private void CheckBuildMapContent(BuildMapContext buildMapContext) private void CheckBuildMapContent(BuildMapContext buildMapContext)
{ {
foreach (var bundleInfo in buildMapContext.Report.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
{ {
// 注意:原生文件资源包只能包含一个原生文件 // 注意:原生文件资源包只能包含一个原生文件
bool isRawFile = bundleInfo.IsRawFile; bool isRawFile = bundleInfo.IsRawFile;