22using System ;
33using System . Collections . Generic ;
44using System . IO ;
5+ using Code . Localization . Code ;
56using Sirenix . OdinInspector ;
67using Sirenix . OdinInspector . Editor ;
78using 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
0 commit comments