diff --git a/Editor/UX/UXTextMeshPro/UXTextMeshProEditor.cs b/Editor/UX/UXTextMeshPro/UXTextMeshProEditor.cs index 5f8b0e7..c28028c 100644 --- a/Editor/UX/UXTextMeshPro/UXTextMeshProEditor.cs +++ b/Editor/UX/UXTextMeshPro/UXTextMeshProEditor.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using AlicizaX.Localization; using AlicizaX.Localization.Editor; +using TMPro; using UnityEditor; using UnityEngine; using UnityEngine.UIElements; @@ -172,6 +173,7 @@ namespace UnityEngine.UI localizationID.intValue = 0; m_localizationKey.stringValue = string.Empty; selectedSelectionIndex = 0; + (target as TextMeshProUGUI).text = string.Empty; } else { @@ -186,7 +188,6 @@ namespace UnityEngine.UI } } } - serializedObject.ApplyModifiedProperties(); } } diff --git a/Runtime/UXComponent/Text/LocalizationRefreshHelper.cs b/Runtime/UXComponent/Text/LocalizationRefreshHelper.cs new file mode 100644 index 0000000..7ae6765 --- /dev/null +++ b/Runtime/UXComponent/Text/LocalizationRefreshHelper.cs @@ -0,0 +1,53 @@ +#if UNITY_EDITOR +using System.Collections.Generic; +using System.Linq; +using AlicizaX.Localization; +using AlicizaX.Localization.Runtime; +using UnityEditor; + +namespace UnityEngine.UI +{ + internal static class LocalizationRefreshHelper + { + private static Dictionary previewLabelDic = new(); + + internal static string GetPreviewLabel(string key) + { + Init(); + if (previewLabelDic.ContainsKey(key)) + { + return previewLabelDic[key]; + } + + return string.Empty; + } + + static void Init() + { + previewLabelDic.Clear(); + List allTables = new(); + string[] guids = AssetDatabase.FindAssets("t:GameLocaizationTable"); + foreach (string guid in guids) + { + string assetPath = AssetDatabase.GUIDToAssetPath(guid); + GameLocaizationTable table = AssetDatabase.LoadAssetAtPath(assetPath); + if (table != null) + { + allTables.Add(table); + } + } + + string language = EditorPrefs.GetString(LocalizationComponent.PrefsKey, "None"); + var localizationLanguage = allTables.Select(e => e.Languages.Find(t => t.LanguageName == language)).ToList(); + foreach (var localization in localizationLanguage) + { + foreach (var item in localization.Strings) + { + previewLabelDic.TryAdd(item.Key, item.Value); + } + } + } + } +} + +#endif diff --git a/Runtime/UXComponent/Text/LocalizationRefreshHelper.cs.meta b/Runtime/UXComponent/Text/LocalizationRefreshHelper.cs.meta new file mode 100644 index 0000000..4869a17 --- /dev/null +++ b/Runtime/UXComponent/Text/LocalizationRefreshHelper.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 169b0bd7883944ed897310ddf0085517 +timeCreated: 1765358242 \ No newline at end of file diff --git a/Runtime/UXComponent/Text/UXTextMeshPro.cs b/Runtime/UXComponent/Text/UXTextMeshPro.cs index b89b9fd..b31361e 100644 --- a/Runtime/UXComponent/Text/UXTextMeshPro.cs +++ b/Runtime/UXComponent/Text/UXTextMeshPro.cs @@ -9,6 +9,13 @@ namespace UnityEngine.UI [SerializeField] private int m_localizationID; [SerializeField] private string m_localizationKey = ""; +#if UNITY_EDITOR + protected override void OnValidate() + { + base.OnValidate(); + if (Application.isEditor) text = LocalizationRefreshHelper.GetPreviewLabel(m_localizationKey); + } +#endif protected override void Start() { base.Start();