parent
6de31e5ee9
commit
83164dfbe9
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
|
@ -39,51 +41,11 @@ namespace YooAsset.Editor
|
|||
var buildParametersContext = new BuildParametersContext(buildParameters);
|
||||
_buildContext.SetContextObject(buildParametersContext);
|
||||
|
||||
// 创建构建节点
|
||||
List<IBuildTask> pipeline;
|
||||
if (buildParameters.BuildPipeline == EBuildPipeline.BuiltinBuildPipeline)
|
||||
{
|
||||
pipeline = new List<IBuildTask>
|
||||
{
|
||||
new TaskPrepare(), //前期准备工作
|
||||
new TaskGetBuildMap(), //获取构建列表
|
||||
new TaskBuilding(), //开始执行构建
|
||||
new TaskCopyRawFile(), //拷贝原生文件
|
||||
new TaskVerifyBuildResult(), //验证构建结果
|
||||
new TaskEncryption(), //加密资源文件
|
||||
new TaskUpdateBundleInfo(), //更新资源包信息
|
||||
new TaskCreateManifest(), //创建清单文件
|
||||
new TaskCreateReport(), //创建报告文件
|
||||
new TaskCreatePackage(), //制作包裹
|
||||
new TaskCopyBuildinFiles(), //拷贝内置文件
|
||||
};
|
||||
}
|
||||
else if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||
{
|
||||
pipeline = new List<IBuildTask>
|
||||
{
|
||||
new TaskPrepare(), //前期准备工作
|
||||
new TaskGetBuildMap(), //获取构建列表
|
||||
new TaskBuilding_SBP(), //开始执行构建
|
||||
new TaskCopyRawFile(), //拷贝原生文件
|
||||
new TaskVerifyBuildResult_SBP(), //验证构建结果
|
||||
new TaskEncryption(), //加密资源文件
|
||||
new TaskUpdateBundleInfo(), //更新补丁信息
|
||||
new TaskCreateManifest(), //创建清单文件
|
||||
new TaskCreateReport(), //创建报告文件
|
||||
new TaskCreatePackage(), //制作补丁包
|
||||
new TaskCopyBuildinFiles(), //拷贝内置文件
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// 初始化日志
|
||||
BuildLogger.InitLogger(buildParameters.EnableLog);
|
||||
|
||||
// 执行构建流程
|
||||
var pipeline = GetBuildTasks(buildParameters.BuildPipeline);
|
||||
var buildResult = BuildRunner.Run(pipeline, _buildContext);
|
||||
if (buildResult.Success)
|
||||
{
|
||||
|
@ -99,5 +61,95 @@ namespace YooAsset.Editor
|
|||
|
||||
return buildResult;
|
||||
}
|
||||
|
||||
private List<IBuildTask> GetBuildTasks(EBuildPipeline buildPipeline)
|
||||
{
|
||||
// 获取任务节点的属性集合
|
||||
List<TaskAttribute> attrList = new List<TaskAttribute>();
|
||||
if (buildPipeline == EBuildPipeline.BuiltinBuildPipeline)
|
||||
{
|
||||
/*
|
||||
List<IBuildTask> pipeline = new List<IBuildTask>
|
||||
{
|
||||
new TaskPrepare(), //前期准备工作
|
||||
new TaskGetBuildMap(), //获取构建列表
|
||||
new TaskBuilding(), //开始执行构建
|
||||
new TaskCopyRawFile(), //拷贝原生文件
|
||||
new TaskVerifyBuildResult(), //验证构建结果
|
||||
new TaskEncryption(), //加密资源文件
|
||||
new TaskUpdateBundleInfo(), //更新资源包信息
|
||||
new TaskCreateManifest(), //创建清单文件
|
||||
new TaskCreateReport(), //创建报告文件
|
||||
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);
|
||||
}
|
||||
}
|
||||
else if (buildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||
{
|
||||
/*
|
||||
List<IBuildTask> pipeline = new List<IBuildTask>
|
||||
{
|
||||
new TaskPrepare(), //前期准备工作
|
||||
new TaskGetBuildMap(), //获取构建列表
|
||||
new TaskBuilding_SBP(), //开始执行构建
|
||||
new TaskCopyRawFile(), //拷贝原生文件
|
||||
new TaskVerifyBuildResult_SBP(), //验证构建结果
|
||||
new TaskEncryption(), //加密资源文件
|
||||
new TaskUpdateBundleInfo(), //更新补丁信息
|
||||
new TaskCreateManifest(), //创建清单文件
|
||||
new TaskCreateReport(), //创建报告文件
|
||||
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);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -38,7 +38,7 @@ namespace YooAsset.Editor
|
|||
_buildWatch = Stopwatch.StartNew();
|
||||
var taskAttribute = task.GetType().GetCustomAttribute<TaskAttribute>();
|
||||
if (taskAttribute != null)
|
||||
BuildLogger.Log($"---------------------------------------->{taskAttribute.Desc}<---------------------------------------");
|
||||
BuildLogger.Log($"---------------------------------------->{taskAttribute.TaskDesc}<---------------------------------------");
|
||||
task.Run(context);
|
||||
_buildWatch.Stop();
|
||||
|
||||
|
@ -46,7 +46,7 @@ namespace YooAsset.Editor
|
|||
int seconds = GetBuildSeconds();
|
||||
TotalSeconds += seconds;
|
||||
if (taskAttribute != null)
|
||||
BuildLogger.Log($"{taskAttribute.Desc}耗时:{seconds}秒");
|
||||
BuildLogger.Log($"{taskAttribute.TaskDesc}耗时:{seconds}秒");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public enum ETaskPipeline
|
||||
{
|
||||
/// <summary>
|
||||
/// 所有的构建管线
|
||||
/// </summary>
|
||||
AllPipeline,
|
||||
|
||||
/// <summary>
|
||||
/// 内置构建管线
|
||||
/// </summary>
|
||||
BuiltinBuildPipeline,
|
||||
|
||||
/// <summary>
|
||||
/// 可编程构建管线
|
||||
/// </summary>
|
||||
ScriptableBuildPipeline,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 32477ef3a448a9144aa1574a052fe54e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -5,10 +5,29 @@ namespace YooAsset.Editor
|
|||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class TaskAttribute : Attribute
|
||||
{
|
||||
public string Desc;
|
||||
public TaskAttribute(string desc)
|
||||
/// <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)
|
||||
{
|
||||
Desc = desc;
|
||||
Pipeline = pipeline;
|
||||
TaskOrder = taskOrder;
|
||||
TaskDesc = taskDesc;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,7 +7,7 @@ using UnityEngine;
|
|||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("资源构建内容打包")]
|
||||
[TaskAttribute(ETaskPipeline.BuiltinBuildPipeline, 300, "资源构建内容打包")]
|
||||
public class TaskBuilding : IBuildTask
|
||||
{
|
||||
public class BuildResultContext : IContextObject
|
||||
|
|
|
@ -9,7 +9,7 @@ using UnityEditor.Build.Pipeline.Tasks;
|
|||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("资源构建内容打包")]
|
||||
[TaskAttribute(ETaskPipeline.ScriptableBuildPipeline, 300, "资源构建内容打包")]
|
||||
public class TaskBuilding_SBP : IBuildTask
|
||||
{
|
||||
public class BuildResultContext : IContextObject
|
||||
|
|
|
@ -6,7 +6,7 @@ using UnityEngine;
|
|||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("拷贝内置文件到流目录")]
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 1100, "拷贝内置文件到流目录")]
|
||||
public class TaskCopyBuildinFiles : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
@ -69,7 +69,7 @@ namespace YooAsset.Editor
|
|||
|
||||
// 拷贝文件列表(所有文件)
|
||||
if (option == ECopyBuildinFileOption.ClearAndCopyAll || option == ECopyBuildinFileOption.OnlyCopyAll)
|
||||
{
|
||||
{
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
string sourcePath = $"{packageOutputDirectory}/{packageBundle.FileName}";
|
||||
|
|
|
@ -5,7 +5,7 @@ using System.Collections.Generic;
|
|||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("拷贝原生文件")]
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 400, "拷贝原生文件")]
|
||||
public class TaskCopyRawFile : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace YooAsset.Editor
|
|||
internal PackageManifest Manifest;
|
||||
}
|
||||
|
||||
[TaskAttribute("创建清单文件")]
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 800, "创建清单文件")]
|
||||
public class TaskCreateManifest : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("制作包裹")]
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 1000, "制作包裹")]
|
||||
public class TaskCreatePackage : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
|
|
@ -6,7 +6,7 @@ using UnityEditor;
|
|||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("创建构建报告文件")]
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 900, "创建构建报告文件")]
|
||||
public class TaskCreateReport : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
|
|
@ -6,7 +6,7 @@ using System.Collections.Generic;
|
|||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("资源包加密")]
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 600, "资源包加密")]
|
||||
public class TaskEncryption : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
|
|
@ -7,7 +7,7 @@ using UnityEditor;
|
|||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("获取资源构建内容")]
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 200, "获取资源构建内容")]
|
||||
public class TaskGetBuildMap : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
|
|
@ -6,7 +6,7 @@ using UnityEditor;
|
|||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("资源构建准备工作")]
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 100, "资源构建准备工作")]
|
||||
public class TaskPrepare : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
|
|
@ -6,7 +6,7 @@ using UnityEditor;
|
|||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("更新资源包信息")]
|
||||
[TaskAttribute(ETaskPipeline.AllPipeline, 700, "更新资源包信息")]
|
||||
public class TaskUpdateBundleInfo : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
|
|
@ -8,7 +8,7 @@ using UnityEngine;
|
|||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("验证构建结果")]
|
||||
[TaskAttribute(ETaskPipeline.BuiltinBuildPipeline, 500, "验证构建结果")]
|
||||
public class TaskVerifyBuildResult : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
|
|
@ -9,7 +9,7 @@ using UnityEditor.Build.Pipeline.Interfaces;
|
|||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
[TaskAttribute("验证构建结果")]
|
||||
[TaskAttribute(ETaskPipeline.ScriptableBuildPipeline, 500, "验证构建结果")]
|
||||
public class TaskVerifyBuildResult_SBP : IBuildTask
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
|
|
|
@ -35,10 +35,20 @@ namespace YooAsset.Editor
|
|||
TypeCache.TypeCollection collection = TypeCache.GetTypesDerivedFrom(parentType);
|
||||
return collection.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取带有指定属性的所有类的类型
|
||||
/// </summary>
|
||||
public static List<Type> GetTypesWithAttribute(System.Type attrType)
|
||||
{
|
||||
TypeCache.TypeCollection collection = TypeCache.GetTypesWithAttribute(attrType);
|
||||
return collection.ToList();
|
||||
}
|
||||
#else
|
||||
private static readonly List<Type> _cacheTypes = new List<Type>(10000);
|
||||
private static void InitAssembly()
|
||||
{
|
||||
_cacheTypes.Clear();
|
||||
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
|
||||
foreach (Assembly assembly in assemblies)
|
||||
{
|
||||
|
@ -65,6 +75,23 @@ namespace YooAsset.Editor
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取带有指定属性的所有类的类型
|
||||
/// </summary>
|
||||
public static List<Type> GetTypesWithAttribute(System.Type attrType)
|
||||
{
|
||||
List<Type> result = new List<Type>();
|
||||
for (int i = 0; i < _cacheTypes.Count; i++)
|
||||
{
|
||||
Type type = _cacheTypes[i];
|
||||
if (type.GetCustomAttribute(attrType) != null)
|
||||
{
|
||||
result.Add(type);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
|
@ -213,11 +240,11 @@ namespace YooAsset.Editor
|
|||
public static void FocusUnitySceneWindow()
|
||||
{
|
||||
EditorWindow.FocusWindowIfItsOpen<SceneView>();
|
||||
}
|
||||
public static void CloseUnityGameWindow()
|
||||
{
|
||||
System.Type T = Assembly.Load("UnityEditor").GetType("UnityEditor.GameView");
|
||||
EditorWindow.GetWindow(T, false, "GameView", true).Close();
|
||||
}
|
||||
public static void CloseUnityGameWindow()
|
||||
{
|
||||
System.Type T = Assembly.Load("UnityEditor").GetType("UnityEditor.GameView");
|
||||
EditorWindow.GetWindow(T, false, "GameView", true).Close();
|
||||
}
|
||||
public static void FocusUnityGameWindow()
|
||||
{
|
||||
|
@ -399,7 +426,7 @@ namespace YooAsset.Editor
|
|||
FileInfo fileInfo = new FileInfo(filePath);
|
||||
fileInfo.MoveTo(destPath);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 拷贝文件夹
|
||||
/// 注意:包括所有子目录的文件
|
||||
|
|
Loading…
Reference in New Issue