Update AssetBundleBuilder

保留构建窗口界面的配置数据
pull/4/head
hevinci 2022-04-13 16:19:57 +08:00
parent 6bb3c17f82
commit 89bde69417
6 changed files with 160 additions and 8 deletions

View File

@ -0,0 +1,38 @@
using System;
using UnityEngine;
namespace YooAsset.Editor
{
public class AssetBundleBuilderSetting : ScriptableObject
{
/// <summary>
/// 构建版本号
/// </summary>
public int BuildVersion = 0;
/// <summary>
/// 压缩方式
/// </summary>
public ECompressOption CompressOption = ECompressOption.LZ4;
/// <summary>
/// 加密类名称
/// </summary>
public string EncyptionClassName = string.Empty;
/// <summary>
/// 附加后缀格式
/// </summary>
public bool AppendExtension = false;
/// <summary>
/// 强制构建
/// </summary>
public bool ForceRebuild = false;
/// <summary>
/// 内置标签
/// </summary>
public string BuildTags = string.Empty;
}
}

View File

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

View File

@ -0,0 +1,57 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
namespace YooAsset.Editor
{
public class AssetBundleBuilderSettingData
{
private static AssetBundleBuilderSetting _setting = null;
public static AssetBundleBuilderSetting Setting
{
get
{
if (_setting == null)
LoadSettingData();
return _setting;
}
}
/// <summary>
/// 加载配置文件
/// </summary>
private static void LoadSettingData()
{
// 加载配置文件
_setting = AssetDatabase.LoadAssetAtPath<AssetBundleBuilderSetting>(EditorDefine.AssetBundleBuilderSettingFilePath);
if (_setting == null)
{
Debug.LogWarning($"Create new {nameof(AssetBundleBuilderSetting)}.asset : {EditorDefine.AssetBundleBuilderSettingFilePath}");
_setting = ScriptableObject.CreateInstance<AssetBundleBuilderSetting>();
EditorTools.CreateFileDirectory(EditorDefine.AssetBundleBuilderSettingFilePath);
AssetDatabase.CreateAsset(Setting, EditorDefine.AssetBundleBuilderSettingFilePath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
else
{
Debug.Log($"Load {nameof(AssetBundleBuilderSetting)}.asset ok");
}
}
/// <summary>
/// 存储文件
/// </summary>
public static void SaveFile()
{
if (Setting != null)
{
EditorUtility.SetDirty(Setting);
AssetDatabase.SaveAssets();
Debug.Log($"{nameof(AssetBundleBuilderSetting)}.asset is saved!");
}
}
}
}

View File

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

View File

@ -61,23 +61,43 @@ namespace YooAsset.Editor
_buildOutputTxt.SetEnabled(false);
// 构建版本
var appVersion = new Version(Application.version);
_buildVersionField = root.Q<IntegerField>("BuildVersion");
_buildVersionField.SetValueWithoutNotify(appVersion.Revision);
_buildVersionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildVersion);
_buildVersionField.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value;
});
// 压缩方式
_compressionField = root.Q<EnumField>("Compression");
_compressionField.Init(ECompressOption.LZ4);
_compressionField.SetValueWithoutNotify(ECompressOption.LZ4);
_compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption);
_compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption);
_compressionField.style.width = 300;
_compressionField.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value;
});
// 加密方法
var encryptionContainer = root.Q("EncryptionContainer");
if (_encryptionServicesClassNames.Count > 0)
{
_encryptionField = new PopupField<string>(_encryptionServicesClassNames, 0);
int defaultIndex = 0;
for (int index = 0; index < _encryptionServicesClassNames.Count; index++)
{
if (_encryptionServicesClassNames[index] == AssetBundleBuilderSettingData.Setting.EncyptionClassName)
{
defaultIndex = index;
break;
}
}
_encryptionField = new PopupField<string>(_encryptionServicesClassNames, defaultIndex);
_encryptionField.label = "Encryption";
_encryptionField.style.width = 300;
_encryptionField.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.Setting.EncyptionClassName = _encryptionField.value;
});
encryptionContainer.Add(_encryptionField);
}
else
@ -90,18 +110,29 @@ namespace YooAsset.Editor
// 附加后缀格式
_appendExtensionToggle = root.Q<Toggle>("AppendExtension");
_appendExtensionToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.AppendExtension);
_appendExtensionToggle.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.Setting.AppendExtension = _appendExtensionToggle.value;
});
// 强制构建
_forceRebuildToggle = root.Q<Toggle>("ForceRebuild");
_forceRebuildToggle.SetValueWithoutNotify(true);
_forceRebuildToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.ForceRebuild);
_forceRebuildToggle.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.Setting.ForceRebuild = _forceRebuildToggle.value;
_buildTagsTxt.SetEnabled(_forceRebuildToggle.value);
});
// 内置标签
_buildTagsTxt = root.Q<TextField>("BuildinTags");
_buildTagsTxt.SetEnabled(_forceRebuildToggle.value);
_buildTagsTxt.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags);
_buildTagsTxt.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.Setting.BuildTags = _buildTagsTxt.value;
});
// 构建按钮
var buildButton = root.Q<Button>("Build");
@ -112,6 +143,10 @@ namespace YooAsset.Editor
Debug.LogError(e.ToString());
}
}
public void OnDestroy()
{
AssetBundleBuilderSettingData.SaveFile();
}
private void BuildButton_clicked()
{

View File

@ -4,9 +4,9 @@ namespace YooAsset.Editor
public class EditorDefine
{
/// <summary>
/// 资源包收集工具的配置文件存储路径
/// 资源包构建工具的配置文件存储路径
/// </summary>
public const string AssetBundleCollectorSettingFilePath = "Assets/YooAssetSetting/AssetBundleCollectorSetting.asset";
public const string AssetBundleBuilderSettingFilePath = "Assets/YooAssetSetting/AssetBundleBuilderSetting.asset";
/// <summary>
/// 资源包分组工具的配置文件存储路径