com.alicizax.unity.framework/Editor/UI/GenerateTool/UISettingEditorWindow.cs

105 lines
4.3 KiB
C#
Raw Normal View History

2025-09-05 19:46:30 +08:00
using System.Collections.Generic;
using Newtonsoft.Json;
using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor;
using UnityEditor;
using UnityEngine;
using UnityEngine.Windows;
namespace AlicizaX.UI.Editor
{
2025-09-10 14:26:54 +08:00
internal class UISettingEditorWindow : OdinEditorWindow
2025-09-05 19:46:30 +08:00
{
[MenuItem("Tools/AlicizaX/UI Setting Window")]
private static void OpenWindow()
{
GetWindow<UISettingEditorWindow>().Show();
}
protected override void Initialize()
{
uiGenerateConfiguration = UIGenerateConfiguration.Instance;
UIGenerateCommonData = uiGenerateConfiguration.UIGenerateCommonData;
UIScriptGenerateConfig = uiGenerateConfiguration.UIScriptGenerateConfig;
UIElementRegexConfigs = uiGenerateConfiguration.UIElementRegexConfigs;
RefreshLabel();
}
// [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]
public UIScriptGenerateConfig UIScriptGenerateConfig;
[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 = UIGlobalPath.DefaultComPath;
string text = System.IO.File.ReadAllText(Path);
UIElementRegexConfigs = JsonConvert.DeserializeObject<List<UIEelementRegexData>>(text);
}
[TabGroup("UI元素映射")]
[Sirenix.OdinInspector.Button("导出")]
private void ExportConfig()
{
var json = JsonConvert.SerializeObject(UIElementRegexConfigs);
System.IO.File.WriteAllText("Assets/uielementconfig.txt", json);
AssetDatabase.Refresh();
Debug.Log("Export UIElements Finished");
}
[TabGroup("UI元素映射")]
[Sirenix.OdinInspector.Button("导入")]
private void ImportConfig(TextAsset text)
{
UIElementRegexConfigs = JsonConvert.DeserializeObject<List<UIEelementRegexData>>(text.text);
Debug.Log("Import UIElements Finished");
}
protected override void OnDisable()
{
base.OnDisable();
uiGenerateConfiguration.UIGenerateCommonData = UIGenerateCommonData;
uiGenerateConfiguration.UIScriptGenerateConfig = UIScriptGenerateConfig;
uiGenerateConfiguration.UIElementRegexConfigs = UIElementRegexConfigs;
EditorUtility.SetDirty(uiGenerateConfiguration);
AssetDatabase.SaveAssets();
UIGenerateConfiguration.Save();
}
protected override void OnDestroy()
{
base.OnDestroy();
uiGenerateConfiguration.UIGenerateCommonData = UIGenerateCommonData;
uiGenerateConfiguration.UIScriptGenerateConfig = UIScriptGenerateConfig;
uiGenerateConfiguration.UIElementRegexConfigs = UIElementRegexConfigs;
EditorUtility.SetDirty(uiGenerateConfiguration);
AssetDatabase.SaveAssets();
UIGenerateConfiguration.Save();
}
}
}