Update AssetBundleBuilder

pull/4/head
hevinci 2022-03-21 14:46:43 +08:00
parent 73d1bc9eac
commit fa0009685d
8 changed files with 46 additions and 228 deletions

View File

@ -10,6 +10,8 @@ namespace YooAsset.Editor
{
public class BuildParametersContext : IContextObject
{
private readonly System.Diagnostics.Stopwatch _buildWatch = new System.Diagnostics.Stopwatch();
/// <summary>
/// 构建参数
/// </summary>
@ -67,6 +69,23 @@ namespace YooAsset.Editor
return opt;
}
/// <summary>
/// 获取构建的耗时(单位:秒)
/// </summary>
public int GetBuildingSeconds()
{
int seconds = (int)(_buildWatch.ElapsedMilliseconds / 1000);
return seconds;
}
public void BeginWatch()
{
_buildWatch.Start();
}
public void StopWatch()
{
_buildWatch.Stop();
}
}
private readonly BuildContext _buildContext = new BuildContext();
@ -91,7 +110,6 @@ namespace YooAsset.Editor
new TaskBuilding(), //开始执行构建
new TaskEncryption(), //加密资源文件
new TaskCreatePatchManifest(), //创建清单文件
new TaskCreateReadme(), //创建说明文件
new TaskCreateReport(), //创建报告文件
new TaskCreatePatchPackage(), //制作补丁包
new TaskCopyBuildinFiles(), //拷贝内置文件

View File

@ -26,6 +26,11 @@ namespace YooAsset.Editor
/// </summary>
public List<ReportBundleInfo> BundleInfos = new List<ReportBundleInfo>();
/// <summary>
/// 收集器信息列表
/// </summary>
public List<string> CollectorInfoList = new List<string>();
/// <summary>
/// 冗余的资源列表
/// </summary>

View File

@ -1,4 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
namespace YooAsset.Editor
@ -62,6 +64,7 @@ namespace YooAsset.Editor
// 构建结果
public int AssetFileTotalCount;
public int RedundancyAssetFileCount;
public int AllBundleTotalCount;
public long AllBundleTotalSize;
public int BuildinBundleTotalCount;

View File

@ -22,14 +22,6 @@ namespace YooAsset.Editor
string packageDirectory = buildParameters.GetPackageDirectory();
UnityEngine.Debug.Log($"开始拷贝补丁文件到补丁包目录:{packageDirectory}");
// 拷贝Readme文件
{
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{ResourceSettingData.Setting.ReadmeFileName}";
string destPath = $"{packageDirectory}/{ResourceSettingData.Setting.ReadmeFileName}";
EditorTools.CopyFile(sourcePath, destPath, true);
UnityEngine.Debug.Log($"拷贝Readme文件到{destPath}");
}
// 拷贝Report文件
{
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{ResourceSettingData.Setting.ReportFileName}";

View File

@ -1,205 +0,0 @@
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset.Editor
{
/// <summary>
/// 创建说明文件
/// </summary>
public class TaskCreateReadme : IBuildTask
{
void IBuildTask.Run(BuildContext context)
{
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
var buildMapContext = context.GetContextObject<TaskGetBuildMap.BuildMapContext>();
CreateReadmeFile(buildParameters, buildMapContext);
}
/// <summary>
/// 创建Readme文件到输出目录
/// </summary>
private void CreateReadmeFile(AssetBundleBuilder.BuildParametersContext buildParameters, TaskGetBuildMap.BuildMapContext buildMapContext)
{
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
// 删除旧文件
string filePath = $"{buildParameters.PipelineOutputDirectory}/{ResourceSettingData.Setting.ReadmeFileName}";
if (File.Exists(filePath))
File.Delete(filePath);
UnityEngine.Debug.Log($"创建说明文件:{filePath}");
StringBuilder content = new StringBuilder();
AppendData(content, $"构建时间:{DateTime.Now}");
AppendData(content, $"构建平台:{buildParameters.Parameters.BuildTarget}");
AppendData(content, $"构建版本:{buildParameters.Parameters.BuildVersion}");
AppendData(content, $"自动分包:{buildParameters.Parameters.EnableAutoCollect}");
AppendData(content, "");
AppendData(content, $"--着色器--");
AppendData(content, $"IsCollectAllShaders{AssetBundleCollectorSettingData.Setting.AutoCollectShaders}");
AppendData(content, $"ShadersBundleName{AssetBundleCollectorSettingData.Setting.ShadersBundleName}");
AppendData(content, "");
AppendData(content, $"--配置信息--");
for (int i = 0; i < AssetBundleCollectorSettingData.Setting.Collectors.Count; i++)
{
AssetBundleCollectorSetting.Collector wrapper = AssetBundleCollectorSettingData.Setting.Collectors[i];
AppendData(content, wrapper.ToString());
}
AppendData(content, "");
AppendData(content, $"--构建参数--");
AppendData(content, $"CompressOption{buildParameters.Parameters.CompressOption}");
AppendData(content, $"IsForceRebuild{buildParameters.Parameters.ForceRebuild}");
AppendData(content, $"BuildinTags{buildParameters.Parameters.BuildinTags}");
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, $"--构建信息--");
AppendData(content, $"参与构建的资源总数:{buildMapContext.GetAllAssets().Count}");
GetBundleFileCountAndTotalSize(patchManifest, out int fileCount1, out long fileTotalSize1);
AppendData(content, $"构建的资源包总数:{fileCount1} 文件总大小:{fileTotalSize1 / (1024 * 1024)}MB");
GetBuildinFileCountAndTotalSize(patchManifest, out int fileCount2, out long fileTotalSize2);
AppendData(content, $"内置的资源包总数:{fileCount2} 文件总大小:{fileTotalSize2 / (1024 * 1024)}MB");
GetNotBuildinFileCountAndTotalSize(patchManifest, out int fileCount3, out long fileTotalSize3);
AppendData(content, $"非内置的资源包总数:{fileCount3} 文件总大小:{fileTotalSize3 / (1024 * 1024)}MB");
GetEncryptedFileCountAndTotalSize(patchManifest, out int fileCount4, out long fileTotalSize4);
AppendData(content, $"加密的资源包总数:{fileCount4} 文件总大小:{fileTotalSize4 / (1024 * 1024)}MB");
GetRawFileCountAndTotalSize(patchManifest, out int fileCount5, out long fileTotalSize5);
AppendData(content, $"原生的资源包总数:{fileCount5} 文件总大小:{fileTotalSize5 / (1024 * 1024)}MB");
AppendData(content, "");
AppendData(content, $"--冗余列表--");
for (int i = 0; i < buildMapContext.RedundancyAssetList.Count; i++)
{
string redundancyAssetPath = buildMapContext.RedundancyAssetList[i];
AppendData(content, redundancyAssetPath);
}
AppendData(content, "");
AppendData(content, $"--构建列表--");
for (int i = 0; i < buildMapContext.BundleInfos.Count; i++)
{
string bundleName = buildMapContext.BundleInfos[i].BundleName;
AppendData(content, bundleName);
}
AppendData(content, "");
AppendData(content, $"--内置文件列表--");
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.IsBuildin)
{
AppendData(content, patchBundle.BundleName);
}
}
AppendData(content, "");
AppendData(content, $"--非内置文件列表--");
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.IsBuildin == false)
{
AppendData(content, patchBundle.BundleName);
}
}
AppendData(content, "");
AppendData(content, $"--加密文件列表--");
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.IsEncrypted)
{
AppendData(content, patchBundle.BundleName);
}
}
AppendData(content, "");
AppendData(content, $"--原生文件列表--");
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.IsRawFile)
{
AppendData(content, patchBundle.BundleName);
}
}
// 创建新文件
File.WriteAllText(filePath, content.ToString(), Encoding.UTF8);
}
private void AppendData(StringBuilder sb, string data)
{
sb.Append(data);
sb.Append("\r\n");
}
private void GetBundleFileCountAndTotalSize(PatchManifest patchManifest, out int fileCount, out long fileBytes)
{
fileCount = patchManifest.BundleList.Count;
fileBytes = 0;
foreach (var patchBundle in patchManifest.BundleList)
{
fileBytes += patchBundle.SizeBytes;
}
}
private void GetBuildinFileCountAndTotalSize(PatchManifest patchManifest, out int fileCount, out long fileBytes)
{
fileCount = 0;
fileBytes = 0;
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.IsBuildin)
{
fileCount++;
fileBytes += patchBundle.SizeBytes;
}
}
}
private void GetNotBuildinFileCountAndTotalSize(PatchManifest patchManifest, out int fileCount, out long fileBytes)
{
fileCount = 0;
fileBytes = 0;
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.IsBuildin == false)
{
fileCount++;
fileBytes += patchBundle.SizeBytes;
}
}
}
private void GetEncryptedFileCountAndTotalSize(PatchManifest patchManifest, out int fileCount, out long fileBytes)
{
fileCount = 0;
fileBytes = 0;
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.IsEncrypted)
{
fileCount++;
fileBytes += patchBundle.SizeBytes;
}
}
}
private void GetRawFileCountAndTotalSize(PatchManifest patchManifest, out int fileCount, out long fileBytes)
{
fileCount = 0;
fileBytes = 0;
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.IsRawFile)
{
fileCount++;
fileBytes += patchBundle.SizeBytes;
}
}
}
}
}

View File

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

View File

@ -20,12 +20,13 @@ namespace YooAsset.Editor
{
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
BuildReport buildReport = new BuildReport();
buildParameters.StopWatch();
// 概述信息
{
buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion;
buildReport.Summary.BuildTime = DateTime.Now.ToString();
buildReport.Summary.BuildSeconds = 0;
buildReport.Summary.BuildSeconds = buildParameters.GetBuildingSeconds();
buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget;
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion;
buildReport.Summary.EnableAutoCollect = buildParameters.Parameters.EnableAutoCollect;
@ -44,6 +45,7 @@ namespace YooAsset.Editor
// 构建结果
buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount;
buildReport.Summary.RedundancyAssetFileCount = buildMapContext.RedundancyAssetList.Count;
buildReport.Summary.AllBundleTotalCount = GetAllBundleCount(patchManifest);
buildReport.Summary.AllBundleTotalSize = GetAllBundleSize(patchManifest);
buildReport.Summary.BuildinBundleTotalCount = GetBuildinBundleCount(patchManifest);
@ -52,6 +54,8 @@ namespace YooAsset.Editor
buildReport.Summary.EncryptedBundleTotalSize = GetEncryptedBundleSize(patchManifest);
buildReport.Summary.RawBundleTotalCount = GetRawBundleCount(patchManifest);
buildReport.Summary.RawBundleTotalSize = GetRawBundleSize(patchManifest);
}
// 资源对象列表
@ -82,8 +86,19 @@ namespace YooAsset.Editor
buildReport.BundleInfos.Add(reportBundleInfo);
}
// 收集器列表
for (int i = 0; i < AssetBundleCollectorSettingData.Setting.Collectors.Count; i++)
{
var wrapper = AssetBundleCollectorSettingData.Setting.Collectors[i];
buildReport.CollectorInfoList.Add(wrapper.ToString());
}
// 冗余资源列表
buildReport.RedundancyAssetList = buildMapContext.RedundancyAssetList;
for (int i = 0; i < buildMapContext.RedundancyAssetList.Count; i++)
{
string redundancyAssetPath = buildMapContext.RedundancyAssetList[i];
buildReport.RedundancyAssetList.Add(redundancyAssetPath);
}
// 删除旧文件
string filePath = $"{buildParameters.PipelineOutputDirectory}/{ResourceSettingData.Setting.ReportFileName}";

View File

@ -10,7 +10,8 @@ namespace YooAsset.Editor
{
void IBuildTask.Run(BuildContext context)
{
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
var buildParameters = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
buildParameters.BeginWatch();
// 检测构建平台是否合法
if (buildParameters.Parameters.BuildTarget == BuildTarget.NoTarget)