Update AssetBundleBuilder

增加首包资源文件拷贝选项
pull/51/head
hevinci 2022-10-09 11:54:26 +08:00
parent fc575f5bc0
commit a348d9131d
10 changed files with 207 additions and 1 deletions

View File

@ -59,6 +59,7 @@ namespace YooAsset.Editor
new TaskCreatePatchManifest(), //创建清单文件 new TaskCreatePatchManifest(), //创建清单文件
new TaskCreateReport(), //创建报告文件 new TaskCreateReport(), //创建报告文件
new TaskCreatePatchPackage(), //制作补丁包 new TaskCreatePatchPackage(), //制作补丁包
new TaskCopyBuildinFiles(), //拷贝内置文件
}; };
} }
else if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline) else if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
@ -73,6 +74,7 @@ namespace YooAsset.Editor
new TaskCreatePatchManifest(), //创建清单文件 new TaskCreatePatchManifest(), //创建清单文件
new TaskCreateReport(), //创建报告文件 new TaskCreateReport(), //创建报告文件
new TaskCreatePatchPackage(), //制作补丁包 new TaskCreatePatchPackage(), //制作补丁包
new TaskCopyBuildinFiles(), //拷贝内置文件
}; };
} }
else else

View File

@ -30,6 +30,16 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public EOutputNameStyle OutputNameStyle = EOutputNameStyle.HashName; public EOutputNameStyle OutputNameStyle = EOutputNameStyle.HashName;
/// <summary>
/// 首包资源文件的拷贝方式
/// </summary>
public ECopyBuildinFileOption CopyBuildinFileOption = ECopyBuildinFileOption.None;
/// <summary>
/// 首包资源文件的标签集合
/// </summary>
public string CopyBuildinFileTags = string.Empty;
/// <summary> /// <summary>
/// 加密类名称 /// 加密类名称
/// </summary> /// </summary>

View File

@ -31,6 +31,8 @@ namespace YooAsset.Editor
private PopupField<string> _encryptionField; private PopupField<string> _encryptionField;
private EnumField _compressionField; private EnumField _compressionField;
private EnumField _outputNameStyleField; private EnumField _outputNameStyleField;
private EnumField _copyBuildinFileOptionField;
private TextField _copyBuildinFileTagsField;
public void CreateGUI() public void CreateGUI()
{ {
@ -135,7 +137,7 @@ namespace YooAsset.Editor
encryptionContainer.Add(_encryptionField); encryptionContainer.Add(_encryptionField);
} }
// 压缩方式 // 压缩方式选项
_compressionField = root.Q<EnumField>("Compression"); _compressionField = root.Q<EnumField>("Compression");
_compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption); _compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption);
_compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption); _compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption);
@ -157,6 +159,27 @@ namespace YooAsset.Editor
AssetBundleBuilderSettingData.Setting.OutputNameStyle = (EOutputNameStyle)_outputNameStyleField.value; AssetBundleBuilderSettingData.Setting.OutputNameStyle = (EOutputNameStyle)_outputNameStyleField.value;
}); });
// 首包文件拷贝选项
_copyBuildinFileOptionField = root.Q<EnumField>("CopyBuildinFileOption");
_copyBuildinFileOptionField.Init(AssetBundleBuilderSettingData.Setting.CopyBuildinFileOption);
_copyBuildinFileOptionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CopyBuildinFileOption);
_copyBuildinFileOptionField.style.width = 350;
_copyBuildinFileOptionField.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.CopyBuildinFileOption = (ECopyBuildinFileOption)_copyBuildinFileOptionField.value;
RefreshWindow();
});
// 首包文件的资源标签
_copyBuildinFileTagsField = root.Q<TextField>("CopyBuildinFileTags");
_copyBuildinFileTagsField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CopyBuildinFileTags);
_copyBuildinFileTagsField.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.CopyBuildinFileTags = _copyBuildinFileTagsField.value;
});
// 构建按钮 // 构建按钮
var buildButton = root.Q<Button>("Build"); var buildButton = root.Q<Button>("Build");
buildButton.clicked += BuildButton_clicked; ; buildButton.clicked += BuildButton_clicked; ;
@ -193,10 +216,15 @@ namespace YooAsset.Editor
private void RefreshWindow() private void RefreshWindow()
{ {
var buildMode = AssetBundleBuilderSettingData.Setting.BuildMode; var buildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
var copyOption = AssetBundleBuilderSettingData.Setting.CopyBuildinFileOption;
bool enableElement = buildMode == EBuildMode.ForceRebuild; bool enableElement = buildMode == EBuildMode.ForceRebuild;
bool tagsFiledVisible = copyOption == ECopyBuildinFileOption.ClearAndCopyByTags || copyOption == ECopyBuildinFileOption.OnlyCopyByTags;
_encryptionField.SetEnabled(enableElement); _encryptionField.SetEnabled(enableElement);
_compressionField.SetEnabled(enableElement); _compressionField.SetEnabled(enableElement);
_outputNameStyleField.SetEnabled(enableElement); _outputNameStyleField.SetEnabled(enableElement);
_copyBuildinFileOptionField.SetEnabled(enableElement);
_copyBuildinFileTagsField.SetEnabled(enableElement);
_copyBuildinFileTagsField.visible = tagsFiledVisible;
} }
private void SaveBtn_clicked() private void SaveBtn_clicked()
{ {
@ -233,6 +261,8 @@ namespace YooAsset.Editor
buildParameters.EncryptionServices = CreateEncryptionServicesInstance(); buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption; buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption;
buildParameters.OutputNameStyle = AssetBundleBuilderSettingData.Setting.OutputNameStyle; buildParameters.OutputNameStyle = AssetBundleBuilderSettingData.Setting.OutputNameStyle;
buildParameters.CopyBuildinFileOption = AssetBundleBuilderSettingData.Setting.CopyBuildinFileOption;
buildParameters.CopyBuildinFileTags = AssetBundleBuilderSettingData.Setting.CopyBuildinFileTags;
if (AssetBundleBuilderSettingData.Setting.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline) if (AssetBundleBuilderSettingData.Setting.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{ {

View File

@ -10,6 +10,8 @@
<ui:VisualElement name="EncryptionContainer" style="height: 24px;" /> <ui:VisualElement name="EncryptionContainer" style="height: 24px;" />
<uie:EnumField label="Compression" value="Center" name="Compression" /> <uie:EnumField label="Compression" value="Center" name="Compression" />
<uie:EnumField label="Output Name Style" value="Center" name="OutputNameStyle" /> <uie:EnumField label="Output Name Style" value="Center" name="OutputNameStyle" />
<uie:EnumField label="Copy Buildin File Option" value="Center" name="CopyBuildinFileOption" />
<ui:TextField picking-mode="Ignore" label="Copy Buildin File Tags" name="CopyBuildinFileTags" />
<ui:Button text="构建" display-tooltip-when-elided="true" name="Build" style="height: 50px; background-color: rgb(40, 106, 42); margin-top: 10px;" /> <ui:Button text="构建" display-tooltip-when-elided="true" name="Build" style="height: 50px; background-color: rgb(40, 106, 42); margin-top: 10px;" />
</ui:VisualElement> </ui:VisualElement>
</ui:UXML> </ui:UXML>

View File

@ -82,6 +82,16 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public EOutputNameStyle OutputNameStyle = EOutputNameStyle.HashName; public EOutputNameStyle OutputNameStyle = EOutputNameStyle.HashName;
/// <summary>
/// 拷贝内置资源选项
/// </summary>
public ECopyBuildinFileOption CopyBuildinFileOption = ECopyBuildinFileOption.None;
/// <summary>
/// 拷贝内置资源的标签
/// </summary>
public string CopyBuildinFileTags = string.Empty;
/// <summary> /// <summary>
/// 压缩选项 /// 压缩选项
/// </summary> /// </summary>

View File

@ -0,0 +1,87 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace YooAsset.Editor
{
[TaskAttribute("拷贝内置文件到流目录")]
public class TaskCopyBuildinFiles : IBuildTask
{
void IBuildTask.Run(BuildContext context)
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
if (buildParametersContext.Parameters.CopyBuildinFileOption != ECopyBuildinFileOption.None)
{
CopyBuildinFilesToStreaming(buildParametersContext);
}
}
/// <summary>
/// 拷贝首包资源文件
/// </summary>
private void CopyBuildinFilesToStreaming(BuildParametersContext buildParametersContext)
{
ECopyBuildinFileOption option = buildParametersContext.Parameters.CopyBuildinFileOption;
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
string streamingAssetsDirectory = AssetBundleBuilderHelper.GetStreamingAssetsFolderPath();
string buildPackageName = buildParametersContext.Parameters.BuildPackage;
string outputPackageCRC = buildParametersContext.OutputPackageCRC;
// 加载补丁清单
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(packageOutputDirectory, buildPackageName, outputPackageCRC);
// 清空流目录
if (option == ECopyBuildinFileOption.ClearAndCopyAll || option == ECopyBuildinFileOption.ClearAndCopyByTags)
{
AssetBundleBuilderHelper.ClearStreamingAssetsFolder();
}
// 拷贝补丁清单文件
{
string manifestFileName = YooAssetSettingsData.GetPatchManifestFileName(buildPackageName, outputPackageCRC);
string sourcePath = $"{packageOutputDirectory}/{manifestFileName}";
string destPath = $"{streamingAssetsDirectory}/{manifestFileName}";
EditorTools.CopyFile(sourcePath, destPath, true);
}
// 拷贝静态版本文件
{
string versionFileName = YooAssetSettingsData.GetStaticVersionFileName(buildPackageName);
string sourcePath = $"{packageOutputDirectory}/{versionFileName}";
string destPath = $"{streamingAssetsDirectory}/{versionFileName}";
EditorTools.CopyFile(sourcePath, destPath, true);
}
// 拷贝文件列表(所有文件)
if (option == ECopyBuildinFileOption.ClearAndCopyAll || option == ECopyBuildinFileOption.OnlyCopyAll)
{
foreach (var patchBundle in patchManifest.BundleList)
{
string sourcePath = $"{packageOutputDirectory}/{patchBundle.FileName}";
string destPath = $"{streamingAssetsDirectory}/{patchBundle.FileName}";
EditorTools.CopyFile(sourcePath, destPath, true);
}
}
// 拷贝文件列表(带标签的文件)
if (option == ECopyBuildinFileOption.ClearAndCopyByTags || option == ECopyBuildinFileOption.OnlyCopyByTags)
{
string[] tags = buildParametersContext.Parameters.CopyBuildinFileTags.Split(';');
foreach (var patchBundle in patchManifest.BundleList)
{
if (patchBundle.HasTag(tags) == false)
continue;
string sourcePath = $"{packageOutputDirectory}/{patchBundle.FileName}";
string destPath = $"{streamingAssetsDirectory}/{patchBundle.FileName}";
EditorTools.CopyFile(sourcePath, destPath, true);
}
}
// 刷新目录
AssetDatabase.Refresh();
BuildRunner.Log($"内置文件拷贝完成:{streamingAssetsDirectory}");
}
}
}

View File

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

View File

@ -32,9 +32,18 @@ namespace YooAsset.Editor
if (EditorTools.HasDirtyScenes()) if (EditorTools.HasDirtyScenes())
throw new Exception("检测到未保存的场景文件"); throw new Exception("检测到未保存的场景文件");
// 检测首包资源标签
if (buildParameters.CopyBuildinFileOption == ECopyBuildinFileOption.ClearAndCopyByTags
|| buildParameters.CopyBuildinFileOption == ECopyBuildinFileOption.OnlyCopyByTags)
{
if (string.IsNullOrEmpty(buildParameters.CopyBuildinFileTags))
throw new Exception("首包资源标签不能为空!");
}
// 保存改动的资源 // 保存改动的资源
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
} }
if (buildParameters.BuildMode == EBuildMode.ForceRebuild) if (buildParameters.BuildMode == EBuildMode.ForceRebuild)
{ {
// 删除平台总目录 // 删除平台总目录

View File

@ -0,0 +1,34 @@

namespace YooAsset.Editor
{
/// <summary>
/// 首包资源文件的拷贝方式
/// </summary>
public enum ECopyBuildinFileOption
{
/// <summary>
/// 不拷贝任何文件
/// </summary>
None = 0,
/// <summary>
/// 先清空已有文件,然后拷贝所有文件
/// </summary>
ClearAndCopyAll,
/// <summary>
/// 先清空已有文件,然后按照资源标签拷贝文件
/// </summary>
ClearAndCopyByTags,
/// <summary>
/// 不清空已有文件,直接拷贝所有文件
/// </summary>
OnlyCopyAll,
/// <summary>
/// 不清空已有文件,直接按照资源标签拷贝文件
/// </summary>
OnlyCopyByTags,
}
}

View File

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