72 lines
2.1 KiB
C#
72 lines
2.1 KiB
C#
![]() |
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();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|