Update AssetBundleBuilder

增加配置保存按钮。
pull/28/head
hevinci 2022-07-18 12:05:40 +08:00
parent 669339d5b4
commit ca3c011f34
3 changed files with 46 additions and 2 deletions

View File

@ -19,6 +19,11 @@ namespace YooAsset.Editor
} }
} }
/// <summary>
/// 配置数据是否被修改
/// </summary>
public static bool IsDirty { set; get; } = false;
/// <summary> /// <summary>
/// 加载配置文件 /// 加载配置文件
/// </summary> /// </summary>
@ -34,6 +39,7 @@ namespace YooAsset.Editor
{ {
if (Setting != null) if (Setting != null)
{ {
IsDirty = false;
EditorUtility.SetDirty(Setting); EditorUtility.SetDirty(Setting);
AssetDatabase.SaveAssets(); AssetDatabase.SaveAssets();
Debug.Log($"{nameof(AssetBundleBuilderSetting)}.asset is saved!"); Debug.Log($"{nameof(AssetBundleBuilderSetting)}.asset is saved!");

View File

@ -22,6 +22,7 @@ namespace YooAsset.Editor
private List<Type> _encryptionServicesClassTypes; private List<Type> _encryptionServicesClassTypes;
private List<string> _encryptionServicesClassNames; private List<string> _encryptionServicesClassNames;
private Button _saveButton;
private TextField _buildOutputField; private TextField _buildOutputField;
private IntegerField _buildVersionField; private IntegerField _buildVersionField;
private EnumField _buildPipelineField; private EnumField _buildPipelineField;
@ -44,7 +45,14 @@ namespace YooAsset.Editor
visualAsset.CloneTree(root); visualAsset.CloneTree(root);
// 配置保存按钮
_saveButton = root.Q<Button>("SaveButton");
_saveButton.clicked += SaveBtn_clicked;
// 构建平台
_buildTarget = EditorUserBuildSettings.activeBuildTarget; _buildTarget = EditorUserBuildSettings.activeBuildTarget;
// 加密服务类
_encryptionServicesClassTypes = GetEncryptionServicesClassTypes(); _encryptionServicesClassTypes = GetEncryptionServicesClassTypes();
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList(); _encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList();
@ -60,6 +68,7 @@ namespace YooAsset.Editor
_buildVersionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildVersion); _buildVersionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildVersion);
_buildVersionField.RegisterValueChangedCallback(evt => _buildVersionField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value; AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value;
}); });
@ -70,6 +79,7 @@ namespace YooAsset.Editor
_buildPipelineField.style.width = 300; _buildPipelineField.style.width = 300;
_buildPipelineField.RegisterValueChangedCallback(evt => _buildPipelineField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.BuildPipeline = (EBuildPipeline)_buildPipelineField.value; AssetBundleBuilderSettingData.Setting.BuildPipeline = (EBuildPipeline)_buildPipelineField.value;
RefreshWindow(); RefreshWindow();
}); });
@ -81,6 +91,7 @@ namespace YooAsset.Editor
_buildModeField.style.width = 300; _buildModeField.style.width = 300;
_buildModeField.RegisterValueChangedCallback(evt => _buildModeField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.BuildMode = (EBuildMode)_buildModeField.value; AssetBundleBuilderSettingData.Setting.BuildMode = (EBuildMode)_buildModeField.value;
RefreshWindow(); RefreshWindow();
}); });
@ -90,6 +101,7 @@ namespace YooAsset.Editor
_buildinTagsField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags); _buildinTagsField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags);
_buildinTagsField.RegisterValueChangedCallback(evt => _buildinTagsField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.BuildTags = _buildinTagsField.value; AssetBundleBuilderSettingData.Setting.BuildTags = _buildinTagsField.value;
}); });
@ -103,6 +115,7 @@ namespace YooAsset.Editor
_encryptionField.style.width = 300; _encryptionField.style.width = 300;
_encryptionField.RegisterValueChangedCallback(evt => _encryptionField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.EncyptionClassName = _encryptionField.value; AssetBundleBuilderSettingData.Setting.EncyptionClassName = _encryptionField.value;
}); });
encryptionContainer.Add(_encryptionField); encryptionContainer.Add(_encryptionField);
@ -122,6 +135,7 @@ namespace YooAsset.Editor
_compressionField.style.width = 300; _compressionField.style.width = 300;
_compressionField.RegisterValueChangedCallback(evt => _compressionField.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value; AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value;
}); });
@ -130,6 +144,7 @@ namespace YooAsset.Editor
_appendExtensionToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.AppendExtension); _appendExtensionToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.AppendExtension);
_appendExtensionToggle.RegisterValueChangedCallback(evt => _appendExtensionToggle.RegisterValueChangedCallback(evt =>
{ {
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.AppendExtension = _appendExtensionToggle.value; AssetBundleBuilderSettingData.Setting.AppendExtension = _appendExtensionToggle.value;
}); });
@ -146,7 +161,24 @@ namespace YooAsset.Editor
} }
public void OnDestroy() public void OnDestroy()
{ {
AssetBundleBuilderSettingData.SaveFile(); if(AssetBundleBuilderSettingData.IsDirty)
AssetBundleBuilderSettingData.SaveFile();
}
public void Update()
{
if(_saveButton != null)
{
if(AssetBundleBuilderSettingData.IsDirty)
{
if (_saveButton.enabledSelf == false)
_saveButton.SetEnabled(true);
}
else
{
if(_saveButton.enabledSelf)
_saveButton.SetEnabled(false);
}
}
} }
private void RefreshWindow() private void RefreshWindow()
@ -158,6 +190,10 @@ namespace YooAsset.Editor
_compressionField.SetEnabled(enableElement); _compressionField.SetEnabled(enableElement);
_appendExtensionToggle.SetEnabled(enableElement); _appendExtensionToggle.SetEnabled(enableElement);
} }
private void SaveBtn_clicked()
{
AssetBundleBuilderSettingData.SaveFile();
}
private void BuildButton_clicked() private void BuildButton_clicked()
{ {
var buildMode = AssetBundleBuilderSettingData.Setting.BuildMode; var buildMode = AssetBundleBuilderSettingData.Setting.BuildMode;

View File

@ -1,5 +1,7 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True"> <ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
<uie:Toolbar name="Toolbar" style="display: flex;" /> <uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;">
<ui:Button text="Save" display-tooltip-when-elided="true" name="SaveButton" style="background-color: rgb(56, 147, 58);" />
</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:IntegerField label="Build Version" value="0" name="BuildVersion" />