diff --git a/Editor/UX/UXTextMeshPro.meta b/Editor/UX/UXTextMeshPro.meta new file mode 100644 index 0000000..6b13c04 --- /dev/null +++ b/Editor/UX/UXTextMeshPro.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: bcd7a6d11834494097fd3fd07be556bb +timeCreated: 1760516522 \ No newline at end of file diff --git a/Editor/UX/UXTextMeshProEditor.cs b/Editor/UX/UXTextMeshPro/UXTextMeshProEditor.cs similarity index 100% rename from Editor/UX/UXTextMeshProEditor.cs rename to Editor/UX/UXTextMeshPro/UXTextMeshProEditor.cs diff --git a/Editor/UX/UXTextMeshProEditor.cs.meta b/Editor/UX/UXTextMeshPro/UXTextMeshProEditor.cs.meta similarity index 100% rename from Editor/UX/UXTextMeshProEditor.cs.meta rename to Editor/UX/UXTextMeshPro/UXTextMeshProEditor.cs.meta diff --git a/Editor/UX/UXTextMeshPro/UXTextMeshProLocalization.cs b/Editor/UX/UXTextMeshPro/UXTextMeshProLocalization.cs new file mode 100644 index 0000000..1271fc3 --- /dev/null +++ b/Editor/UX/UXTextMeshPro/UXTextMeshProLocalization.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using AlicizaX.Localization; +using UnityEditor; + +namespace UnityEngine.UI +{ + internal static class UXTextMeshProLocalization + { + [MenuItem("Tools/AlicizaX/Localization/Update UXTextMeshPro Localization Refrencee")] + static void UpdateUXTextMeshProLocalizationRefrence() + { + List allTables = new(); + Dictionary allTableNames = new(); + + string[] tablesGuids = AssetDatabase.FindAssets("t:GameLocaizationTable"); + foreach (string guid in tablesGuids) + { + string assetPath = AssetDatabase.GUIDToAssetPath(guid); + GameLocaizationTable table = AssetDatabase.LoadAssetAtPath(assetPath); + if (table != null) + { + allTables.Add(table); + } + } + + foreach (var table in allTables) + { + foreach (var sheet in table.TableSheet) + { + foreach (var selection in sheet.SectionSheet) + { + string combineKey = $"{table.name}/{sheet.SectionName}/{selection.Key}"; + string combineValue = $"{sheet.SectionName}.{selection.Key}"; + int id = selection.Id; + allTableNames.TryAdd(id, new TableSelectionData(id, combineKey, combineValue)); + } + } + } + + string[] guids = AssetDatabase.FindAssets("t:Prefab"); + foreach (string guid in guids) + { + string assetPath = AssetDatabase.GUIDToAssetPath(guid); + GameObject prefab = AssetDatabase.LoadAssetAtPath(assetPath); + + GameObject prefabInstance = (GameObject)PrefabUtility.InstantiatePrefab(prefab); + if (prefabInstance == null) continue; + + + UXTextMeshPro[] components = prefabInstance.GetComponentsInChildren(true); + bool updated = false; + + foreach (UXTextMeshPro component in components) + { + if (component == null) + continue; + + FieldInfo localizationId = component.GetType().GetField("m_localizationID", BindingFlags.NonPublic | BindingFlags.Instance); + FieldInfo localizationKey = component.GetType().GetField("m_localizationKey", BindingFlags.NonPublic | BindingFlags.Instance); + + int localizationIDValue = (int)localizationId.GetValue(component); + string localizationKeyValue = (string)localizationKey.GetValue(component); + if (allTableNames.TryGetValue(localizationIDValue, out TableSelectionData data)) + { + if (!localizationKeyValue.Equals(data.CombineValue)) + { + updated = true; + component.GetType().GetField("m_localizationKey", BindingFlags.NonPublic | BindingFlags.Instance)?.SetValue(component, data.CombineValue); + } + } + } + + if (updated) + { + PrefabUtility.SaveAsPrefabAsset(prefabInstance, assetPath); + Debug.Log($"Updated Refrence in '{prefab.name}' ({assetPath})"); + } + + Object.DestroyImmediate(prefabInstance); + } + + Debug.Log("Update Localization Refrencee Compeleted"); + } + } +} diff --git a/Editor/UX/UXTextMeshPro/UXTextMeshProLocalization.cs.meta b/Editor/UX/UXTextMeshPro/UXTextMeshProLocalization.cs.meta new file mode 100644 index 0000000..e84095a --- /dev/null +++ b/Editor/UX/UXTextMeshPro/UXTextMeshProLocalization.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5187aa23e60a462b953161106e73f599 +timeCreated: 1760516554 \ No newline at end of file