Update AssetBundleBuilder

增加输出文件名称样式的选择功能。
pull/28/head
hevinci 2022-07-23 17:39:04 +08:00
parent 6d392139df
commit 42d52720f3
10 changed files with 104 additions and 39 deletions

View File

@ -30,14 +30,14 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public ECompressOption CompressOption = ECompressOption.LZ4; public ECompressOption CompressOption = ECompressOption.LZ4;
/// <summary>
/// 输出文件名称样式
/// </summary>
public EOutputNameStyle OutputNameStyle = EOutputNameStyle.HashName;
/// <summary> /// <summary>
/// 加密类名称 /// 加密类名称
/// </summary> /// </summary>
public string EncyptionClassName = string.Empty; public string EncyptionClassName = string.Empty;
/// <summary>
/// 附加后缀格式
/// </summary>
public bool AppendExtension = false;
} }
} }

View File

@ -30,7 +30,7 @@ namespace YooAsset.Editor
private TextField _buildinTagsField; private TextField _buildinTagsField;
private PopupField<string> _encryptionField; private PopupField<string> _encryptionField;
private EnumField _compressionField; private EnumField _compressionField;
private Toggle _appendExtensionToggle; private EnumField _outputNameStyleField;
public void CreateGUI() public void CreateGUI()
{ {
@ -76,7 +76,7 @@ namespace YooAsset.Editor
_buildPipelineField = root.Q<EnumField>("BuildPipeline"); _buildPipelineField = root.Q<EnumField>("BuildPipeline");
_buildPipelineField.Init(AssetBundleBuilderSettingData.Setting.BuildPipeline); _buildPipelineField.Init(AssetBundleBuilderSettingData.Setting.BuildPipeline);
_buildPipelineField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildPipeline); _buildPipelineField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildPipeline);
_buildPipelineField.style.width = 300; _buildPipelineField.style.width = 350;
_buildPipelineField.RegisterValueChangedCallback(evt => _buildPipelineField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.IsDirty = true; AssetBundleBuilderSettingData.IsDirty = true;
@ -88,7 +88,7 @@ namespace YooAsset.Editor
_buildModeField = root.Q<EnumField>("BuildMode"); _buildModeField = root.Q<EnumField>("BuildMode");
_buildModeField.Init(AssetBundleBuilderSettingData.Setting.BuildMode); _buildModeField.Init(AssetBundleBuilderSettingData.Setting.BuildMode);
_buildModeField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildMode); _buildModeField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildMode);
_buildModeField.style.width = 300; _buildModeField.style.width = 350;
_buildModeField.RegisterValueChangedCallback(evt => _buildModeField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.IsDirty = true; AssetBundleBuilderSettingData.IsDirty = true;
@ -112,7 +112,7 @@ namespace YooAsset.Editor
int defaultIndex = GetEncryptionDefaultIndex(AssetBundleBuilderSettingData.Setting.EncyptionClassName); int defaultIndex = GetEncryptionDefaultIndex(AssetBundleBuilderSettingData.Setting.EncyptionClassName);
_encryptionField = new PopupField<string>(_encryptionServicesClassNames, defaultIndex); _encryptionField = new PopupField<string>(_encryptionServicesClassNames, defaultIndex);
_encryptionField.label = "Encryption"; _encryptionField.label = "Encryption";
_encryptionField.style.width = 300; _encryptionField.style.width = 350;
_encryptionField.RegisterValueChangedCallback(evt => _encryptionField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.IsDirty = true; AssetBundleBuilderSettingData.IsDirty = true;
@ -124,7 +124,7 @@ namespace YooAsset.Editor
{ {
_encryptionField = new PopupField<string>(); _encryptionField = new PopupField<string>();
_encryptionField.label = "Encryption"; _encryptionField.label = "Encryption";
_encryptionField.style.width = 300; _encryptionField.style.width = 350;
encryptionContainer.Add(_encryptionField); encryptionContainer.Add(_encryptionField);
} }
@ -132,20 +132,22 @@ namespace YooAsset.Editor
_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);
_compressionField.style.width = 300; _compressionField.style.width = 350;
_compressionField.RegisterValueChangedCallback(evt => _compressionField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.IsDirty = true; AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value; AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value;
}); });
// 附加后缀格式 // 输出文件名称样式
_appendExtensionToggle = root.Q<Toggle>("AppendExtension"); _outputNameStyleField = root.Q<EnumField>("OutputNameStyle");
_appendExtensionToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.AppendExtension); _outputNameStyleField.Init(AssetBundleBuilderSettingData.Setting.OutputNameStyle);
_appendExtensionToggle.RegisterValueChangedCallback(evt => _outputNameStyleField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.OutputNameStyle);
_outputNameStyleField.style.width = 350;
_outputNameStyleField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.IsDirty = true; AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.AppendExtension = _appendExtensionToggle.value; AssetBundleBuilderSettingData.Setting.OutputNameStyle = (EOutputNameStyle)_outputNameStyleField.value;
}); });
// 构建按钮 // 构建按钮
@ -188,7 +190,7 @@ namespace YooAsset.Editor
_buildinTagsField.SetEnabled(enableElement); _buildinTagsField.SetEnabled(enableElement);
_encryptionField.SetEnabled(enableElement); _encryptionField.SetEnabled(enableElement);
_compressionField.SetEnabled(enableElement); _compressionField.SetEnabled(enableElement);
_appendExtensionToggle.SetEnabled(enableElement); _outputNameStyleField.SetEnabled(enableElement);
} }
private void SaveBtn_clicked() private void SaveBtn_clicked()
{ {
@ -223,10 +225,10 @@ namespace YooAsset.Editor
buildParameters.BuildinTags = AssetBundleBuilderSettingData.Setting.BuildTags; buildParameters.BuildinTags = AssetBundleBuilderSettingData.Setting.BuildTags;
buildParameters.VerifyBuildingResult = true; buildParameters.VerifyBuildingResult = true;
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable; buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
buildParameters.AppendFileExtension = AssetBundleBuilderSettingData.Setting.AppendExtension;
buildParameters.CopyBuildinTagFiles = AssetBundleBuilderSettingData.Setting.BuildMode == EBuildMode.ForceRebuild; buildParameters.CopyBuildinTagFiles = AssetBundleBuilderSettingData.Setting.BuildMode == EBuildMode.ForceRebuild;
buildParameters.EncryptionServices = CreateEncryptionServicesInstance(); buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption; buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption;
buildParameters.OutputNameStyle = AssetBundleBuilderSettingData.Setting.OutputNameStyle;
if (AssetBundleBuilderSettingData.Setting.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline) if (AssetBundleBuilderSettingData.Setting.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{ {

View File

@ -9,7 +9,7 @@
<uie:EnumField label="Build Mode" name="BuildMode" /> <uie:EnumField label="Build Mode" name="BuildMode" />
<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" />
<ui:Toggle label="Append Extension" name="AppendExtension" style="height: 15px;" /> <uie:EnumField label="Output Name Style" value="Center" name="OutputNameStyle" />
<ui:TextField picking-mode="Ignore" label="Buildin Tags" name="BuildinTags" /> <ui:TextField picking-mode="Ignore" label="Buildin Tags" name="BuildinTags" />
<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>

View File

@ -77,12 +77,7 @@ namespace YooAsset.Editor
/// 启用可寻址资源定位 /// 启用可寻址资源定位
/// </summary> /// </summary>
public bool EnableAddressable = false; public bool EnableAddressable = false;
/// <summary>
/// 追加文件扩展名
/// </summary>
public bool AppendFileExtension = false;
/// <summary> /// <summary>
/// 拷贝内置资源文件到StreamingAssets目录首包资源文件 /// 拷贝内置资源文件到StreamingAssets目录首包资源文件
/// </summary> /// </summary>
@ -94,6 +89,11 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public IEncryptionServices EncryptionServices = null; public IEncryptionServices EncryptionServices = null;
/// <summary>
/// 补丁文件名称的样式
/// </summary>
public EOutputNameStyle OutputNameStyle = EOutputNameStyle.HashName;
/// <summary> /// <summary>
/// 压缩选项 /// 压缩选项
/// </summary> /// </summary>

View File

@ -58,11 +58,6 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public bool EnableAddressable; public bool EnableAddressable;
/// <summary>
/// 追加文件扩展名
/// </summary>
public bool AppendFileExtension;
/// <summary> /// <summary>
/// 拷贝内置资源文件 /// 拷贝内置资源文件
/// </summary> /// </summary>
@ -84,6 +79,7 @@ namespace YooAsset.Editor
public string EncryptionServicesClassName; public string EncryptionServicesClassName;
// 构建参数 // 构建参数
public EOutputNameStyle OutputNameStyle;
public ECompressOption CompressOption; public ECompressOption CompressOption;
public bool DisableWriteTypeTree; public bool DisableWriteTypeTree;
public bool IgnoreTypeTreeChanges; public bool IgnoreTypeTreeChanges;

View File

@ -69,6 +69,7 @@ namespace YooAsset.Editor
List<string> buildinTags = buildParameters.Parameters.GetBuildinTags(); List<string> buildinTags = buildParameters.Parameters.GetBuildinTags();
var buildMode = buildParameters.Parameters.BuildMode; var buildMode = buildParameters.Parameters.BuildMode;
var outputNameStype = buildParameters.Parameters.OutputNameStyle;
bool standardBuild = buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild; bool standardBuild = buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild;
foreach (var bundleInfo in buildMapContext.BundleInfos) foreach (var bundleInfo in buildMapContext.BundleInfos)
{ {
@ -82,13 +83,8 @@ namespace YooAsset.Editor
bool isBuildin = IsBuildinBundle(tags, buildinTags); bool isBuildin = IsBuildinBundle(tags, buildinTags);
bool isRawFile = bundleInfo.IsRawFile; bool isRawFile = bundleInfo.IsRawFile;
// 附加文件扩展名 string fileName = GetFileOutputName(outputNameStype, hash, bundleInfo);
if (buildParameters.Parameters.AppendFileExtension) PatchBundle patchBundle = new PatchBundle(bundleName, fileName, crc32, size, tags);
{
hash += bundleInfo.GetAppendExtension();
}
PatchBundle patchBundle = new PatchBundle(bundleName, hash, crc32, size, tags);
patchBundle.SetFlagsValue(isEncrypted, isBuildin, isRawFile); patchBundle.SetFlagsValue(isEncrypted, isBuildin, isRawFile);
result.Add(patchBundle); result.Add(patchBundle);
} }
@ -108,6 +104,37 @@ namespace YooAsset.Editor
} }
return false; return false;
} }
private string GetFileOutputName(EOutputNameStyle outputNameStyle, string hash, BuildBundleInfo bundleInfo)
{
string fileName;
var bundleName = bundleInfo.BundleName;
if (outputNameStyle == EOutputNameStyle.HashName)
{
fileName = hash;
}
else if (outputNameStyle == EOutputNameStyle.HashName_Extension)
{
string tempFileExtension = bundleInfo.GetAppendExtension();
fileName = $"{hash}{tempFileExtension}";
}
else if (outputNameStyle == EOutputNameStyle.BundleName_HashName)
{
string tempFileExtension = bundleInfo.GetAppendExtension();
string tempBundleName = bundleName.Replace('/', '_').Replace(tempFileExtension, "");
fileName = $"{tempBundleName}_{hash}";
}
else if (outputNameStyle == EOutputNameStyle.BundleName_HashName_Extension)
{
string tempFileExtension = bundleInfo.GetAppendExtension();
string tempBundleName = bundleName.Replace('/', '_').Replace(tempFileExtension, "");
fileName = $"{tempBundleName}_{hash}{tempFileExtension}";
}
else
{
throw new NotImplementedException();
}
return fileName;
}
private string GetFileHash(string filePath, bool standardBuild) private string GetFileHash(string filePath, bool standardBuild)
{ {
if (standardBuild) if (standardBuild)

View File

@ -47,7 +47,6 @@ namespace YooAsset.Editor
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion; buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion;
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags; buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
buildReport.Summary.EnableAddressable = buildParameters.Parameters.EnableAddressable; buildReport.Summary.EnableAddressable = buildParameters.Parameters.EnableAddressable;
buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension;
buildReport.Summary.CopyBuildinTagFiles = buildParameters.Parameters.CopyBuildinTagFiles; buildReport.Summary.CopyBuildinTagFiles = buildParameters.Parameters.CopyBuildinTagFiles;
buildReport.Summary.AutoCollectShaders = AssetBundleCollectorSettingData.Setting.AutoCollectShaders; buildReport.Summary.AutoCollectShaders = AssetBundleCollectorSettingData.Setting.AutoCollectShaders;
buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName; buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
@ -55,6 +54,7 @@ namespace YooAsset.Editor
"null" : buildParameters.Parameters.EncryptionServices.GetType().FullName; "null" : buildParameters.Parameters.EncryptionServices.GetType().FullName;
// 构建参数 // 构建参数
buildReport.Summary.OutputNameStyle = buildParameters.Parameters.OutputNameStyle;
buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption; buildReport.Summary.CompressOption = buildParameters.Parameters.CompressOption;
buildReport.Summary.DisableWriteTypeTree = buildParameters.Parameters.DisableWriteTypeTree; buildReport.Summary.DisableWriteTypeTree = buildParameters.Parameters.DisableWriteTypeTree;
buildReport.Summary.IgnoreTypeTreeChanges = buildParameters.Parameters.IgnoreTypeTreeChanges; buildReport.Summary.IgnoreTypeTreeChanges = buildParameters.Parameters.IgnoreTypeTreeChanges;

View File

@ -0,0 +1,29 @@

namespace YooAsset.Editor
{
/// <summary>
/// 输出文件名称的样式
/// </summary>
public enum EOutputNameStyle
{
/// <summary>
/// 000000000000000f000000000000000
/// </summary>
HashName,
/// <summary>
/// 000000000000000f000000000000000.bundle
/// </summary>
HashName_Extension,
/// <summary>
/// bundle_name_000000000000000f000000000000000
/// </summary>
BundleName_HashName,
/// <summary>
/// bundle_name_000000000000000f000000000000000.bundle
/// </summary>
BundleName_HashName_Extension,
}
}

View File

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

View File

@ -70,7 +70,6 @@ namespace YooAsset.Editor
_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}"));
_items.Add(new ItemWrapper("追加文件扩展名", $"{buildReport.Summary.AppendFileExtension}"));
_items.Add(new ItemWrapper("拷贝内置资源文件", $"{buildReport.Summary.CopyBuildinTagFiles}")); _items.Add(new ItemWrapper("拷贝内置资源文件", $"{buildReport.Summary.CopyBuildinTagFiles}"));
_items.Add(new ItemWrapper("自动收集着色器", $"{buildReport.Summary.AutoCollectShaders}")); _items.Add(new ItemWrapper("自动收集着色器", $"{buildReport.Summary.AutoCollectShaders}"));
_items.Add(new ItemWrapper("着色器资源包名称", $"{buildReport.Summary.ShadersBundleName}")); _items.Add(new ItemWrapper("着色器资源包名称", $"{buildReport.Summary.ShadersBundleName}"));
@ -78,6 +77,7 @@ namespace YooAsset.Editor
_items.Add(new ItemWrapper(string.Empty, string.Empty)); _items.Add(new ItemWrapper(string.Empty, string.Empty));
_items.Add(new ItemWrapper("构建参数", string.Empty)); _items.Add(new ItemWrapper("构建参数", string.Empty));
_items.Add(new ItemWrapper("OutputNameStyle", $"{buildReport.Summary.OutputNameStyle}"));
_items.Add(new ItemWrapper("CompressOption", $"{buildReport.Summary.CompressOption}")); _items.Add(new ItemWrapper("CompressOption", $"{buildReport.Summary.CompressOption}"));
_items.Add(new ItemWrapper("DisableWriteTypeTree", $"{buildReport.Summary.DisableWriteTypeTree}")); _items.Add(new ItemWrapper("DisableWriteTypeTree", $"{buildReport.Summary.DisableWriteTypeTree}"));
_items.Add(new ItemWrapper("IgnoreTypeTreeChanges", $"{buildReport.Summary.IgnoreTypeTreeChanges}")); _items.Add(new ItemWrapper("IgnoreTypeTreeChanges", $"{buildReport.Summary.IgnoreTypeTreeChanges}"));