This commit is contained in:
陈思海 2025-03-13 16:40:06 +08:00
parent 9d941a179d
commit dadd04238a

View File

@ -2,6 +2,7 @@ using System.Collections.Generic;
using AlicizaX.Localization.Editor; using AlicizaX.Localization.Editor;
using AlicizaX.Localization.Runtime; using AlicizaX.Localization.Runtime;
using UnityEditor; using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine; using UnityEngine;
namespace UnityEngine.UI namespace UnityEngine.UI
@ -12,14 +13,12 @@ namespace UnityEngine.UI
{ {
private SerializedProperty text; private SerializedProperty text;
private SerializedProperty localizationID; private SerializedProperty localizationID;
private List<LocalizationMasterConfig.LanguageEntry> _entries;
protected override void OnEnable() protected override void OnEnable()
{ {
text = serializedObject.FindProperty("m_text"); text = serializedObject.FindProperty("m_text");
localizationID = serializedObject.FindProperty("m_localizationID"); localizationID = serializedObject.FindProperty("m_localizationID");
base.OnEnable(); base.OnEnable();
_entries = LocalizationMasterConfig.GetAllEntries();
} }
public override void OnInspectorGUI() public override void OnInspectorGUI()
@ -28,56 +27,24 @@ namespace UnityEngine.UI
bool isPlay = Application.isPlaying; bool isPlay = Application.isPlaying;
// 准备Key列表
string[] keys = new string[_entries.Count];
for (int i = 0; i < _entries.Count; i++)
{
keys[i] = _entries[i].ID;
}
// Key选择逻辑 // Key选择逻辑
EditorGUI.BeginDisabledGroup(isPlay); EditorGUILayout.PropertyField(localizationID);
{
int currentIndex = -1;
for (int i = 0; i < keys.Length; i++)
{
if (localizationID.stringValue == keys[i])
{
currentIndex = i;
break;
}
}
// 显示警告如果Key不存在 //
if (currentIndex == -1 && !string.IsNullOrEmpty(localizationID.stringValue)) // // 显示预览信息
{ // EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.HelpBox("当前Key在配置文件中不存在", MessageType.Warning); // {
} // EditorGUILayout.PropertyField(localizationID);
// if (!string.IsNullOrEmpty(localizationID.stringValue))
// 绘制Key下拉菜单 // {
int newIndex = EditorGUILayout.Popup("本地化Key", currentIndex, keys); // var entry = _entries.Find(e => e.ID == localizationID.stringValue);
if (newIndex != currentIndex && newIndex >= 0) // if (entry != null)
{ // {
localizationID.stringValue = keys[newIndex]; // EditorGUILayout.TextField("当前文本预览", entry.ChineseSimplified);
text.stringValue = _entries[newIndex].ChineseSimplified; // }
} // }
} // }
EditorGUI.EndDisabledGroup(); // EditorGUI.EndDisabledGroup();
// 显示预览信息
EditorGUI.BeginDisabledGroup(true);
{
EditorGUILayout.PropertyField(localizationID);
if (!string.IsNullOrEmpty(localizationID.stringValue))
{
var entry = _entries.Find(e => e.ID == localizationID.stringValue);
if (entry != null)
{
EditorGUILayout.TextField("当前文本预览", entry.ChineseSimplified);
}
}
}
EditorGUI.EndDisabledGroup();
serializedObject.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties();
base.OnInspectorGUI(); base.OnInspectorGUI();