Update editor logic

pull/40/head
hevinci 2022-09-27 21:04:08 +08:00
parent 50bfde6e8e
commit e1801a5fba
23 changed files with 193 additions and 254 deletions

View File

@ -86,7 +86,8 @@ namespace YooAsset.Editor
var buildResult = BuildRunner.Run(pipeline, _buildContext); var buildResult = BuildRunner.Run(pipeline, _buildContext);
if (buildResult.Success) if (buildResult.Success)
{ {
buildResult.OutputPackageDirectory = buildParametersContext.GetPackageDirectory(); buildResult.OutputPackageCRC = buildParametersContext.OutputPackageCRC;
buildResult.OutputPackageDirectory = buildParametersContext.GetPackageOutputDirectory();
Debug.Log($"{buildParameters.BuildMode} pipeline build succeed !"); Debug.Log($"{buildParameters.BuildMode} pipeline build succeed !");
} }
else else

View File

@ -25,14 +25,6 @@ namespace YooAsset.Editor
return $"{Application.dataPath}/StreamingAssets/YooAssets/"; return $"{Application.dataPath}/StreamingAssets/YooAssets/";
} }
/// <summary>
/// 获取构建管线的输出目录
/// </summary>
public static string MakePipelineOutputDirectory(string outputRoot, BuildTarget buildTarget)
{
return $"{outputRoot}/{buildTarget}/{YooAssetSettings.OutputFolderName}";
}
/// <summary> /// <summary>
/// 清空流文件夹 /// 清空流文件夹
/// </summary> /// </summary>
@ -67,61 +59,25 @@ namespace YooAsset.Editor
} }
} }
/// <summary> /// <summary>
/// 获取所有补丁包版本列表 /// 获取构建管线的输出目录
/// 注意:列表会按照版本号从小到大排序
/// </summary> /// </summary>
private static List<int> GetPackageVersionList(BuildTarget buildTarget, string outputRoot) public static string MakePipelineOutputDirectory(string outputRoot, string buildPackage, BuildTarget buildTarget, EBuildMode buildMode)
{ {
List<int> versionList = new List<int>(); string result = $"{outputRoot}/{buildPackage}/{buildTarget}/{YooAssetSettings.OutputFolderName}";
if (buildMode == EBuildMode.DryRunBuild)
string parentPath = $"{outputRoot}/{buildTarget}"; result += $"_{EBuildMode.DryRunBuild}";
if (Directory.Exists(parentPath) == false) else if (buildMode == EBuildMode.SimulateBuild)
return versionList; result += $"_{EBuildMode.SimulateBuild}";
return result;
// 获取所有补丁包文件夹
string[] allFolders = Directory.GetDirectories(parentPath);
for (int i = 0; i < allFolders.Length; i++)
{
string folderName = Path.GetFileNameWithoutExtension(allFolders[i]);
if (int.TryParse(folderName, out int version))
versionList.Add(version);
} }
// 从小到大排序
versionList.Sort();
return versionList;
}
/// <summary>
/// 获取当前最大的补丁包版本号
/// </summary>
/// <returns>如果没有任何补丁版本,那么返回-1</returns>
public static int GetMaxPackageVersion(BuildTarget buildTarget, string outputRoot)
{
List<int> versionList = GetPackageVersionList(buildTarget, outputRoot);
if (versionList.Count == 0)
return -1;
return versionList[versionList.Count - 1];
}
/// <summary>
/// 是否存在任何补丁包版本
/// </summary>
public static bool HasAnyPackageVersion(BuildTarget buildTarget, string outputRoot)
{
List<int> versionList = GetPackageVersionList(buildTarget, outputRoot);
return versionList.Count > 0;
}
/// <summary> /// <summary>
/// 加载补丁清单文件 /// 加载补丁清单文件
/// </summary> /// </summary>
internal static PatchManifest LoadPatchManifestFile(string fileDirectory, int resourceVersion) internal static PatchManifest LoadPatchManifestFile(string fileDirectory, string packageName, string packageCRC)
{ {
string filePath = $"{fileDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; string filePath = $"{fileDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(packageName, packageCRC)}";
if (File.Exists(filePath) == false) if (File.Exists(filePath) == false)
{ {
throw new System.Exception($"Not found patch manifest file : {filePath}"); throw new System.Exception($"Not found patch manifest file : {filePath}");
@ -130,16 +86,5 @@ namespace YooAsset.Editor
string jsonData = FileUtility.ReadFile(filePath); string jsonData = FileUtility.ReadFile(filePath);
return PatchManifest.Deserialize(jsonData); return PatchManifest.Deserialize(jsonData);
} }
/// <summary>
/// 获取旧的补丁清单
/// </summary>
internal static PatchManifest GetOldPatchManifest(string pipelineOutputDirectory)
{
string staticVersionFilePath = $"{pipelineOutputDirectory}/{YooAssetSettings.VersionFileName}";
string staticVersionContent = FileUtility.ReadFile(staticVersionFilePath);
int staticVersion = int.Parse(staticVersionContent);
return LoadPatchManifestFile(pipelineOutputDirectory, staticVersion);
}
} }
} }

View File

@ -5,11 +5,6 @@ namespace YooAsset.Editor
{ {
public class AssetBundleBuilderSetting : ScriptableObject public class AssetBundleBuilderSetting : ScriptableObject
{ {
/// <summary>
/// 构建版本号
/// </summary>
public int BuildVersion = 0;
/// <summary> /// <summary>
/// 构建管线 /// 构建管线
/// </summary> /// </summary>

View File

@ -25,7 +25,6 @@ namespace YooAsset.Editor
private Button _saveButton; private Button _saveButton;
private TextField _buildOutputField; private TextField _buildOutputField;
private IntegerField _buildVersionField;
private EnumField _buildPipelineField; private EnumField _buildPipelineField;
private EnumField _buildModeField; private EnumField _buildModeField;
private TextField _buildinTagsField; private TextField _buildinTagsField;
@ -63,20 +62,10 @@ namespace YooAsset.Editor
// 输出目录 // 输出目录
string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot(); string defaultOutputRoot = AssetBundleBuilderHelper.GetDefaultOutputRoot();
string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(defaultOutputRoot, _buildTarget);
_buildOutputField = root.Q<TextField>("BuildOutput"); _buildOutputField = root.Q<TextField>("BuildOutput");
_buildOutputField.SetValueWithoutNotify(pipelineOutputDirectory); _buildOutputField.SetValueWithoutNotify(defaultOutputRoot);
_buildOutputField.SetEnabled(false); _buildOutputField.SetEnabled(false);
// 构建版本
_buildVersionField = root.Q<IntegerField>("BuildVersion");
_buildVersionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildVersion);
_buildVersionField.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value;
});
// 构建管线 // 构建管线
_buildPipelineField = root.Q<EnumField>("BuildPipeline"); _buildPipelineField = root.Q<EnumField>("BuildPipeline");
_buildPipelineField.Init(AssetBundleBuilderSettingData.Setting.BuildPipeline); _buildPipelineField.Init(AssetBundleBuilderSettingData.Setting.BuildPipeline);
@ -249,7 +238,6 @@ namespace YooAsset.Editor
buildParameters.BuildTarget = _buildTarget; buildParameters.BuildTarget = _buildTarget;
buildParameters.BuildPipeline = AssetBundleBuilderSettingData.Setting.BuildPipeline; buildParameters.BuildPipeline = AssetBundleBuilderSettingData.Setting.BuildPipeline;
buildParameters.BuildMode = AssetBundleBuilderSettingData.Setting.BuildMode; buildParameters.BuildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
buildParameters.BuildVersion = AssetBundleBuilderSettingData.Setting.BuildVersion;
buildParameters.BuildPackage = AssetBundleBuilderSettingData.Setting.BuildPackage; buildParameters.BuildPackage = AssetBundleBuilderSettingData.Setting.BuildPackage;
buildParameters.BuildinTags = AssetBundleBuilderSettingData.Setting.BuildTags; buildParameters.BuildinTags = AssetBundleBuilderSettingData.Setting.BuildTags;
buildParameters.VerifyBuildingResult = true; buildParameters.VerifyBuildingResult = true;
@ -269,7 +257,7 @@ namespace YooAsset.Editor
var buildResult = builder.Run(buildParameters); var buildResult = builder.Run(buildParameters);
if (buildResult.Success) if (buildResult.Success)
{ {
EditorUtility.RevealInFinder($"{buildParameters.OutputRoot}/{buildParameters.BuildTarget}/{buildParameters.BuildVersion}"); EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory);
} }
} }

View File

@ -4,7 +4,6 @@
</uie:Toolbar> </uie:Toolbar>
<ui:VisualElement name="BuildContainer"> <ui:VisualElement name="BuildContainer">
<ui:TextField picking-mode="Ignore" label="Build Output" name="BuildOutput" /> <ui:TextField picking-mode="Ignore" label="Build Output" name="BuildOutput" />
<uie:IntegerField label="Build Version" value="0" name="BuildVersion" />
<uie:EnumField label="Build Pipeline" name="BuildPipeline" /> <uie:EnumField label="Build Pipeline" name="BuildPipeline" />
<uie:EnumField label="Build Mode" name="BuildMode" /> <uie:EnumField label="Build Mode" name="BuildMode" />
<ui:VisualElement name="BuildPackageContainer" style="height: 24px;" /> <ui:VisualElement name="BuildPackageContainer" style="height: 24px;" />

View File

@ -16,7 +16,6 @@ namespace YooAsset.Editor
buildParameters.OutputRoot = defaultOutputRoot; buildParameters.OutputRoot = defaultOutputRoot;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget; buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.BuildMode = EBuildMode.SimulateBuild; buildParameters.BuildMode = EBuildMode.SimulateBuild;
buildParameters.BuildVersion = 999;
buildParameters.BuildPackage = AssetBundleBuilderSettingData.Setting.BuildPackage; buildParameters.BuildPackage = AssetBundleBuilderSettingData.Setting.BuildPackage;
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable; buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
@ -24,8 +23,9 @@ namespace YooAsset.Editor
var buildResult = builder.Run(buildParameters); var buildResult = builder.Run(buildParameters);
if (buildResult.Success) if (buildResult.Success)
{ {
string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(buildParameters.OutputRoot, buildParameters.BuildTarget); string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(buildParameters.OutputRoot, buildParameters.BuildPackage, buildParameters.BuildTarget, buildParameters.BuildMode);
_manifestFilePath = $"{pipelineOutputDirectory}_{EBuildMode.SimulateBuild}/{YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildVersion)}"; string manifestFileName = YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildPackage, buildResult.OutputPackageCRC);
_manifestFilePath = $"{pipelineOutputDirectory}/{manifestFileName}";
} }
else else
{ {

View File

@ -61,11 +61,6 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public string BuildPackage; public string BuildPackage;
/// <summary>
/// 构建的版本(资源版本号)
/// </summary>
public int BuildVersion;
/// <summary> /// <summary>
/// 内置资源标签集合(首包资源标签) /// 内置资源标签集合(首包资源标签)
/// 注意:分号为分隔符 /// 注意:分号为分隔符

View File

@ -9,34 +9,61 @@ namespace YooAsset.Editor
{ {
private readonly System.Diagnostics.Stopwatch _buildWatch = new System.Diagnostics.Stopwatch(); private readonly System.Diagnostics.Stopwatch _buildWatch = new System.Diagnostics.Stopwatch();
private string _pipelineOutputDirectory = string.Empty;
private string _packageOutputDirectory = string.Empty;
private string _outputPackageCRC = string.Empty;
/// <summary> /// <summary>
/// 构建参数 /// 构建参数
/// </summary> /// </summary>
public BuildParameters Parameters { private set; get; } public BuildParameters Parameters { private set; get; }
/// <summary> /// <summary>
/// 构建管线的输出目录 /// 构建输出的包裹清单哈希值
/// </summary> /// </summary>
public string PipelineOutputDirectory { private set; get; } public string OutputPackageCRC
{
get
{
if (string.IsNullOrEmpty(_outputPackageCRC))
throw new Exception("Output package file CRC32 is empty !");
return _outputPackageCRC;
}
set
{
_outputPackageCRC = value;
}
}
public BuildParametersContext(BuildParameters parameters) public BuildParametersContext(BuildParameters parameters)
{ {
Parameters = parameters; Parameters = parameters;
}
PipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(parameters.OutputRoot, parameters.BuildTarget); /// <summary>
if (parameters.BuildMode == EBuildMode.DryRunBuild) /// 获取构建管线的输出目录
PipelineOutputDirectory += $"_{EBuildMode.DryRunBuild}"; /// </summary>
else if (parameters.BuildMode == EBuildMode.SimulateBuild) /// <returns></returns>
PipelineOutputDirectory += $"_{EBuildMode.SimulateBuild}"; public string GetPipelineOutputDirectory()
{
if (string.IsNullOrEmpty(_pipelineOutputDirectory))
{
_pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(Parameters.OutputRoot, Parameters.BuildPackage, Parameters.BuildTarget, Parameters.BuildMode);
}
return _pipelineOutputDirectory;
} }
/// <summary> /// <summary>
/// 获取本次构建的补丁目录 /// 获取本次构建的补丁目录
/// </summary> /// </summary>
public string GetPackageDirectory() public string GetPackageOutputDirectory()
{ {
return $"{Parameters.OutputRoot}/{Parameters.BuildTarget}/{Parameters.BuildVersion}"; if (string.IsNullOrEmpty(_packageOutputDirectory))
{
_packageOutputDirectory = $"{Parameters.OutputRoot}/{Parameters.BuildPackage}/{Parameters.BuildTarget}/{OutputPackageCRC}";
}
return _packageOutputDirectory;
} }
/// <summary> /// <summary>
@ -86,7 +113,8 @@ namespace YooAsset.Editor
throw new Exception("Should never get here !"); throw new Exception("Should never get here !");
var targetGroup = BuildPipeline.GetBuildTargetGroup(Parameters.BuildTarget); var targetGroup = BuildPipeline.GetBuildTargetGroup(Parameters.BuildTarget);
var buildParams = new UnityEditor.Build.Pipeline.BundleBuildParameters(Parameters.BuildTarget, targetGroup, PipelineOutputDirectory); var pipelineOutputDirectory = GetPipelineOutputDirectory();
var buildParams = new UnityEditor.Build.Pipeline.BundleBuildParameters(Parameters.BuildTarget, targetGroup, pipelineOutputDirectory);
if (Parameters.CompressOption == ECompressOption.Uncompressed) if (Parameters.CompressOption == ECompressOption.Uncompressed)
buildParams.BundleCompression = UnityEngine.BuildCompression.Uncompressed; buildParams.BundleCompression = UnityEngine.BuildCompression.Uncompressed;

View File

@ -44,9 +44,9 @@ namespace YooAsset.Editor
public EBuildMode BuildMode; public EBuildMode BuildMode;
/// <summary> /// <summary>
/// 构建版本 /// 构建包裹
/// </summary> /// </summary>
public int BuildVersion; public string BuildPackage;
/// <summary> /// <summary>
/// 内置资源标签 /// 内置资源标签

View File

@ -25,5 +25,10 @@ namespace YooAsset.Editor
/// 输出的补丁包目录 /// 输出的补丁包目录
/// </summary> /// </summary>
public string OutputPackageDirectory; public string OutputPackageDirectory;
/// <summary>
/// 输出的包裹清单哈希值
/// </summary>
public string OutputPackageCRC;
} }
} }

View File

@ -25,14 +25,15 @@ namespace YooAsset.Editor
if (buildMode == EBuildMode.SimulateBuild) if (buildMode == EBuildMode.SimulateBuild)
return; return;
BuildAssetBundleOptions opt = buildParametersContext.GetPipelineBuildOptions(); string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
AssetBundleManifest buildResults = BuildPipeline.BuildAssetBundles(buildParametersContext.PipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), opt, buildParametersContext.Parameters.BuildTarget); BuildAssetBundleOptions buildOptions = buildParametersContext.GetPipelineBuildOptions();
AssetBundleManifest buildResults = BuildPipeline.BuildAssetBundles(pipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), buildOptions, buildParametersContext.Parameters.BuildTarget);
if (buildResults == null) if (buildResults == null)
throw new Exception("构建过程中发生错误!"); throw new Exception("构建过程中发生错误!");
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild) if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
{ {
string unityOutputManifestFilePath = $"{buildParametersContext.PipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}"; string unityOutputManifestFilePath = $"{buildParametersContext.GetPipelineOutputDirectory()}/{YooAssetSettings.OutputFolderName}";
if(System.IO.File.Exists(unityOutputManifestFilePath) == false) if(System.IO.File.Exists(unityOutputManifestFilePath) == false)
throw new Exception("构建过程中发生严重错误!请查阅上下文日志!"); throw new Exception("构建过程中发生严重错误!请查阅上下文日志!");
} }
@ -54,11 +55,12 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private void CopyRawBundle(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext) private void CopyRawBundle(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext)
{ {
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
foreach (var bundleInfo in buildMapContext.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
{ {
if (bundleInfo.IsRawFile) if (bundleInfo.IsRawFile)
{ {
string dest = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; string dest = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
foreach (var buildAsset in bundleInfo.BuildinAssets) foreach (var buildAsset in bundleInfo.BuildinAssets)
{ {
if (buildAsset.IsRawAsset) if (buildAsset.IsRawAsset)
@ -73,11 +75,12 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private void UpdateBuildBundleInfo(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext, BuildResultContext buildResult) private void UpdateBuildBundleInfo(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext, BuildResultContext buildResult)
{ {
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
foreach (var bundleInfo in buildMapContext.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
{ {
if (bundleInfo.IsRawFile) if (bundleInfo.IsRawFile)
{ {
string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
bundleInfo.ContentHash = HashUtility.FileMD5(filePath); bundleInfo.ContentHash = HashUtility.FileMD5(filePath);
} }
else else

View File

@ -58,11 +58,12 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private void CopyRawBundle(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext) private void CopyRawBundle(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext)
{ {
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
foreach (var bundleInfo in buildMapContext.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
{ {
if (bundleInfo.IsRawFile) if (bundleInfo.IsRawFile)
{ {
string dest = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; string dest = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
foreach (var buildAsset in bundleInfo.BuildinAssets) foreach (var buildAsset in bundleInfo.BuildinAssets)
{ {
if (buildAsset.IsRawAsset) if (buildAsset.IsRawAsset)
@ -77,11 +78,12 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private void UpdateBuildBundleInfo(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext, BuildResultContext buildResult) private void UpdateBuildBundleInfo(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext, BuildResultContext buildResult)
{ {
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
foreach (var bundleInfo in buildMapContext.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
{ {
if (bundleInfo.IsRawFile) if (bundleInfo.IsRawFile)
{ {
string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
bundleInfo.ContentHash = HashUtility.FileMD5(filePath); bundleInfo.ContentHash = HashUtility.FileMD5(filePath);
} }
else else

View File

@ -11,22 +11,26 @@ namespace YooAsset.Editor
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
// 注意:我们只有在强制重建的时候才会拷贝 var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildParameters = context.GetContextObject<BuildParametersContext>(); if (buildParametersContext.Parameters.CopyBuildinTagFiles)
if (buildParameters.Parameters.CopyBuildinTagFiles)
{ {
// 清空流目录 // 清空流目录
AssetBundleBuilderHelper.ClearStreamingAssetsFolder(); AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
// 拷贝内置文件 // 拷贝内置文件
CopyBuildinFilesToStreaming(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion); CopyBuildinFilesToStreaming(buildParametersContext);
} }
} }
private void CopyBuildinFilesToStreaming(string pipelineOutputDirectory, int buildVersion) private void CopyBuildinFilesToStreaming(BuildParametersContext buildParametersContext)
{ {
string streamingAssetsOutputDirectory = AssetBundleBuilderHelper.GetStreamingAssetsFolderPath();
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
string packageName = buildParametersContext.Parameters.BuildPackage;
string packageCRC = buildParametersContext.OutputPackageCRC;
// 加载补丁清单 // 加载补丁清单
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory, buildVersion); PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory, packageName, packageCRC);
// 拷贝文件列表 // 拷贝文件列表
foreach (var patchBundle in patchManifest.BundleList) foreach (var patchBundle in patchManifest.BundleList)
@ -35,34 +39,29 @@ namespace YooAsset.Editor
continue; continue;
string sourcePath = $"{pipelineOutputDirectory}/{patchBundle.BundleName}"; string sourcePath = $"{pipelineOutputDirectory}/{patchBundle.BundleName}";
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{patchBundle.FileName}"; string destPath = $"{streamingAssetsOutputDirectory}/{patchBundle.FileName}";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
// 拷贝清单文件 // 拷贝清单文件
{ {
string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(buildVersion)}"; string manifestFileName = YooAssetSettingsData.GetPatchManifestFileName(packageName, packageCRC);
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettingsData.GetPatchManifestFileName(buildVersion)}"; string sourcePath = $"{pipelineOutputDirectory}/{manifestFileName}";
EditorTools.CopyFile(sourcePath, destPath, true); string destPath = $"{streamingAssetsOutputDirectory}/{manifestFileName}";
}
// 拷贝清单哈希文件
{
string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(buildVersion)}";
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettingsData.GetPatchManifestHashFileName(buildVersion)}";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
// 拷贝静态版本文件 // 拷贝静态版本文件
{ {
string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettings.VersionFileName}"; string versionFileName = YooAssetSettingsData.GetStaticVersionFileName(packageName);
string destPath = $"{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}/{YooAssetSettings.VersionFileName}"; string sourcePath = $"{pipelineOutputDirectory}/{versionFileName}";
string destPath = $"{streamingAssetsOutputDirectory}/{versionFileName}";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
// 刷新目录 // 刷新目录
AssetDatabase.Refresh(); AssetDatabase.Refresh();
BuildRunner.Log($"内置文件拷贝完成:{AssetBundleBuilderHelper.GetStreamingAssetsFolderPath()}"); BuildRunner.Log($"内置文件拷贝完成:{streamingAssetsOutputDirectory}");
} }
} }
} }

View File

@ -21,23 +21,24 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private void CreatePatchManifestFile(BuildContext context) private void CreatePatchManifestFile(BuildContext context)
{ {
var buildParameters = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
int resourceVersion = buildParameters.Parameters.BuildVersion; var buildParameters = buildParametersContext.Parameters;
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
// 创建新补丁清单 // 创建新补丁清单
PatchManifest patchManifest = new PatchManifest(); PatchManifest patchManifest = new PatchManifest();
patchManifest.FileVersion = YooAssetSettings.PatchManifestFileVersion; patchManifest.FileVersion = YooAssetSettings.PatchManifestFileVersion;
patchManifest.ResourceVersion = buildParameters.Parameters.BuildVersion; patchManifest.EnableAddressable = buildParameters.EnableAddressable;
patchManifest.EnableAddressable = buildParameters.Parameters.EnableAddressable; patchManifest.OutputNameStyle = (int)buildParameters.OutputNameStyle;
patchManifest.OutputNameStyle = (int)buildParameters.Parameters.OutputNameStyle; patchManifest.PackageName = buildParameters.BuildPackage;
patchManifest.BuildinTags = buildParameters.Parameters.BuildinTags; patchManifest.BuildinTags = buildParameters.BuildinTags;
patchManifest.BundleList = GetAllPatchBundle(context); patchManifest.BundleList = GetAllPatchBundle(context);
patchManifest.AssetList = GetAllPatchAsset(context, patchManifest); patchManifest.AssetList = GetAllPatchAsset(context, patchManifest);
// 更新Unity内置资源包的引用关系 // 更新Unity内置资源包的引用关系
if (buildParameters.Parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline) if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{ {
if(buildParameters.Parameters.BuildMode == EBuildMode.IncrementalBuild) if(buildParameters.BuildMode == EBuildMode.IncrementalBuild)
{ {
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>(); var buildResultContext = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
UpdateBuiltInBundleReference(patchManifest, buildResultContext.Results); UpdateBuiltInBundleReference(patchManifest, buildResultContext.Results);
@ -45,21 +46,24 @@ namespace YooAsset.Editor
} }
// 创建补丁清单文件 // 创建补丁清单文件
string manifestFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; string manifestFileTempName = YooAssetSettingsData.GetPatchManifestTempFileName(buildParameters.BuildPackage);
BuildRunner.Log($"创建补丁清单文件:{manifestFilePath}"); string manifestFileTempPath = $"{pipelineOutputDirectory}/{manifestFileTempName}";
PatchManifest.Serialize(manifestFilePath, patchManifest); BuildRunner.Log($"创建补丁清单文件:{manifestFileTempPath}");
PatchManifest.Serialize(manifestFileTempPath, patchManifest);
// 创建补丁清单哈希文件 // 计算补丁清单文件的CRC32
string manifestHashFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}"; buildParametersContext.OutputPackageCRC = HashUtility.FileCRC32(manifestFileTempPath);
string manifestHash = HashUtility.FileMD5(manifestFilePath);
BuildRunner.Log($"创建补丁清单哈希文件:{manifestHashFilePath}"); // 补丁清单文件重命名
FileUtility.CreateFile(manifestHashFilePath, manifestHash); string manifestFileName = YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC);
string manifestFilePath = $"{pipelineOutputDirectory}/{manifestFileName}";
EditorTools.FileMoveTo(manifestFileTempPath, manifestFilePath);
// 创建静态版本文件 // 创建静态版本文件
string staticVersionFilePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}"; string staticVersionFileName = YooAssetSettingsData.GetStaticVersionFileName(buildParameters.BuildPackage);
string staticVersion = resourceVersion.ToString(); string staticVersionFilePath = $"{pipelineOutputDirectory}/{staticVersionFileName}";
BuildRunner.Log($"创建静态版本文件:{staticVersionFilePath}"); BuildRunner.Log($"创建静态版本文件:{staticVersionFilePath}");
FileUtility.CreateFile(staticVersionFilePath, staticVersion); FileUtility.CreateFile(staticVersionFilePath, buildParametersContext.OutputPackageCRC);
} }
/// <summary> /// <summary>
@ -111,7 +115,7 @@ namespace YooAsset.Editor
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild) if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
return "00000000000000000000000000000000"; //32位 return "00000000000000000000000000000000"; //32位
string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; string filePath = $"{buildParametersContext.GetPipelineOutputDirectory()}/{bundleInfo.BundleName}";
return HashUtility.FileMD5(filePath); return HashUtility.FileMD5(filePath);
} }
private string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) private string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
@ -120,7 +124,7 @@ namespace YooAsset.Editor
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild) if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
return "00000000"; //8位 return "00000000"; //8位
string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; string filePath = $"{buildParametersContext.GetPipelineOutputDirectory()}/{bundleInfo.BundleName}";
return HashUtility.FileCRC32(filePath); return HashUtility.FileCRC32(filePath);
} }
private long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) private long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
@ -129,7 +133,7 @@ namespace YooAsset.Editor
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild) if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
return 0; return 0;
string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}"; string filePath = $"{buildParametersContext.GetPipelineOutputDirectory()}/{bundleInfo.BundleName}";
return FileUtility.GetFileSize(filePath); return FileUtility.GetFileSize(filePath);
} }

View File

@ -19,55 +19,51 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 拷贝补丁文件到补丁包目录 /// 拷贝补丁文件到补丁包目录
/// </summary> /// </summary>
private void CopyPatchFiles(BuildParametersContext buildParameters) private void CopyPatchFiles(BuildParametersContext buildParametersContext)
{ {
int resourceVersion = buildParameters.Parameters.BuildVersion; var buildParameters = buildParametersContext.Parameters;
string packageDirectory = buildParameters.GetPackageDirectory(); string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
BuildRunner.Log($"开始拷贝补丁文件到补丁包目录:{packageDirectory}"); string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
BuildRunner.Log($"开始拷贝补丁文件到补丁包目录:{packageOutputDirectory}");
// 拷贝Report文件 // 拷贝Report文件
{ {
string reportFileName = YooAssetSettingsData.GetReportFileName(buildParameters.Parameters.BuildVersion); string reportFileName = YooAssetSettingsData.GetReportFileName(buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC);
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{reportFileName}"; string sourcePath = $"{pipelineOutputDirectory}/{reportFileName}";
string destPath = $"{packageDirectory}/{reportFileName}"; string destPath = $"{packageOutputDirectory}/{reportFileName}";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
// 拷贝补丁清单文件 // 拷贝补丁清单文件
{ {
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; string manifestFileName = YooAssetSettingsData.GetPatchManifestFileName(buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC);
string destPath = $"{packageDirectory}/{YooAssetSettingsData.GetPatchManifestFileName(resourceVersion)}"; string sourcePath = $"{pipelineOutputDirectory}/{manifestFileName}";
EditorTools.CopyFile(sourcePath, destPath, true); string destPath = $"{packageOutputDirectory}/{manifestFileName}";
}
// 拷贝补丁清单哈希文件
{
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}";
string destPath = $"{packageDirectory}/{YooAssetSettingsData.GetPatchManifestHashFileName(resourceVersion)}";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
// 拷贝静态版本文件 // 拷贝静态版本文件
{ {
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.VersionFileName}"; string versionFileName = YooAssetSettingsData.GetStaticVersionFileName(buildParameters.BuildPackage);
string destPath = $"{packageDirectory}/{YooAssetSettings.VersionFileName}"; string sourcePath = $"{pipelineOutputDirectory}/{versionFileName}";
string destPath = $"{packageOutputDirectory}/{versionFileName}";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
if (buildParameters.Parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline) if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{ {
// 拷贝构建日志 // 拷贝构建日志
{ {
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/buildlogtep.json"; string sourcePath = $"{pipelineOutputDirectory}/buildlogtep.json";
string destPath = $"{packageDirectory}/buildlogtep.json"; string destPath = $"{packageOutputDirectory}/buildlogtep.json";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
// 拷贝代码防裁剪配置 // 拷贝代码防裁剪配置
if (buildParameters.Parameters.SBPParameters.WriteLinkXML) if (buildParameters.SBPParameters.WriteLinkXML)
{ {
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/link.xml"; string sourcePath = $"{pipelineOutputDirectory}/link.xml";
string destPath = $"{packageDirectory}/link.xml"; string destPath = $"{packageOutputDirectory}/link.xml";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
} }
@ -75,27 +71,27 @@ namespace YooAsset.Editor
{ {
// 拷贝UnityManifest序列化文件 // 拷贝UnityManifest序列化文件
{ {
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}"; string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}";
string destPath = $"{packageDirectory}/{YooAssetSettings.OutputFolderName}"; string destPath = $"{packageOutputDirectory}/{YooAssetSettings.OutputFolderName}";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
// 拷贝UnityManifest文本文件 // 拷贝UnityManifest文本文件
{ {
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}.manifest"; string sourcePath = $"{pipelineOutputDirectory}/{YooAssetSettings.OutputFolderName}.manifest";
string destPath = $"{packageDirectory}/{YooAssetSettings.OutputFolderName}.manifest"; string destPath = $"{packageOutputDirectory}/{YooAssetSettings.OutputFolderName}.manifest";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
} }
} }
// 拷贝所有补丁文件 // 拷贝所有补丁文件
int progressValue = 0; int progressValue = 0;
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion); PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory, buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC);
int patchFileTotalCount = patchManifest.BundleList.Count; int patchFileTotalCount = patchManifest.BundleList.Count;
foreach (var patchBundle in patchManifest.BundleList) foreach (var patchBundle in patchManifest.BundleList)
{ {
string sourcePath = $"{buildParameters.PipelineOutputDirectory}/{patchBundle.BundleName}"; string sourcePath = $"{pipelineOutputDirectory}/{patchBundle.BundleName}";
string destPath = $"{packageDirectory}/{patchBundle.FileName}"; string destPath = $"{packageOutputDirectory}/{patchBundle.FileName}";
EditorTools.CopyFile(sourcePath, destPath, true); EditorTools.CopyFile(sourcePath, destPath, true);
EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, patchFileTotalCount); EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, patchFileTotalCount);
} }

View File

@ -24,9 +24,12 @@ namespace YooAsset.Editor
BuildRunner.Info($"Build time consuming {buildSeconds} seconds."); BuildRunner.Info($"Build time consuming {buildSeconds} seconds.");
} }
private void CreateReportFile(BuildParametersContext buildParameters, BuildMapContext buildMapContext) private void CreateReportFile(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
{ {
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory, buildParameters.Parameters.BuildVersion); var buildParameters = buildParametersContext.Parameters;
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(pipelineOutputDirectory, buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC);
BuildReport buildReport = new BuildReport(); BuildReport buildReport = new BuildReport();
// 概述信息 // 概述信息
@ -38,22 +41,22 @@ namespace YooAsset.Editor
#endif #endif
buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion; buildReport.Summary.UnityVersion = UnityEngine.Application.unityVersion;
buildReport.Summary.BuildDate = DateTime.Now.ToString(); buildReport.Summary.BuildDate = DateTime.Now.ToString();
buildReport.Summary.BuildSeconds = (int)buildParameters.GetBuildingSeconds(); buildReport.Summary.BuildSeconds = (int)buildParametersContext.GetBuildingSeconds();
buildReport.Summary.BuildTarget = buildParameters.Parameters.BuildTarget; buildReport.Summary.BuildTarget = buildParameters.BuildTarget;
buildReport.Summary.BuildPipeline = buildParameters.Parameters.BuildPipeline; buildReport.Summary.BuildPipeline = buildParameters.BuildPipeline;
buildReport.Summary.BuildMode = buildParameters.Parameters.BuildMode; buildReport.Summary.BuildMode = buildParameters.BuildMode;
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion; buildReport.Summary.BuildPackage = buildParameters.BuildPackage;
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags; buildReport.Summary.BuildinTags = buildParameters.BuildinTags;
buildReport.Summary.EnableAddressable = buildParameters.Parameters.EnableAddressable; buildReport.Summary.EnableAddressable = buildParameters.EnableAddressable;
buildReport.Summary.CopyBuildinTagFiles = buildParameters.Parameters.CopyBuildinTagFiles; buildReport.Summary.CopyBuildinTagFiles = buildParameters.CopyBuildinTagFiles;
buildReport.Summary.EncryptionServicesClassName = buildParameters.Parameters.EncryptionServices == null ? buildReport.Summary.EncryptionServicesClassName = buildParameters.EncryptionServices == null ?
"null" : buildParameters.Parameters.EncryptionServices.GetType().FullName; "null" : buildParameters.EncryptionServices.GetType().FullName;
// 构建参数 // 构建参数
buildReport.Summary.OutputNameStyle = buildParameters.Parameters.OutputNameStyle; buildReport.Summary.OutputNameStyle = buildParameters.OutputNameStyle;
buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption; buildReport.Summary.CompressOption = buildParameters.CompressOption;
buildReport.Summary.DisableWriteTypeTree = buildParameters.Parameters.DisableWriteTypeTree; buildReport.Summary.DisableWriteTypeTree = buildParameters.DisableWriteTypeTree;
buildReport.Summary.IgnoreTypeTreeChanges = buildParameters.Parameters.IgnoreTypeTreeChanges; buildReport.Summary.IgnoreTypeTreeChanges = buildParameters.IgnoreTypeTreeChanges;
// 构建结果 // 构建结果
buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount; buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount;
@ -101,7 +104,8 @@ namespace YooAsset.Editor
} }
// 删除旧文件 // 删除旧文件
string filePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettingsData.GetReportFileName(buildParameters.Parameters.BuildVersion)}"; string fileName = YooAssetSettingsData.GetReportFileName(buildParameters.BuildPackage, buildParametersContext.OutputPackageCRC);
string filePath = $"{pipelineOutputDirectory}/{fileName}";
if (File.Exists(filePath)) if (File.Exists(filePath))
File.Delete(filePath); File.Delete(filePath);

View File

@ -45,9 +45,9 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 加密文件 /// 加密文件
/// </summary> /// </summary>
private List<string> EncryptFiles(BuildParametersContext buildParameters, BuildMapContext buildMapContext) private List<string> EncryptFiles(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
{ {
var encryptionServices = buildParameters.Parameters.EncryptionServices; var encryptionServices = buildParametersContext.Parameters.EncryptionServices;
// 加密资源列表 // 加密资源列表
List<string> encryptList = new List<string>(); List<string> encryptList = new List<string>();
@ -57,6 +57,7 @@ namespace YooAsset.Editor
return encryptList; return encryptList;
int progressValue = 0; int progressValue = 0;
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
foreach (var bundleInfo in buildMapContext.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
{ {
if (encryptionServices.Check(bundleInfo.BundleName)) if (encryptionServices.Check(bundleInfo.BundleName))
@ -70,7 +71,7 @@ namespace YooAsset.Editor
encryptList.Add(bundleInfo.BundleName); encryptList.Add(bundleInfo.BundleName);
// 注意:通过判断文件合法性,规避重复加密一个文件 // 注意:通过判断文件合法性,规避重复加密一个文件
string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleInfo.BundleName}"; string filePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
byte[] fileData = File.ReadAllBytes(filePath); byte[] fileData = File.ReadAllBytes(filePath);
if (EditorTools.CheckBundleFileValid(fileData)) if (EditorTools.CheckBundleFileValid(fileData))
{ {

View File

@ -11,24 +11,18 @@ namespace YooAsset.Editor
{ {
void IBuildTask.Run(BuildContext context) void IBuildTask.Run(BuildContext context)
{ {
var buildParameters = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
buildParameters.BeginWatch(); buildParametersContext.BeginWatch();
var buildMode = buildParameters.Parameters.BuildMode; var buildParameters = buildParametersContext.Parameters;
// 检测构建平台是否合法 // 检测构建参数合法性
if (buildParameters.Parameters.BuildTarget == BuildTarget.NoTarget) if (buildParameters.BuildTarget == BuildTarget.NoTarget)
throw new Exception("请选择目标平台"); throw new Exception("请选择目标平台");
if (string.IsNullOrEmpty(buildParameters.BuildPackage))
throw new Exception("包裹名称不能为空");
// 检测构建版本是否合法 if (buildParameters.BuildMode != EBuildMode.SimulateBuild)
if (buildParameters.Parameters.BuildVersion <= 0)
throw new Exception("请先设置版本号");
// 检测输出目录是否为空
if (string.IsNullOrEmpty(buildParameters.PipelineOutputDirectory))
throw new Exception("输出目录不能为空");
if (buildMode != EBuildMode.SimulateBuild)
{ {
// 检测当前是否正在构建资源包 // 检测当前是否正在构建资源包
if (BuildPipeline.isBuildingPlayer) if (BuildPipeline.isBuildingPlayer)
@ -41,35 +35,10 @@ namespace YooAsset.Editor
// 保存改动的资源 // 保存改动的资源
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
} }
if (buildParameters.BuildMode == EBuildMode.ForceRebuild)
// 增量更新时候的必要检测
if (buildMode == EBuildMode.IncrementalBuild)
{
// 检测历史版本是否存在
if (AssetBundleBuilderHelper.HasAnyPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot))
{
// 检测构建版本是否合法
int maxPackageVersion = AssetBundleBuilderHelper.GetMaxPackageVersion(buildParameters.Parameters.BuildTarget, buildParameters.Parameters.OutputRoot);
if (buildParameters.Parameters.BuildVersion <= maxPackageVersion)
throw new Exception("构建版本不能小于历史版本");
// 检测补丁包是否已经存在
string packageDirectory = buildParameters.GetPackageDirectory();
if (Directory.Exists(packageDirectory))
throw new Exception($"补丁包已经存在:{packageDirectory}");
// 检测内置资源分类标签是否一致
var oldPatchManifest = AssetBundleBuilderHelper.GetOldPatchManifest(buildParameters.PipelineOutputDirectory);
if (buildParameters.Parameters.BuildinTags != oldPatchManifest.BuildinTags)
throw new Exception($"增量更新时内置资源标签必须一致:{buildParameters.Parameters.BuildinTags} != {oldPatchManifest.BuildinTags}");
}
}
// 如果是强制重建
if (buildMode == EBuildMode.ForceRebuild)
{ {
// 删除平台总目录 // 删除平台总目录
string platformDirectory = $"{buildParameters.Parameters.OutputRoot}/{buildParameters.Parameters.BuildTarget}"; string platformDirectory = $"{buildParameters.OutputRoot}/{buildParameters.BuildPackage}/{buildParameters.BuildTarget}";
if (EditorTools.DeleteDirectory(platformDirectory)) if (EditorTools.DeleteDirectory(platformDirectory))
{ {
BuildRunner.Log($"删除平台总目录:{platformDirectory}"); BuildRunner.Log($"删除平台总目录:{platformDirectory}");
@ -77,9 +46,10 @@ namespace YooAsset.Editor
} }
// 如果输出目录不存在 // 如果输出目录不存在
if (EditorTools.CreateDirectory(buildParameters.PipelineOutputDirectory)) string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
if (EditorTools.CreateDirectory(pipelineOutputDirectory))
{ {
BuildRunner.Log($"创建输出目录:{buildParameters.PipelineOutputDirectory}"); BuildRunner.Log($"创建输出目录:{pipelineOutputDirectory}");
} }
} }
} }

View File

@ -32,7 +32,7 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
private void VerifyingBuildingResult(BuildContext context, AssetBundleManifest unityManifest) private void VerifyingBuildingResult(BuildContext context, AssetBundleManifest unityManifest)
{ {
var buildParameters = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>(); var buildMapContext = context.GetContextObject<BuildMapContext>();
string[] buildedBundles = unityManifest.GetAllAssetBundles(); string[] buildedBundles = unityManifest.GetAllAssetBundles();
@ -63,13 +63,14 @@ namespace YooAsset.Editor
// 4. 验证Asset // 4. 验证Asset
bool isPass = true; bool isPass = true;
var buildMode = buildParameters.Parameters.BuildMode; var buildMode = buildParametersContext.Parameters.BuildMode;
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild) if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
{ {
int progressValue = 0; int progressValue = 0;
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
foreach (var buildedBundle in buildedBundles) foreach (var buildedBundle in buildedBundles)
{ {
string filePath = $"{buildParameters.PipelineOutputDirectory}/{buildedBundle}"; string filePath = $"{pipelineOutputDirectory}/{buildedBundle}";
string[] buildedAssetPaths = GetAssetBundleAllAssets(filePath); string[] buildedAssetPaths = GetAssetBundleAllAssets(filePath);
string[] mapAssetPaths = buildMapContext.GetBuildinAssetPaths(buildedBundle); string[] mapAssetPaths = buildMapContext.GetBuildinAssetPaths(buildedBundle);
if (mapAssetPaths.Length != buildedAssetPaths.Length) if (mapAssetPaths.Length != buildedAssetPaths.Length)

View File

@ -240,7 +240,7 @@ namespace YooAsset.Editor
// 添加包裹元素 // 添加包裹元素
var packageElement = xmlDoc.CreateElement(XmlPackage); var packageElement = xmlDoc.CreateElement(XmlPackage);
packageElement.SetAttribute(XmlPackageName, "Default Package"); packageElement.SetAttribute(XmlPackageName, "DefaultPackage");
packageElement.SetAttribute(XmlPackageDesc, string.Empty); packageElement.SetAttribute(XmlPackageDesc, string.Empty);
root.AppendChild(packageElement); root.AppendChild(packageElement);

View File

@ -374,7 +374,7 @@ namespace YooAsset.Editor
private void AddPackageBtn_clicked() private void AddPackageBtn_clicked()
{ {
Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow AddPackage"); Undo.RecordObject(AssetBundleCollectorSettingData.Setting, "YooAsset.AssetBundleCollectorWindow AddPackage");
AssetBundleCollectorSettingData.CreatePackage("Default Package"); AssetBundleCollectorSettingData.CreatePackage("DefaultPackage");
FillPackageViewData(); FillPackageViewData();
} }
private void RemovePackageBtn_clicked() private void RemovePackageBtn_clicked()

View File

@ -66,7 +66,7 @@ namespace YooAsset.Editor
_items.Add(new ItemWrapper("构建平台", $"{buildReport.Summary.BuildTarget}")); _items.Add(new ItemWrapper("构建平台", $"{buildReport.Summary.BuildTarget}"));
_items.Add(new ItemWrapper("构建管线", $"{buildReport.Summary.BuildPipeline}")); _items.Add(new ItemWrapper("构建管线", $"{buildReport.Summary.BuildPipeline}"));
_items.Add(new ItemWrapper("构建模式", $"{buildReport.Summary.BuildMode}")); _items.Add(new ItemWrapper("构建模式", $"{buildReport.Summary.BuildMode}"));
_items.Add(new ItemWrapper("构建版本", $"{buildReport.Summary.BuildVersion}")); _items.Add(new ItemWrapper("构建包裹", $"{buildReport.Summary.BuildPackage}"));
_items.Add(new ItemWrapper("内置资源标签", $"{buildReport.Summary.BuildinTags}")); _items.Add(new ItemWrapper("内置资源标签", $"{buildReport.Summary.BuildinTags}"));
_items.Add(new ItemWrapper("启用可寻址资源定位", $"{buildReport.Summary.EnableAddressable}")); _items.Add(new ItemWrapper("启用可寻址资源定位", $"{buildReport.Summary.EnableAddressable}"));

View File

@ -353,6 +353,9 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public static void FileMoveTo(string filePath, string destPath) public static void FileMoveTo(string filePath, string destPath)
{ {
if (File.Exists(destPath))
File.Delete(destPath);
FileInfo fileInfo = new FileInfo(filePath); FileInfo fileInfo = new FileInfo(filePath);
fileInfo.MoveTo(destPath); fileInfo.MoveTo(destPath);
} }