com.alicizax.unity.ui.exten.../Editor/UIExtension/Text/UXTextMeshProEditor.cs
陈思海 5c45f9aa7b init
2025-02-07 16:15:34 +08:00

72 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AlicizaX.UI.Extension.Editor;
using UnityEditor;
namespace UnityEngine.UI
{
[CustomEditor(typeof(UXTextMeshPro), true)]
[CanEditMultipleObjects]
public class UXTextMeshProEditor : TMPro.EditorUtilities.TMP_EditorPanelUI
{
private SerializedProperty text;
private SerializedProperty localizationID;
protected override void OnEnable()
{
text = serializedObject.FindProperty("m_text");
localizationID = serializedObject.FindProperty("m_localizationID");
base.OnEnable();
}
protected override void OnDisable()
{
base.OnDisable();
}
public override void OnInspectorGUI()
{
serializedObject.Update();
bool isPlay = Application.isPlaying;
EditorGUI.BeginDisabledGroup(isPlay);
string[] keys = LocalizeStaticKey.GetAllStaticKeys();
int index = -1;
for (int i = 0; i < keys.Length; i++)
{
if (localizationID.stringValue == keys[i])
{
index = i;
break;
}
}
if (index == -1)
{
EditorGUILayout.HelpBox("对应的多语言Key找不到请重新配置", MessageType.Warning);
}
int selectedIndex = EditorGUILayout.Popup("Key", index, keys);
if (selectedIndex != index)
{
localizationID.stringValue = keys[selectedIndex];
}
EditorGUI.EndDisabledGroup();
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.PropertyField(localizationID, new GUIContent("key"));
if (!string.IsNullOrEmpty(localizationID.stringValue) && localizationID.stringValue != "None")
{
text.stringValue = LocalizeStaticKey.GetText(localizationID.stringValue);
}
EditorGUI.EndDisabledGroup();
serializedObject.ApplyModifiedProperties();
base.OnInspectorGUI();
}
}
}