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.Runtime;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
namespace UnityEngine.UI
@ -12,14 +13,12 @@ namespace UnityEngine.UI
{
private SerializedProperty text;
private SerializedProperty localizationID;
private List<LocalizationMasterConfig.LanguageEntry> _entries;
protected override void OnEnable()
{
text = serializedObject.FindProperty("m_text");
localizationID = serializedObject.FindProperty("m_localizationID");
base.OnEnable();
_entries = LocalizationMasterConfig.GetAllEntries();
}
public override void OnInspectorGUI()
@ -28,56 +27,24 @@ namespace UnityEngine.UI
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选择逻辑
EditorGUI.BeginDisabledGroup(isPlay);
{
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))
{
EditorGUILayout.HelpBox("当前Key在配置文件中不存在", MessageType.Warning);
}
// 绘制Key下拉菜单
int newIndex = EditorGUILayout.Popup("本地化Key", currentIndex, keys);
if (newIndex != currentIndex && newIndex >= 0)
{
localizationID.stringValue = keys[newIndex];
text.stringValue = _entries[newIndex].ChineseSimplified;
}
}
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();
//
// // 显示预览信息
// 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();
base.OnInspectorGUI();