修复着色器变种收集配置无法保存的问题。
pull/98/head^2
hevinci 2023-04-14 15:21:26 +08:00
parent 4e4da4440b
commit fd282d96d1
3 changed files with 42 additions and 3 deletions

View File

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

View File

@ -20,6 +20,7 @@ namespace YooAsset.Editor
private List<string> _packageNames;
private Button _saveButton;
private Button _collectButton;
private TextField _collectOutputField;
private Label _currentShaderCountField;
@ -40,6 +41,10 @@ namespace YooAsset.Editor
visualAsset.CloneTree(root);
// 配置保存按钮
_saveButton = root.Q<Button>("SaveButton");
_saveButton.clicked += SaveBtn_clicked;
// 包裹名称列表
_packageNames = GetBuildPackageNames();
@ -48,6 +53,7 @@ namespace YooAsset.Editor
_collectOutputField.SetValueWithoutNotify(ShaderVariantCollectorSettingData.Setting.SavePath);
_collectOutputField.RegisterValueChangedCallback(evt =>
{
ShaderVariantCollectorSettingData.IsDirty = true;
ShaderVariantCollectorSettingData.Setting.SavePath = _collectOutputField.value;
});
@ -61,6 +67,7 @@ namespace YooAsset.Editor
_packageField.style.width = 350;
_packageField.RegisterValueChangedCallback(evt =>
{
ShaderVariantCollectorSettingData.IsDirty = true;
ShaderVariantCollectorSettingData.Setting.CollectPackage = _packageField.value;
});
packageContainer.Add(_packageField);
@ -80,12 +87,14 @@ namespace YooAsset.Editor
_processCapacitySlider.label = $"Capacity ({_processCapacitySlider.value})";
_processCapacitySlider.RegisterValueChangedCallback(evt =>
{
ShaderVariantCollectorSettingData.IsDirty = true;
ShaderVariantCollectorSettingData.Setting.ProcessCapacity = _processCapacitySlider.value;
_processCapacitySlider.label = $"Capacity ({_processCapacitySlider.value})";
});
#else
_processCapacitySlider.RegisterValueChangedCallback(evt =>
{
ShaderVariantCollectorSettingData.IsDirty = true;
ShaderVariantCollectorSettingData.Setting.ProcessCapacity = _processCapacitySlider.value;
});
#endif
@ -102,8 +111,27 @@ namespace YooAsset.Editor
Debug.LogError(e.ToString());
}
}
public void OnDestroy()
{
if (ShaderVariantCollectorSettingData.IsDirty)
ShaderVariantCollectorSettingData.SaveFile();
}
private void Update()
{
if (_saveButton != null)
{
if (ShaderVariantCollectorSettingData.IsDirty)
{
if (_saveButton.enabledSelf == false)
_saveButton.SetEnabled(true);
}
else
{
if (_saveButton.enabledSelf)
_saveButton.SetEnabled(false);
}
}
if (_currentShaderCountField != null)
{
int currentShaderCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionShaderCount();
@ -117,6 +145,10 @@ namespace YooAsset.Editor
}
}
private void SaveBtn_clicked()
{
ShaderVariantCollectorSettingData.SaveFile();
}
private void CollectButton_clicked()
{
string savePath = ShaderVariantCollectorSettingData.Setting.SavePath;

View File

@ -1,6 +1,8 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements">
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<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(40, 106, 42);" />
</uie:Toolbar>
<ui:VisualElement name="CollectContainer">
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;" />
<ui:TextField picking-mode="Ignore" label="文件保存路径" name="CollectOutput" style="height: 22px;" />
<ui:VisualElement name="PackageContainer" style="height: 24px;" />
<ui:Label text="Current Shader Count" display-tooltip-when-elided="true" name="CurrentShaderCount" style="height: 20px; padding-left: 4px;" />