Skip to content

Commit 51ebfeb

Browse files
committed
feat: FindTMPLocalizersInAssets
1 parent e5940f3 commit 51ebfeb

4 files changed

Lines changed: 124 additions & 44 deletions

File tree

Assets/Code/Localization/Editor/LocalizationEditorWindow.cs

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using System.IO;
5+
using Code.Localization.Code;
56
using Sirenix.OdinInspector;
67
using Sirenix.OdinInspector.Editor;
78
using UnityEditor;
@@ -18,7 +19,7 @@ private static void OpenWindow()
1819
{
1920
var window = GetWindow<LocalizationEditorWindow>();
2021
window.titleContent = new GUIContent("Localization Editor");
21-
window.minSize = new Vector2(600, 500);
22+
window.minSize = new Vector2(600, 800);
2223
window.Show();
2324
}
2425

@@ -89,17 +90,17 @@ private void DeleteSelectedLanguage()
8990
}
9091
}
9192

92-
[FoldoutGroup("Add New Language", expanded: true)]
93+
[FoldoutGroup("Create New Language TxT", expanded: true)]
9394
[ShowInInspector, PropertyOrder(0)]
9495
[ValueDropdown("GetNewLanguages")]
95-
private SystemLanguage _NewLanguage = SystemLanguage.Afrikaans;
96+
private SystemLanguage _NewLanguage = SystemLanguage.Unknown;
9697

97-
[FoldoutGroup("Add New Language")]
98+
[FoldoutGroup("Create New Language TxT")]
9899
[ShowInInspector, PropertyOrder(1)]
99100
[ValueDropdown("GetAvailableLanguages")]
100101
private string _BaseLanguage = "English";
101102

102-
[FoldoutGroup("Add New Language")]
103+
[FoldoutGroup("Create New Language TxT")]
103104
[ShowInInspector, PropertyOrder(2)]
104105
[Button("🆕 Create New Language From Base", ButtonSizes.Large), GUIColor(0.1f, 0.8f, 1f)]
105106
private void CreateNewLanguageFromBase()
@@ -126,6 +127,70 @@ private void CreateNewLanguageFromBase()
126127
Debug.Log($"✅ Created '{newLang}' from '{_BaseLanguage}'.");
127128
}
128129

130+
[FoldoutGroup("Find Localized Assets")]
131+
[TableList(AlwaysExpanded = true)]
132+
[ShowInInspector]
133+
private List<TMPAssetEntry> _localizersInAssets = new();
134+
135+
[FoldoutGroup("Find Localized Assets", expanded: true)]
136+
[Button("📁 Find All TMP_Localizers in Resources", ButtonSizes.Large), GUIColor(0.1f, 0.8f, 1f)]
137+
private void FindTMPLocalizersInAssets()
138+
{
139+
_localizersInAssets.Clear();
140+
141+
string[] guids = AssetDatabase.FindAssets("t:Prefab", new[] { "Assets" });
142+
foreach (string guid in guids)
143+
{
144+
string path = AssetDatabase.GUIDToAssetPath(guid);
145+
GameObject prefabRoot = PrefabUtility.LoadPrefabContents(path);
146+
if (prefabRoot == null)
147+
{
148+
Debug.LogWarning($"❌ Failed to load prefab contents: {path}");
149+
continue;
150+
}
151+
152+
LocalizeBase[] localizers = prefabRoot.GetComponentsInChildren<LocalizeBase>(true);
153+
154+
foreach (var localizer in localizers)
155+
{
156+
string objName = localizer.gameObject.name;
157+
string parentName = localizer.transform.parent != null ? localizer.transform.parent.name : "(root)";
158+
string childName = localizer.transform.childCount > 0 ? localizer.transform.GetChild(0).name : "(no child)";
159+
160+
_localizersInAssets.Add(new TMPAssetEntry
161+
{
162+
AssetPath = path,
163+
GameObjectName = objName,
164+
ParentName = parentName,
165+
ChildName = childName,
166+
Component = localizer,
167+
LocalizationKey = localizer.localizationKey
168+
});
169+
}
170+
171+
PrefabUtility.UnloadPrefabContents(prefabRoot);
172+
}
173+
174+
Debug.Log($"✅ Done! Total found TMP_Localizers in prefabs: {_localizersInAssets.Count}");
175+
}
176+
177+
[FoldoutGroup("Find Localized Assets")]
178+
[Button("💾 Save Changes To Assets", ButtonSizes.Large), GUIColor(0.6f, 1f, 0.6f)]
179+
private void ApplyLocalizationKeyChangesToAssets()
180+
{
181+
foreach (var entry in _localizersInAssets)
182+
{
183+
if (entry.Component == null) continue;
184+
185+
Undo.RecordObject(entry.Component, "Change Localization Key");
186+
entry.Component.localizationKey = entry.LocalizationKey;
187+
EditorUtility.SetDirty(entry.Component);
188+
}
189+
190+
AssetDatabase.SaveAssets();
191+
Debug.Log("✅ Localization keys in assets updated.");
192+
}
193+
129194
private void LoadLocalizationFile()
130195
{
131196
_entries.Clear();
@@ -201,6 +266,28 @@ public class LocalizationEntry
201266
[MultiLineProperty(2)]
202267
public string Value;
203268
}
269+
270+
[Serializable]
271+
public class TMPAssetEntry
272+
{
273+
[ReadOnly, TableColumnWidth(200)]
274+
public string GameObjectName;
275+
276+
[ReadOnly, TableColumnWidth(150)]
277+
public string ParentName;
278+
279+
[ReadOnly, TableColumnWidth(150)]
280+
public string ChildName;
281+
282+
[ReadOnly, TableColumnWidth(300)]
283+
public string AssetPath;
284+
285+
[HideInInspector]
286+
public LocalizeBase Component;
287+
288+
[TableColumnWidth(400, resizable: true)]
289+
public string LocalizationKey;
290+
}
204291
}
205292
}
206293
#endif

Assets/Code/Localization/Editor/TMPTextWithLocalizationEditor.cs

Lines changed: 0 additions & 24 deletions
This file was deleted.

Assets/Code/Localization/Editor/TMPTextWithLocalizationEditor.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Assets/Resources/UI/GameHud.prefab

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ GameObject:
449449
- component: {fileID: 2946530545023338009}
450450
- component: {fileID: 4968532830018370828}
451451
- component: {fileID: 6745997590823684149}
452+
- component: {fileID: 8441029816296931728}
452453
m_Layer: 5
453454
m_Name: Text_GameOver
454455
m_TagString: Untagged
@@ -572,6 +573,19 @@ MonoBehaviour:
572573
m_hasFontAssetChanged: 0
573574
m_baseMaterial: {fileID: 0}
574575
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
576+
--- !u!114 &8441029816296931728
577+
MonoBehaviour:
578+
m_ObjectHideFlags: 0
579+
m_CorrespondingSourceObject: {fileID: 0}
580+
m_PrefabInstance: {fileID: 0}
581+
m_PrefabAsset: {fileID: 0}
582+
m_GameObject: {fileID: 2243239779776556166}
583+
m_Enabled: 1
584+
m_EditorHideFlags: 0
585+
m_Script: {fileID: 11500000, guid: 836a40dddfacaeb4384366e730750713, type: 3}
586+
m_Name:
587+
m_EditorClassIdentifier:
588+
localizationKey:
575589
--- !u!1 &3474973785348890874
576590
GameObject:
577591
m_ObjectHideFlags: 0
@@ -1117,6 +1131,7 @@ GameObject:
11171131
- component: {fileID: 3594349661768254799}
11181132
- component: {fileID: 4774952041969802988}
11191133
- component: {fileID: 7309555813235861460}
1134+
- component: {fileID: 6837681858970599634}
11201135
m_Layer: 5
11211136
m_Name: Text_Play
11221137
m_TagString: Untagged
@@ -1240,6 +1255,19 @@ MonoBehaviour:
12401255
m_hasFontAssetChanged: 0
12411256
m_baseMaterial: {fileID: 0}
12421257
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
1258+
--- !u!114 &6837681858970599634
1259+
MonoBehaviour:
1260+
m_ObjectHideFlags: 0
1261+
m_CorrespondingSourceObject: {fileID: 0}
1262+
m_PrefabInstance: {fileID: 0}
1263+
m_PrefabAsset: {fileID: 0}
1264+
m_GameObject: {fileID: 5222434654072416771}
1265+
m_Enabled: 1
1266+
m_EditorHideFlags: 0
1267+
m_Script: {fileID: 11500000, guid: 836a40dddfacaeb4384366e730750713, type: 3}
1268+
m_Name:
1269+
m_EditorClassIdentifier:
1270+
localizationKey:
12431271
--- !u!1 &7820538167365247427
12441272
GameObject:
12451273
m_ObjectHideFlags: 0
@@ -1271,6 +1299,7 @@ RectTransform:
12711299
- {fileID: 5001744298333058997}
12721300
- {fileID: 2039853583507517311}
12731301
- {fileID: 8372138397902033123}
1302+
- {fileID: 5962648131348975462}
12741303
m_Father: {fileID: 6547191552835619457}
12751304
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
12761305
m_AnchorMin: {x: 0, y: 0}
@@ -1445,7 +1474,6 @@ RectTransform:
14451474
m_Children:
14461475
- {fileID: 1340421931193501842}
14471476
- {fileID: 7819726220318285085}
1448-
- {fileID: 5962648131348975462}
14491477
m_Father: {fileID: 0}
14501478
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
14511479
m_AnchorMin: {x: 0, y: 0}
@@ -1462,7 +1490,7 @@ Canvas:
14621490
m_GameObject: {fileID: 8664315041680610172}
14631491
m_Enabled: 1
14641492
serializedVersion: 3
1465-
m_RenderMode: 0
1493+
m_RenderMode: 1
14661494
m_Camera: {fileID: 0}
14671495
m_PlaneDistance: 100
14681496
m_PixelPerfect: 0
@@ -1540,13 +1568,13 @@ RectTransform:
15401568
m_PrefabAsset: {fileID: 0}
15411569
m_GameObject: {fileID: 8933064833224827719}
15421570
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
1543-
m_LocalPosition: {x: 0, y: 0, z: 90}
1571+
m_LocalPosition: {x: 0, y: 0, z: 0}
15441572
m_LocalScale: {x: 1, y: 1, z: 1}
15451573
m_ConstrainProportionsScale: 0
15461574
m_Children:
15471575
- {fileID: 297070466131320601}
15481576
- {fileID: 8278398173702700151}
1549-
m_Father: {fileID: 6547191552835619457}
1577+
m_Father: {fileID: 7819726220318285085}
15501578
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
15511579
m_AnchorMin: {x: 0, y: 0}
15521580
m_AnchorMax: {x: 1, y: 0.2114815}

0 commit comments

Comments
 (0)