Update AssetBundleBuilder
parent
52413ff376
commit
feb9a22083
|
@ -181,6 +181,7 @@ namespace YooAsset.Editor
|
|||
new TaskEncryption(), //加密资源文件
|
||||
new TaskCreatePatchManifest(), //创建清单文件
|
||||
new TaskCreateReadme(), //创建说明文件
|
||||
new TaskCreateReport(), //创建报告文件
|
||||
new TaskCreatePatchPackage(), //制作补丁包
|
||||
new TaskCopyBuildinFiles(), //拷贝内置文件
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
|
@ -10,40 +11,29 @@ namespace YooAsset.Editor
|
|||
[Serializable]
|
||||
public class BuildReport
|
||||
{
|
||||
/// <summary>
|
||||
/// 构建汇总信息
|
||||
/// </summary>
|
||||
public BuildSummary Summary = new BuildSummary();
|
||||
|
||||
/// <summary>
|
||||
/// 资源包列表
|
||||
/// </summary>
|
||||
public readonly List<BuildBundleInfo> BundleInfos = new List<BuildBundleInfo>(1000);
|
||||
public List<BuildBundleInfo> BundleInfos;
|
||||
|
||||
/// <summary>
|
||||
/// 冗余的资源列表
|
||||
/// </summary>
|
||||
public readonly List<string> RedundancyList = new List<string>(1000);
|
||||
public List<string> RedundancyList;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 检测是否包含BundleName
|
||||
/// 序列化
|
||||
/// </summary>
|
||||
public bool IsContainsBundle(string bundleFullName)
|
||||
public static void Serialize(string savePath, BuildReport buildReport)
|
||||
{
|
||||
return TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo);
|
||||
}
|
||||
|
||||
/// <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;
|
||||
string json = JsonUtility.ToJson(buildReport, true);
|
||||
FileUtility.CreateFile(savePath, json);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cc215f5628022c345be919a0e21fcc8c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -31,7 +31,7 @@ namespace YooAsset.Editor
|
|||
context.SetContextObject(unityManifestContext);
|
||||
|
||||
// 拷贝原生文件
|
||||
foreach (var bundleInfo in buildMapContext.Report.BundleInfos)
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
if (bundleInfo.IsRawFile)
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ namespace YooAsset.Editor
|
|||
|
||||
// 1. 过滤掉原生Bundle
|
||||
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)
|
||||
expectBundles.Add(bundleInfo);
|
||||
|
@ -77,7 +77,7 @@ namespace YooAsset.Editor
|
|||
// 3. 正向验证Bundle
|
||||
foreach (var bundleName in buildedBundles)
|
||||
{
|
||||
if (buildMapContext.Report.IsContainsBundle(bundleName) == false)
|
||||
if (buildMapContext.IsContainsBundle(bundleName) == false)
|
||||
{
|
||||
throw new Exception($"Should never get here !");
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace YooAsset.Editor
|
|||
oldPatchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
|
||||
}
|
||||
|
||||
foreach (var bundleInfo in buildMapContext.Report.BundleInfos)
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
var bundleName = bundleInfo.BundleName;
|
||||
string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}";
|
||||
|
@ -114,7 +114,7 @@ namespace YooAsset.Editor
|
|||
private List<PatchAsset> GetAllPatchAsset(TaskGetBuildMap.BuildMapContext buildMapContext, PatchManifest patchManifest)
|
||||
{
|
||||
List<PatchAsset> result = new List<PatchAsset>(1000);
|
||||
foreach (var bundleInfo in buildMapContext.Report.BundleInfos)
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
var assetInfos = bundleInfo.GetCollectAssetInfos();
|
||||
foreach (var assetInfo in assetInfos)
|
||||
|
|
|
@ -77,17 +77,17 @@ namespace YooAsset.Editor
|
|||
|
||||
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, "");
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bd12814185b4c7044b0afd59f9c1c948
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -64,7 +64,7 @@ namespace YooAsset.Editor
|
|||
|
||||
UnityEngine.Debug.Log($"开始加密资源文件");
|
||||
int progressValue = 0;
|
||||
foreach (var bundleInfo in buildMapContext.Report.BundleInfos)
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
var bundleName = bundleInfo.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();
|
||||
|
||||
|
|
|
@ -11,14 +11,23 @@ namespace YooAsset.Editor
|
|||
{
|
||||
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>
|
||||
public void PackAsset(BuildAssetInfo assetInfo)
|
||||
{
|
||||
if (Report.TryGetBundleInfo(assetInfo.BundleName, out BuildBundleInfo bundleInfo))
|
||||
if (TryGetBundleInfo(assetInfo.BundleName, out BuildBundleInfo bundleInfo))
|
||||
{
|
||||
bundleInfo.PackAsset(assetInfo);
|
||||
}
|
||||
|
@ -26,7 +35,7 @@ namespace YooAsset.Editor
|
|||
{
|
||||
BuildBundleInfo newBundleInfo = new BuildBundleInfo(assetInfo.BundleName);
|
||||
newBundleInfo.PackAsset(assetInfo);
|
||||
Report.BundleInfos.Add(newBundleInfo);
|
||||
BundleInfos.Add(newBundleInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -35,8 +44,8 @@ namespace YooAsset.Editor
|
|||
/// </summary>
|
||||
public List<BuildAssetInfo> GetAllAssets()
|
||||
{
|
||||
List<BuildAssetInfo> result = new List<BuildAssetInfo>(Report.BundleInfos.Count);
|
||||
foreach (var bundleInfo in Report.BundleInfos)
|
||||
List<BuildAssetInfo> result = new List<BuildAssetInfo>(BundleInfos.Count);
|
||||
foreach (var bundleInfo in BundleInfos)
|
||||
{
|
||||
result.AddRange(bundleInfo.Assets);
|
||||
}
|
||||
|
@ -48,7 +57,7 @@ namespace YooAsset.Editor
|
|||
/// </summary>
|
||||
public string[] GetAssetTags(string bundleFullName)
|
||||
{
|
||||
if (Report.TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo))
|
||||
if (TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo))
|
||||
{
|
||||
return bundleInfo.GetAssetTags();
|
||||
}
|
||||
|
@ -60,7 +69,7 @@ namespace YooAsset.Editor
|
|||
/// </summary>
|
||||
public string[] GetBuildinAssetPaths(string bundleFullName)
|
||||
{
|
||||
if (Report.TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo))
|
||||
if (TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo))
|
||||
{
|
||||
return bundleInfo.GetBuildinAssetPaths();
|
||||
}
|
||||
|
@ -72,14 +81,36 @@ namespace YooAsset.Editor
|
|||
/// </summary>
|
||||
public UnityEditor.AssetBundleBuild[] GetPipelineBuilds()
|
||||
{
|
||||
List<UnityEditor.AssetBundleBuild> builds = new List<UnityEditor.AssetBundleBuild>(Report.BundleInfos.Count);
|
||||
foreach (var bundleInfo in Report.BundleInfos)
|
||||
List<UnityEditor.AssetBundleBuild> builds = new List<UnityEditor.AssetBundleBuild>(BundleInfos.Count);
|
||||
foreach (var bundleInfo in BundleInfos)
|
||||
{
|
||||
if (bundleInfo.IsRawFile == false)
|
||||
builds.Add(bundleInfo.CreatePipelineBuild());
|
||||
}
|
||||
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))
|
||||
{
|
||||
undependentAssets.Add(buildAssetInfo);
|
||||
buildMapContext.Report.RedundancyList.Add(buildAssetInfo.AssetPath);
|
||||
buildMapContext.RedundancyList.Add(buildAssetInfo.AssetPath);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +211,7 @@ namespace YooAsset.Editor
|
|||
if (AssetBundleCollectorSettingData.HasCollector(buildAssetInfo.AssetPath) == false)
|
||||
{
|
||||
undependentAssets.Add(buildAssetInfo);
|
||||
buildMapContext.Report.RedundancyList.Add(buildAssetInfo.AssetPath);
|
||||
buildMapContext.RedundancyList.Add(buildAssetInfo.AssetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -237,7 +268,7 @@ namespace YooAsset.Editor
|
|||
/// </summary>
|
||||
private void CheckBuildMapContent(BuildMapContext buildMapContext)
|
||||
{
|
||||
foreach (var bundleInfo in buildMapContext.Report.BundleInfos)
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
// 注意:原生文件资源包只能包含一个原生文件
|
||||
bool isRawFile = bundleInfo.IsRawFile;
|
||||
|
|
Loading…
Reference in New Issue