Update AssetBundleBuilder

pull/4/head
hevinci 2022-03-17 21:52:08 +08:00
parent 7cb0394785
commit 233e477bc8
7 changed files with 150 additions and 25 deletions

View File

@ -14,9 +14,10 @@ namespace YooAsset.Editor
public string BundleName { private set; get; } public string BundleName { private set; get; }
/// <summary> /// <summary>
/// 包含的资源列表 /// 参与构建的资源列表
/// 注意:不包含冗余资源或零依赖资源
/// </summary> /// </summary>
public readonly List<BuildAssetInfo> Assets = new List<BuildAssetInfo>(); public readonly List<BuildAssetInfo> BuildinAssets = new List<BuildAssetInfo>();
/// <summary> /// <summary>
/// 是否为原生文件 /// 是否为原生文件
@ -25,7 +26,7 @@ namespace YooAsset.Editor
{ {
get get
{ {
foreach (var asset in Assets) foreach (var asset in BuildinAssets)
{ {
if (asset.IsRawAsset) if (asset.IsRawAsset)
return true; return true;
@ -45,7 +46,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public bool IsContainsAsset(string assetPath) public bool IsContainsAsset(string assetPath)
{ {
foreach (var assetInfo in Assets) foreach (var assetInfo in BuildinAssets)
{ {
if (assetInfo.AssetPath == assetPath) if (assetInfo.AssetPath == assetPath)
{ {
@ -63,7 +64,7 @@ namespace YooAsset.Editor
if (IsContainsAsset(assetInfo.AssetPath)) if (IsContainsAsset(assetInfo.AssetPath))
throw new System.Exception($"Asset is existed : {assetInfo.AssetPath}"); throw new System.Exception($"Asset is existed : {assetInfo.AssetPath}");
Assets.Add(assetInfo); BuildinAssets.Add(assetInfo);
} }
/// <summary> /// <summary>
@ -82,8 +83,8 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public string[] GetAssetTags() public string[] GetAssetTags()
{ {
List<string> result = new List<string>(Assets.Count); List<string> result = new List<string>(BuildinAssets.Count);
foreach (var assetInfo in Assets) foreach (var assetInfo in BuildinAssets)
{ {
foreach (var assetTag in assetInfo.AssetTags) foreach (var assetTag in assetInfo.AssetTags)
{ {
@ -99,7 +100,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public string[] GetBuildinAssetPaths() public string[] GetBuildinAssetPaths()
{ {
return Assets.Select(t => t.AssetPath).ToArray(); return BuildinAssets.Select(t => t.AssetPath).ToArray();
} }
/// <summary> /// <summary>
@ -107,7 +108,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public BuildAssetInfo[] GetCollectAssetInfos() public BuildAssetInfo[] GetCollectAssetInfos()
{ {
return Assets.Where(t => t.IsCollectAsset).ToArray(); return BuildinAssets.Where(t => t.IsCollectAsset).ToArray();
} }
/// <summary> /// <summary>

View File

@ -17,14 +17,14 @@ namespace YooAsset.Editor
public BuildSummary Summary = new BuildSummary(); public BuildSummary Summary = new BuildSummary();
/// <summary> /// <summary>
/// 资源列表 /// 资源对象列表
/// </summary> /// </summary>
public List<ReportBundleInfo> BundleInfos; public List<ReportAssetInfo> AssetInfos = new List<ReportAssetInfo>();
/// <summary> /// <summary>
/// 冗余的资源列表 /// 资源列表
/// </summary> /// </summary>
public List<string> RedundancyList; public List<ReportBundleInfo> BundleInfos = new List<ReportBundleInfo>();
/// <summary> /// <summary>

View File

@ -7,6 +7,24 @@ namespace YooAsset.Editor
[Serializable] [Serializable]
public class ReportAssetInfo public class ReportAssetInfo
{ {
/// <summary>
/// 资源路径
/// </summary>
public string AssetPath;
/// <summary>
/// 所属资源包
/// </summary>
public string MainBundle;
/// <summary>
/// 依赖的资源包
/// </summary>
public List<string> DependBundles = new List<string>();
/// <summary>
/// 依赖的资源列表
/// </summary>
public List<string> DependAssets = new List<string>();
} }
} }

View File

@ -7,6 +7,39 @@ namespace YooAsset.Editor
[Serializable] [Serializable]
public class ReportBundleInfo public class ReportBundleInfo
{ {
/// <summary>
/// 资源包完整名称
/// </summary>
public string BundleName;
/// <summary>
/// 哈希值
/// </summary>
public string Hash;
/// <summary>
/// 文件校验码
/// </summary>
public string CRC;
/// <summary>
/// 文件大小(字节数)
/// </summary>
public long SizeBytes;
/// <summary>
/// 文件版本
/// </summary>
public int Version;
/// <summary>
/// Tags
/// </summary>
public string[] Tags;
/// <summary>
/// Flags
/// </summary>
public int Flags;
} }
} }

View File

@ -36,7 +36,7 @@ namespace YooAsset.Editor
if (bundleInfo.IsRawFile) if (bundleInfo.IsRawFile)
{ {
string dest = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; string dest = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}";
foreach(var buildAsset in bundleInfo.Assets) foreach(var buildAsset in bundleInfo.BuildinAssets)
{ {
if(buildAsset.IsRawAsset) if(buildAsset.IsRawAsset)
EditorTools.CopyFile(buildAsset.AssetPath, dest, true); EditorTools.CopyFile(buildAsset.AssetPath, dest, true);

View File

@ -1,8 +1,6 @@
using System; using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
@ -20,8 +18,10 @@ namespace YooAsset.Editor
private void CreateReportFile(AssetBundleBuilder.BuildParametersContext buildParameters, TaskGetBuildMap.BuildMapContext buildMapContext) private void CreateReportFile(AssetBundleBuilder.BuildParametersContext buildParameters, TaskGetBuildMap.BuildMapContext buildMapContext)
{ {
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
BuildReport buildReport = new BuildReport(); BuildReport buildReport = new BuildReport();
// 概述信息
buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion; buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion;
buildReport.Summary.BuildTime = DateTime.Now.ToString(); buildReport.Summary.BuildTime = DateTime.Now.ToString();
buildReport.Summary.BuildSeconds = 0; buildReport.Summary.BuildSeconds = 0;
@ -29,10 +29,8 @@ namespace YooAsset.Editor
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion; buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion;
buildReport.Summary.ApplyRedundancy = buildParameters.Parameters.ApplyRedundancy; buildReport.Summary.ApplyRedundancy = buildParameters.Parameters.ApplyRedundancy;
buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension; buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension;
buildReport.Summary.IsCollectAllShaders = AssetBundleCollectorSettingData.Setting.IsCollectAllShaders; buildReport.Summary.IsCollectAllShaders = AssetBundleCollectorSettingData.Setting.IsCollectAllShaders;
buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName; buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
buildReport.Summary.IsForceRebuild = buildParameters.Parameters.IsForceRebuild; buildReport.Summary.IsForceRebuild = buildParameters.Parameters.IsForceRebuild;
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags; buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption; buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption;
@ -41,14 +39,88 @@ namespace YooAsset.Editor
buildReport.Summary.IsIgnoreTypeTreeChanges = buildParameters.Parameters.IsIgnoreTypeTreeChanges; buildReport.Summary.IsIgnoreTypeTreeChanges = buildParameters.Parameters.IsIgnoreTypeTreeChanges;
buildReport.Summary.IsDisableLoadAssetByFileName = buildParameters.Parameters.IsDisableLoadAssetByFileName; buildReport.Summary.IsDisableLoadAssetByFileName = buildParameters.Parameters.IsDisableLoadAssetByFileName;
//buildReport.BundleInfos = buildMapContext.BundleInfos; // 资源对象列表
buildReport.RedundancyList = buildMapContext.RedundancyList; buildReport.AssetInfos = new List<ReportAssetInfo>(patchManifest.AssetList.Count);
foreach (var patchAsset in patchManifest.AssetList)
{
var mainBundle = patchManifest.BundleList[patchAsset.BundleID];
ReportAssetInfo reportAssetInfo = new ReportAssetInfo();
reportAssetInfo.AssetPath = patchAsset.AssetPath;
reportAssetInfo.MainBundle = mainBundle.BundleName;
reportAssetInfo.DependBundles = GetDependBundles(patchManifest, patchAsset);
reportAssetInfo.DependAssets = GetDependAssets(buildMapContext, mainBundle.BundleName, patchAsset.AssetPath);
buildReport.AssetInfos.Add(reportAssetInfo);
}
// 资源包列表
buildReport.BundleInfos = new List<ReportBundleInfo>(patchManifest.BundleList.Count);
foreach (var patchBundle in patchManifest.BundleList)
{
ReportBundleInfo reportBundleInfo = new ReportBundleInfo();
reportBundleInfo.BundleName = patchBundle.BundleName;
reportBundleInfo.Hash = patchBundle.Hash;
reportBundleInfo.CRC = patchBundle.CRC;
reportBundleInfo.SizeBytes = patchBundle.SizeBytes;
reportBundleInfo.Version = patchBundle.Version;
reportBundleInfo.Tags = patchBundle.Tags;
reportBundleInfo.Flags = patchBundle.Flags;
buildReport.BundleInfos.Add(reportBundleInfo);
}
// 删除旧文件 // 删除旧文件
string filePath = $"{buildParameters.PipelineOutputDirectory}/{ResourceSettingData.Setting.ReportFileName}"; string filePath = $"{buildParameters.PipelineOutputDirectory}/{ResourceSettingData.Setting.ReportFileName}";
if (File.Exists(filePath)) if (File.Exists(filePath))
File.Delete(filePath); File.Delete(filePath);
// 序列化文件
BuildReport.Serialize(filePath, buildReport); BuildReport.Serialize(filePath, buildReport);
} }
/// <summary>
/// 获取资源对象依赖的所有资源包
/// </summary>
private List<string> GetDependBundles(PatchManifest patchManifest, PatchAsset patchAsset)
{
List<string> dependBundles = new List<string>(patchAsset.DependIDs.Length);
foreach(int index in patchAsset.DependIDs)
{
string dependBundleName = patchManifest.BundleList[index].BundleName;
dependBundles.Add(dependBundleName);
}
return dependBundles;
}
/// <summary>
/// 获取资源对象依赖的其它所有资源
/// </summary>
private List<string> GetDependAssets(TaskGetBuildMap.BuildMapContext buildMapContext, string bundleName, string assetPath)
{
List<string> result = new List<string>();
if(buildMapContext.TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
{
BuildAssetInfo findAssetInfo = null;
foreach(var buildinAsset in bundleInfo.BuildinAssets)
{
if(buildinAsset.AssetPath == assetPath)
{
findAssetInfo = buildinAsset;
break;
}
}
if (findAssetInfo == null)
{
throw new Exception($"Not found asset {assetPath} in bunlde {bundleName}");
}
foreach(var dependAssetInfo in findAssetInfo.AllDependAssetInfos)
{
result.Add(dependAssetInfo.AssetPath);
}
}
else
{
throw new Exception($"Not found bundle : {bundleName}");
}
return result;
}
} }
} }

View File

@ -47,7 +47,7 @@ namespace YooAsset.Editor
List<BuildAssetInfo> result = new List<BuildAssetInfo>(BundleInfos.Count); List<BuildAssetInfo> result = new List<BuildAssetInfo>(BundleInfos.Count);
foreach (var bundleInfo in BundleInfos) foreach (var bundleInfo in BundleInfos)
{ {
result.AddRange(bundleInfo.Assets); result.AddRange(bundleInfo.BuildinAssets);
} }
return result; return result;
} }
@ -98,7 +98,7 @@ namespace YooAsset.Editor
return TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo); return TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo);
} }
private bool TryGetBundleInfo(string bundleFullName, out BuildBundleInfo result) public bool TryGetBundleInfo(string bundleFullName, out BuildBundleInfo result)
{ {
foreach (var bundleInfo in BundleInfos) foreach (var bundleInfo in BundleInfos)
{ {
@ -188,6 +188,7 @@ namespace YooAsset.Editor
if (buildAssetInfo.IsCollectAsset) if (buildAssetInfo.IsCollectAsset)
continue; continue;
// 零依赖资源
if (buildAssetInfo.DependCount == 0) if (buildAssetInfo.DependCount == 0)
{ {
undependentAssets.Add(buildAssetInfo); undependentAssets.Add(buildAssetInfo);
@ -274,13 +275,13 @@ namespace YooAsset.Editor
bool isRawFile = bundleInfo.IsRawFile; bool isRawFile = bundleInfo.IsRawFile;
if (isRawFile) if (isRawFile)
{ {
if (bundleInfo.Assets.Count != 1) if (bundleInfo.BuildinAssets.Count != 1)
throw new Exception("The bundle does not support multiple raw asset : {bundleInfo.BundleName}"); throw new Exception("The bundle does not support multiple raw asset : {bundleInfo.BundleName}");
continue; continue;
} }
// 注意:原生文件不能被其它资源文件依赖 // 注意:原生文件不能被其它资源文件依赖
foreach (var assetInfo in bundleInfo.Assets) foreach (var assetInfo in bundleInfo.BuildinAssets)
{ {
if (assetInfo.AllDependAssetInfos != null) if (assetInfo.AllDependAssetInfos != null)
{ {