AlicizaX/Client/Packages/com.alicizax.unity.ui/Editor/UIConfig/UIGenerateConfigurationTab.cs
2025-03-04 18:40:14 +08:00

72 lines
3.2 KiB
C#

using System.Collections.Generic;
using System.IO;
using AlicizaX.Editor;
using Newtonsoft.Json;
using Sirenix.OdinInspector;
using UnityEditor;
using UnityEngine;
namespace AlicizaX.UI.Editor
{
[System.Serializable]
[DisplayName("UI构建设置")]
internal sealed class UIGenerateConfigurationTab : GameFrameworkTabBase
{
// [Required] [InlineEditor(InlineEditorObjectFieldModes.CompletelyHidden)] [DisableInPlayMode] [HideLabel]
private UIGenerateConfiguration uiGenerateConfiguration;
[Required] [DisableInPlayMode] [HideLabel] [TabGroup("UI基础设置")] [SerializeField]
public UIGenerateCommonData UIGenerateCommonData;
[TabGroup("UI基础设置")] [LabelText("脚本生成预览")] [ShowInInspector] [ReadOnly] [OnValueChanged("RefreshLabel")]
private string previewLabel;
[TabGroup("UI基础设置")] [LabelText("组件生成预览")] [ShowInInspector] [ReadOnly] [OnValueChanged("RefreshLabel")]
[SuffixLabel("(下标0开始)")]
private string previewCompLabel;
[Required] [DisableInPlayMode] [HideLabel] [TabGroup("UI构建配置")] [SerializeField] [TableList(ShowIndexLabels = false, DrawScrollView = true, AlwaysExpanded = true)]
public List<UIScriptGenerateData> UIScriptGenerateConfigs;
[Required] [DisableInPlayMode] [HideLabel] [TabGroup("UI元素映射")] [SerializeField] [TableList(ShowIndexLabels = false, DrawScrollView = true, AlwaysExpanded = true)]
public List<UIEelementRegexData> UIElementRegexConfigs;
private void RefreshLabel()
{
previewLabel = $"{UIGenerateCommonData.GeneratePrefix}_UITestWindow";
previewCompLabel = $"{UIGenerateCommonData.ArrayComSplitName}Text{UIGenerateCommonData.ComCheckSplitName}Img" +
$"{UIGenerateCommonData.ComCheckEndName}Test{UIGenerateCommonData.ArrayComSplitName}0";
}
[TabGroup("UI元素映射")]
[Sirenix.OdinInspector.Button("加载默认")]
private void LoadDefaultConfig()
{
const string Path = "Packages/com.alicizax.unity.ui/Editor/Res/default.txt";
string text = System.IO.File.ReadAllText(Path);
UIElementRegexConfigs = JsonConvert.DeserializeObject<List<UIEelementRegexData>>(text);
}
public UIGenerateConfigurationTab()
{
uiGenerateConfiguration = UIGenerateConfiguration.Instance;
UIGenerateCommonData = uiGenerateConfiguration.UIGenerateCommonData;
UIScriptGenerateConfigs = uiGenerateConfiguration.UIScriptGenerateConfigs;
UIElementRegexConfigs = uiGenerateConfiguration.UIElementRegexConfigs;
RefreshLabel();
}
protected override void Save()
{
base.Save();
uiGenerateConfiguration.UIGenerateCommonData = UIGenerateCommonData;
uiGenerateConfiguration.UIScriptGenerateConfigs = UIScriptGenerateConfigs;
uiGenerateConfiguration.UIElementRegexConfigs = UIElementRegexConfigs;
EditorUtility.SetDirty(uiGenerateConfiguration);
AssetDatabase.SaveAssets();
UIGenerateConfiguration.Save();
}
}
}