Skip to content

Commit c5d39da

Browse files
committed
feat: AddTMP_LocalizersToResources
1 parent 51ebfeb commit c5d39da

2 files changed

Lines changed: 106 additions & 0 deletions

File tree

Assets/Code/Localization/Editor/LocalizationEditorWindow.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Code.Localization.Code;
66
using Sirenix.OdinInspector;
77
using Sirenix.OdinInspector.Editor;
8+
using TMPro;
89
using UnityEditor;
910
using UnityEngine;
1011

@@ -191,6 +192,41 @@ private void ApplyLocalizationKeyChangesToAssets()
191192
Debug.Log("✅ Localization keys in assets updated.");
192193
}
193194

195+
[FoldoutGroup("Add Missing Localizers", expanded: true)]
196+
[Button("➕ Add TMP_Localizer to All TMP_Text In Resources", ButtonSizes.Large), GUIColor(0.8f, 0.9f, 1f)]
197+
private void AddTMP_LocalizersToResources()
198+
{
199+
int addedCount = 0;
200+
201+
GameObject[] allPrefabs = Resources.LoadAll<GameObject>("");
202+
foreach (var prefab in allPrefabs)
203+
{
204+
if (prefab == null) continue;
205+
206+
var path = AssetDatabase.GetAssetPath(prefab);
207+
if (string.IsNullOrEmpty(path)) continue;
208+
209+
var root = PrefabUtility.LoadPrefabContents(path);
210+
var texts = root.GetComponentsInChildren<TMP_Text>(true);
211+
212+
foreach (var text in texts)
213+
{
214+
if (text.GetComponent<LocalizeBase>() == null)
215+
{
216+
Undo.RecordObject(text.gameObject, "Add TMP_Localizer");
217+
text.gameObject.AddComponent<TMP_Localizer>();
218+
addedCount++;
219+
}
220+
}
221+
222+
PrefabUtility.SaveAsPrefabAsset(root, path);
223+
PrefabUtility.UnloadPrefabContents(root);
224+
}
225+
226+
AssetDatabase.SaveAssets();
227+
Debug.Log($"✅ Added TMP_Localizer to {addedCount} TMP_Text objects.");
228+
}
229+
194230
private void LoadLocalizationFile()
195231
{
196232
_entries.Clear();

Assets/Resources/UI/GameHud.prefab

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ GameObject:
1111
- component: {fileID: 8278398173702700151}
1212
- component: {fileID: 1432474456044828018}
1313
- component: {fileID: 2703089668246871777}
14+
- component: {fileID: 3843392124701238742}
1415
m_Layer: 5
1516
m_Name: Text_Sound
1617
m_TagString: Untagged
@@ -134,6 +135,19 @@ MonoBehaviour:
134135
m_hasFontAssetChanged: 0
135136
m_baseMaterial: {fileID: 0}
136137
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
138+
--- !u!114 &3843392124701238742
139+
MonoBehaviour:
140+
m_ObjectHideFlags: 0
141+
m_CorrespondingSourceObject: {fileID: 0}
142+
m_PrefabInstance: {fileID: 0}
143+
m_PrefabAsset: {fileID: 0}
144+
m_GameObject: {fileID: 64437009225817884}
145+
m_Enabled: 1
146+
m_EditorHideFlags: 0
147+
m_Script: {fileID: 11500000, guid: 836a40dddfacaeb4384366e730750713, type: 3}
148+
m_Name:
149+
m_EditorClassIdentifier:
150+
localizationKey:
137151
--- !u!1 &1209532665223585865
138152
GameObject:
139153
m_ObjectHideFlags: 0
@@ -278,6 +292,7 @@ GameObject:
278292
- component: {fileID: 305529205899255656}
279293
- component: {fileID: 5603375788990825691}
280294
- component: {fileID: 8802848066749572383}
295+
- component: {fileID: 5002731635053105105}
281296
m_Layer: 5
282297
m_Name: Text_Button
283298
m_TagString: Untagged
@@ -401,6 +416,19 @@ MonoBehaviour:
401416
m_hasFontAssetChanged: 0
402417
m_baseMaterial: {fileID: 0}
403418
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
419+
--- !u!114 &5002731635053105105
420+
MonoBehaviour:
421+
m_ObjectHideFlags: 0
422+
m_CorrespondingSourceObject: {fileID: 0}
423+
m_PrefabInstance: {fileID: 0}
424+
m_PrefabAsset: {fileID: 0}
425+
m_GameObject: {fileID: 1873461456170480768}
426+
m_Enabled: 1
427+
m_EditorHideFlags: 0
428+
m_Script: {fileID: 11500000, guid: 836a40dddfacaeb4384366e730750713, type: 3}
429+
m_Name:
430+
m_EditorClassIdentifier:
431+
localizationKey:
404432
--- !u!1 &2227846456864619828
405433
GameObject:
406434
m_ObjectHideFlags: 0
@@ -597,6 +625,7 @@ GameObject:
597625
- component: {fileID: 8580054027949525529}
598626
- component: {fileID: 1541270637549917980}
599627
- component: {fileID: 8204655942856900796}
628+
- component: {fileID: 4626021855402352789}
600629
m_Layer: 5
601630
m_Name: Text_Button
602631
m_TagString: Untagged
@@ -720,6 +749,19 @@ MonoBehaviour:
720749
m_hasFontAssetChanged: 0
721750
m_baseMaterial: {fileID: 0}
722751
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
752+
--- !u!114 &4626021855402352789
753+
MonoBehaviour:
754+
m_ObjectHideFlags: 0
755+
m_CorrespondingSourceObject: {fileID: 0}
756+
m_PrefabInstance: {fileID: 0}
757+
m_PrefabAsset: {fileID: 0}
758+
m_GameObject: {fileID: 3474973785348890874}
759+
m_Enabled: 1
760+
m_EditorHideFlags: 0
761+
m_Script: {fileID: 11500000, guid: 836a40dddfacaeb4384366e730750713, type: 3}
762+
m_Name:
763+
m_EditorClassIdentifier:
764+
localizationKey:
723765
--- !u!1 &4526269673209905105
724766
GameObject:
725767
m_ObjectHideFlags: 0
@@ -997,6 +1039,7 @@ GameObject:
9971039
- component: {fileID: 2342595119916165433}
9981040
- component: {fileID: 784651582178854056}
9991041
- component: {fileID: 6341152590287427063}
1042+
- component: {fileID: 5396511025127154734}
10001043
m_Layer: 5
10011044
m_Name: Text_Button
10021045
m_TagString: Untagged
@@ -1120,6 +1163,19 @@ MonoBehaviour:
11201163
m_hasFontAssetChanged: 0
11211164
m_baseMaterial: {fileID: 0}
11221165
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
1166+
--- !u!114 &5396511025127154734
1167+
MonoBehaviour:
1168+
m_ObjectHideFlags: 0
1169+
m_CorrespondingSourceObject: {fileID: 0}
1170+
m_PrefabInstance: {fileID: 0}
1171+
m_PrefabAsset: {fileID: 0}
1172+
m_GameObject: {fileID: 5173320831620447260}
1173+
m_Enabled: 1
1174+
m_EditorHideFlags: 0
1175+
m_Script: {fileID: 11500000, guid: 836a40dddfacaeb4384366e730750713, type: 3}
1176+
m_Name:
1177+
m_EditorClassIdentifier:
1178+
localizationKey:
11231179
--- !u!1 &5222434654072416771
11241180
GameObject:
11251181
m_ObjectHideFlags: 0
@@ -1318,6 +1374,7 @@ GameObject:
13181374
- component: {fileID: 297070466131320601}
13191375
- component: {fileID: 5751707108438963087}
13201376
- component: {fileID: 6140615958831474822}
1377+
- component: {fileID: 6396163930544909434}
13211378
m_Layer: 5
13221379
m_Name: Text_Exit
13231380
m_TagString: Untagged
@@ -1441,6 +1498,19 @@ MonoBehaviour:
14411498
m_hasFontAssetChanged: 0
14421499
m_baseMaterial: {fileID: 0}
14431500
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
1501+
--- !u!114 &6396163930544909434
1502+
MonoBehaviour:
1503+
m_ObjectHideFlags: 0
1504+
m_CorrespondingSourceObject: {fileID: 0}
1505+
m_PrefabInstance: {fileID: 0}
1506+
m_PrefabAsset: {fileID: 0}
1507+
m_GameObject: {fileID: 8254333396611359024}
1508+
m_Enabled: 1
1509+
m_EditorHideFlags: 0
1510+
m_Script: {fileID: 11500000, guid: 836a40dddfacaeb4384366e730750713, type: 3}
1511+
m_Name:
1512+
m_EditorClassIdentifier:
1513+
localizationKey:
14441514
--- !u!1 &8664315041680610172
14451515
GameObject:
14461516
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)