update AssetBundleBuilder

1. 移除了资源包构建流程任务节点可扩展功能
2. 新增了构建流程可扩展的方法。
mlyDevMerge1.5.7
hevinci 2023-06-29 10:53:07 +08:00 committed by QiJing
parent 99f89b3c44
commit 480325827b
17 changed files with 39 additions and 117 deletions

View File

@ -13,17 +13,18 @@ namespace YooAsset.Editor
private readonly BuildContext _buildContext = new BuildContext();
/// <summary>
/// 开始构建
/// 构建资源包
/// </summary>
public BuildResult Run(BuildParameters buildParameters)
public BuildResult Run(BuildParameters buildParameters, List<IBuildTask> buildPipeline)
{
// 清空旧数据
_buildContext.ClearAllContext();
// 检测构建参数是否为空
if (buildParameters == null)
throw new Exception($"{nameof(buildParameters)} is null !");
// 检测构建参数是否为空
if (buildPipeline.Count == 0)
throw new Exception($"Build pipeline is empty !");
// 检测可编程构建管线参数
if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{
@ -37,6 +38,9 @@ namespace YooAsset.Editor
throw new Exception($"{nameof(EBuildPipeline.ScriptableBuildPipeline)} not support {nameof(EBuildMode.ForceRebuild)} build mode !");
}
// 清空旧数据
_buildContext.ClearAllContext();
// 构建参数
var buildParametersContext = new BuildParametersContext(buildParameters);
_buildContext.SetContextObject(buildParametersContext);
@ -45,8 +49,7 @@ namespace YooAsset.Editor
BuildLogger.InitLogger(buildParameters.EnableLog);
// 执行构建流程
var pipeline = GetBuildTasks(buildParameters.BuildPipeline);
var buildResult = BuildRunner.Run(pipeline, _buildContext);
var buildResult = BuildRunner.Run(buildPipeline, _buildContext);
if (buildResult.Success)
{
buildResult.OutputPackageDirectory = buildParametersContext.GetPackageOutputDirectory();
@ -62,13 +65,23 @@ namespace YooAsset.Editor
return buildResult;
}
private List<IBuildTask> GetBuildTasks(EBuildPipeline buildPipeline)
/// <summary>
/// 构建资源包
/// </summary>
public BuildResult Run(BuildParameters buildParameters)
{
var buildPipeline = GetDefaultBuildPipeline(buildParameters.BuildPipeline);
return Run(buildParameters, buildPipeline);
}
/// <summary>
/// 获取默认的构建流程
/// </summary>
private List<IBuildTask> GetDefaultBuildPipeline(EBuildPipeline buildPipeline)
{
// 获取任务节点的属性集合
List<TaskAttribute> attrList = new List<TaskAttribute>();
if (buildPipeline == EBuildPipeline.BuiltinBuildPipeline)
{
/*
List<IBuildTask> pipeline = new List<IBuildTask>
{
new TaskPrepare(), //前期准备工作
@ -83,23 +96,10 @@ namespace YooAsset.Editor
new TaskCreatePackage(), //制作包裹
new TaskCopyBuildinFiles(), //拷贝内置文件
};
*/
var classTypes = EditorTools.GetAssignableTypes(typeof(IBuildTask));
foreach (var classType in classTypes)
{
var attribute = classType.GetCustomAttribute<TaskAttribute>();
if (attribute == null)
throw new Exception($"Not found {nameof(TaskAttribute)} int type : {classType.FullName}");
attribute.ClassType = classType;
if (attribute.Pipeline == ETaskPipeline.AllPipeline || attribute.Pipeline == ETaskPipeline.BuiltinBuildPipeline)
attrList.Add(attribute);
}
return pipeline;
}
else if (buildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{
/*
List<IBuildTask> pipeline = new List<IBuildTask>
{
new TaskPrepare(), //前期准备工作
@ -114,42 +114,12 @@ namespace YooAsset.Editor
new TaskCreatePackage(), //制作补丁包
new TaskCopyBuildinFiles(), //拷贝内置文件
};
*/
var classTypes = EditorTools.GetAssignableTypes(typeof(IBuildTask));
foreach (var classType in classTypes)
{
var attribute = classType.GetCustomAttribute<TaskAttribute>();
if (attribute == null)
throw new Exception($"Not found {nameof(TaskAttribute)} int type : {classType.FullName}");
attribute.ClassType = classType;
if (attribute.Pipeline == ETaskPipeline.AllPipeline || attribute.Pipeline == ETaskPipeline.ScriptableBuildPipeline)
attrList.Add(attribute);
}
return pipeline;
}
else
{
throw new NotImplementedException();
}
// 对任务节点进行排序
attrList.Sort((a, b) =>
{
if (a.TaskOrder > b.TaskOrder) { return 1; }
else if (a.TaskOrder < b.TaskOrder) { return -1; }
else { return 0; }
});
// 创建任务节点实例
List<IBuildTask> pipeline = new List<IBuildTask>(attrList.Count);
foreach (var taskAttr in attrList)
{
var task = Activator.CreateInstance(taskAttr.ClassType) as IBuildTask;
pipeline.Add(task);
}
return pipeline;
}
}
}

View File

@ -1,22 +0,0 @@
using System;
namespace YooAsset.Editor
{
public enum ETaskPipeline
{
/// <summary>
/// 所有的构建管线
/// </summary>
AllPipeline,
/// <summary>
/// 内置构建管线
/// </summary>
BuiltinBuildPipeline,
/// <summary>
/// 可编程构建管线
/// </summary>
ScriptableBuildPipeline,
}
}

View File

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

View File

@ -5,28 +5,13 @@ namespace YooAsset.Editor
[AttributeUsage(AttributeTargets.Class)]
public class TaskAttribute : Attribute
{
/// <summary>
/// 任务所属的构建流水线
/// </summary>
public ETaskPipeline Pipeline;
/// <summary>
/// 执行顺序
/// </summary>
public int TaskOrder;
/// <summary>
/// 任务说明
/// </summary>
public string TaskDesc;
// 关联的任务类
public Type ClassType { set; get; }
public TaskAttribute(ETaskPipeline pipeline, int taskOrder, string taskDesc)
public TaskAttribute(string taskDesc)
{
Pipeline = pipeline;
TaskOrder = taskOrder;
TaskDesc = taskDesc;
}
}

View File

@ -7,7 +7,7 @@ using UnityEngine;
namespace YooAsset.Editor
{
[TaskAttribute(ETaskPipeline.BuiltinBuildPipeline, 300, "资源构建内容打包")]
[TaskAttribute("资源构建内容打包")]
public class TaskBuilding : IBuildTask
{
public class BuildResultContext : IContextObject

View File

@ -9,7 +9,7 @@ using UnityEditor.Build.Pipeline.Tasks;
namespace YooAsset.Editor
{
[TaskAttribute(ETaskPipeline.ScriptableBuildPipeline, 300, "资源构建内容打包")]
[TaskAttribute("资源构建内容打包")]
public class TaskBuilding_SBP : IBuildTask
{
public class BuildResultContext : IContextObject

View File

@ -6,7 +6,7 @@ using UnityEngine;
namespace YooAsset.Editor
{
[TaskAttribute(ETaskPipeline.AllPipeline, 1100, "拷贝内置文件到流目录")]
[TaskAttribute("拷贝内置文件到流目录")]
public class TaskCopyBuildinFiles : IBuildTask
{
void IBuildTask.Run(BuildContext context)

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
namespace YooAsset.Editor
{
[TaskAttribute(ETaskPipeline.AllPipeline, 400, "拷贝原生文件")]
[TaskAttribute("拷贝原生文件")]
public class TaskCopyRawFile : IBuildTask
{
void IBuildTask.Run(BuildContext context)

View File

@ -13,7 +13,7 @@ namespace YooAsset.Editor
internal PackageManifest Manifest;
}
[TaskAttribute(ETaskPipeline.AllPipeline, 800, "创建清单文件")]
[TaskAttribute("创建清单文件")]
public class TaskCreateManifest : IBuildTask
{
void IBuildTask.Run(BuildContext context)

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace YooAsset.Editor
{
[TaskAttribute(ETaskPipeline.AllPipeline, 1000, "制作包裹")]
[TaskAttribute("制作包裹")]
public class TaskCreatePackage : IBuildTask
{
void IBuildTask.Run(BuildContext context)

View File

@ -6,7 +6,7 @@ using UnityEditor;
namespace YooAsset.Editor
{
[TaskAttribute(ETaskPipeline.AllPipeline, 900, "创建构建报告文件")]
[TaskAttribute("创建构建报告文件")]
public class TaskCreateReport : IBuildTask
{
void IBuildTask.Run(BuildContext context)

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
namespace YooAsset.Editor
{
[TaskAttribute(ETaskPipeline.AllPipeline, 600, "资源包加密")]
[TaskAttribute("资源包加密")]
public class TaskEncryption : IBuildTask
{
void IBuildTask.Run(BuildContext context)

View File

@ -7,7 +7,7 @@ using UnityEditor;
namespace YooAsset.Editor
{
[TaskAttribute(ETaskPipeline.AllPipeline, 200, "获取资源构建内容")]
[TaskAttribute("获取资源构建内容")]
public class TaskGetBuildMap : IBuildTask
{
void IBuildTask.Run(BuildContext context)

View File

@ -6,7 +6,7 @@ using UnityEditor;
namespace YooAsset.Editor
{
[TaskAttribute(ETaskPipeline.AllPipeline, 100, "资源构建准备工作")]
[TaskAttribute("资源构建准备工作")]
public class TaskPrepare : IBuildTask
{
void IBuildTask.Run(BuildContext context)

View File

@ -6,7 +6,7 @@ using UnityEditor;
namespace YooAsset.Editor
{
[TaskAttribute(ETaskPipeline.AllPipeline, 700, "更新资源包信息")]
[TaskAttribute("更新资源包信息")]
public class TaskUpdateBundleInfo : IBuildTask
{
void IBuildTask.Run(BuildContext context)

View File

@ -8,7 +8,7 @@ using UnityEngine;
namespace YooAsset.Editor
{
[TaskAttribute(ETaskPipeline.BuiltinBuildPipeline, 500, "验证构建结果")]
[TaskAttribute("验证构建结果")]
public class TaskVerifyBuildResult : IBuildTask
{
void IBuildTask.Run(BuildContext context)

View File

@ -9,7 +9,7 @@ using UnityEditor.Build.Pipeline.Interfaces;
namespace YooAsset.Editor
{
[TaskAttribute(ETaskPipeline.ScriptableBuildPipeline, 500, "验证构建结果")]
[TaskAttribute("验证构建结果")]
public class TaskVerifyBuildResult_SBP : IBuildTask
{
void IBuildTask.Run(BuildContext context)