Optimize packaging bundle core logic

优化了打包的核心逻辑,支持设置依赖资源收集器。
This commit is contained in:
hevinci
2022-04-30 23:14:20 +08:00
parent b443a1c308
commit 650d8689ee
22 changed files with 162 additions and 85 deletions
@@ -8,6 +8,7 @@ using UnityEngine;
namespace YooAsset.Editor
{
[TaskAttribute("资源构建内容打包")]
public class TaskBuilding : IBuildTask
{
public class UnityManifestContext : IContextObject
@@ -20,12 +21,12 @@ namespace YooAsset.Editor
var buildParametersContext = context.GetContextObject<AssetBundleBuilder.BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>();
Debug.Log($"开始构建......");
BuildAssetBundleOptions opt = buildParametersContext.GetPipelineBuildOptions();
AssetBundleManifest unityManifest = BuildPipeline.BuildAssetBundles(buildParametersContext.PipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), opt, buildParametersContext.Parameters.BuildTarget);
if (unityManifest == null)
throw new Exception("构建过程中发生错误!");
Debug.Log("Unity引擎打包成功!");
UnityManifestContext unityManifestContext = new UnityManifestContext();
unityManifestContext.UnityManifest = unityManifest;
context.SetContextObject(unityManifestContext);
@@ -6,9 +6,7 @@ using UnityEngine;
namespace YooAsset.Editor
{
/// <summary>
/// 拷贝内置文件到StreamingAssets
/// </summary>
[TaskAttribute("拷贝内置文件到流目录")]
public class TaskCopyBuildinFiles : IBuildTask
{
void IBuildTask.Run(BuildContext context)
@@ -38,7 +36,6 @@ namespace YooAsset.Editor
string sourcePath = $"{pipelineOutputDirectory}/{patchBundle.BundleName}";
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{patchBundle.Hash}";
Debug.Log($"拷贝内置文件到流目录:{patchBundle.BundleName}");
EditorTools.CopyFile(sourcePath, destPath, true);
}
@@ -65,6 +62,7 @@ namespace YooAsset.Editor
// 刷新目录
AssetDatabase.Refresh();
Debug.Log($"内置文件拷贝完成:{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}");
}
}
}
@@ -5,9 +5,7 @@ using System.Collections.Generic;
namespace YooAsset.Editor
{
/// <summary>
/// 创建补丁清单文件
/// </summary>
[TaskAttribute("创建补丁清单文件")]
public class TaskCreatePatchManifest : IBuildTask
{
void IBuildTask.Run(BuildContext context)
@@ -3,9 +3,7 @@ using System.Collections.Generic;
namespace YooAsset.Editor
{
/// <summary>
/// 制作补丁包
/// </summary>
[TaskAttribute("制作补丁包")]
public class TaskCreatePatchPackage : IBuildTask
{
void IBuildTask.Run(BuildContext context)
@@ -24,7 +22,7 @@ namespace YooAsset.Editor
{
int resourceVersion = buildParameters.Parameters.BuildVersion;
string packageDirectory = buildParameters.GetPackageDirectory();
UnityEngine.Debug.Log($"准备开始拷贝补丁文件到补丁包目录:{packageDirectory}");
UnityEngine.Debug.Log($"开始拷贝补丁文件到补丁包目录:{packageDirectory}");
// 拷贝Report文件
{
@@ -32,7 +30,6 @@ namespace YooAsset.Editor
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{reportFileName}";
string destPath = $"{packageDirectory}/{reportFileName}";
EditorTools.CopyFile(sourcePath, destPath, true);
UnityEngine.Debug.Log($"拷贝构建报告文件到:{destPath}");
}
// 拷贝补丁清单文件
@@ -40,7 +37,6 @@ namespace YooAsset.Editor
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
string destPath = $"{packageDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}";
EditorTools.CopyFile(sourcePath, destPath, true);
UnityEngine.Debug.Log($"拷贝补丁清单文件到:{destPath}");
}
// 拷贝补丁清单哈希文件
@@ -48,7 +44,6 @@ namespace YooAsset.Editor
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}";
string destPath = $"{packageDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}";
EditorTools.CopyFile(sourcePath, destPath, true);
UnityEngine.Debug.Log($"拷贝补丁清单哈希文件到:{destPath}");
}
// 拷贝静态版本文件
@@ -56,7 +51,6 @@ namespace YooAsset.Editor
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}";
string destPath = $"{packageDirectory}/{YooAssetSettings.VersionFileName}";
EditorTools.CopyFile(sourcePath, destPath, true);
UnityEngine.Debug.Log($"拷贝静态版本文件到:{destPath}");
}
// 拷贝UnityManifest序列化文件
@@ -64,7 +58,6 @@ namespace YooAsset.Editor
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
string destPath = $"{packageDirectory}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
EditorTools.CopyFile(sourcePath, destPath, true);
UnityEngine.Debug.Log($"拷贝UnityManifest文件到:{destPath}");
}
// 拷贝UnityManifest文本文件
@@ -83,7 +76,6 @@ namespace YooAsset.Editor
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{patchBundle.BundleName}";
string destPath = $"{packageDirectory}/{patchBundle.Hash}";
EditorTools.CopyFile(sourcePath, destPath, true);
UnityEngine.Debug.Log($"拷贝补丁文件到补丁包:{patchBundle.BundleName}");
EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, patchFileTotalCount);
}
EditorTools.ClearProgressBar();
@@ -4,9 +4,7 @@ using System.IO;
namespace YooAsset.Editor
{
/// <summary>
/// 创建报告文件
/// </summary>
[TaskAttribute("创建构建报告文件")]
public class TaskCreateReport : IBuildTask
{
void IBuildTask.Run(BuildContext context)
@@ -93,6 +91,7 @@ namespace YooAsset.Editor
// 序列化文件
BuildReport.Serialize(filePath, buildReport);
UnityEngine.Debug.Log($"资源构建报告文件创建完成:{filePath}");
}
/// <summary>
@@ -6,6 +6,7 @@ using System.Collections.Generic;
namespace YooAsset.Editor
{
[TaskAttribute("资源包加密")]
public class TaskEncryption : IBuildTask
{
public class EncryptionContext : IContextObject
@@ -54,7 +55,6 @@ namespace YooAsset.Editor
if (encryptionServices == null)
return encryptList;
UnityEngine.Debug.Log($"开始加密资源文件");
int progressValue = 0;
foreach (var bundleInfo in buildMapContext.BundleInfos)
{
@@ -84,6 +84,8 @@ namespace YooAsset.Editor
}
EditorTools.ClearProgressBar();
if(encryptList.Count == 0)
UnityEngine.Debug.LogWarning($"没有发现需要加密的文件!");
return encryptList;
}
}
@@ -7,12 +7,14 @@ using UnityEditor;
namespace YooAsset.Editor
{
[TaskAttribute("获取资源构建内容")]
public class TaskGetBuildMap : IBuildTask
{
void IBuildTask.Run(BuildContext context)
{
var buildMapContext = BuildMapHelper.SetupBuildMap();
var buildMapContext = BuildMapCreater.CreateBuildMap();
context.SetContextObject(buildMapContext);
UnityEngine.Debug.Log("构建内容准备完毕!");
// 检测构建结果
CheckBuildMapContent(buildMapContext);
@@ -6,6 +6,7 @@ using UnityEditor;
namespace YooAsset.Editor
{
[TaskAttribute("资源构建准备工作")]
public class TaskPrepare : IBuildTask
{
void IBuildTask.Run(BuildContext context)
@@ -8,6 +8,7 @@ using UnityEngine;
namespace YooAsset.Editor
{
[TaskAttribute("验证构建结果")]
public class TaskVerifyBuildResult : IBuildTask
{
void IBuildTask.Run(BuildContext context)