| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #if UNITY_EDITOR
- using System.Collections.Generic;
- using TMPro;
- using UnityEditor;
- using UnityEngine;
- /// <summary>
- /// Adds LocalizedTMP to prefab static labels using a path→key map.
- /// Menu: Crazy Fruit / Localization / Attach LocalizedTMP To Prefabs
- /// </summary>
- static class PrefabLocalizedTMPSetup
- {
- static readonly (string prefab, string path, string key)[] Map =
- {
- ("01_lobby", "IMG_MainBoardFrame/IMG_NowServingBoard/TMP_NowServingTitle", "lobby.now_serving"),
- ("01_lobby", "IMG_BottomNavBG/IMG_ShopIcon/TMP_ShopLabel", "lobby.nav.shop"),
- ("02_game", "IMG_GameBoardFrame/IMG_FruitCounterBG/IMG_Title/TMP_Title", "game.still_no_stand"),
- ("02_game", "IMG_GameTip/TMP_GameTip", "game.tip.tap_drag"),
- ("02_game", "PowerUpsGroup/BTN_AddMoves/TMP_Name", "defs.item.moves.name"),
- ("02_game", "PowerUpsGroup/BTN_Hammer/TMP_Name", "defs.item.hammer.name"),
- ("02_game", "PowerUpsGroup/BTN_Key/TMP_Name", "defs.item.key.short"),
- ("02_game", "PowerUpsGroup/BTN_Shuffle/TMP_Name", "defs.item.shuffle.name"),
- ("11_setting", "IMG_BG/IMG_Title/TMP_Title", "settings.title"),
- };
- [MenuItem("Crazy Fruit/Localization/Attach LocalizedTMP To Prefabs")]
- static void Attach()
- {
- int count = 0;
- foreach (var entry in Map)
- {
- string assetPath = "Assets/CrazyFruitMaster/Resources/Prefab/" + entry.prefab + ".prefab";
- GameObject root = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
- if (root == null)
- continue;
- Transform target = root.transform.Find(entry.path);
- if (target == null)
- continue;
- TMP_Text text = target.GetComponent<TMP_Text>();
- if (text == null)
- continue;
- LocalizedTMP loc = target.GetComponent<LocalizedTMP>();
- if (loc == null)
- loc = target.gameObject.AddComponent<LocalizedTMP>();
- SerializedObject so = new SerializedObject(loc);
- so.FindProperty("key").stringValue = entry.key;
- so.ApplyModifiedPropertiesWithoutUndo();
- count++;
- }
- AssetDatabase.SaveAssets();
- Debug.Log("[Locale] Attached LocalizedTMP components: " + count);
- }
- }
- #endif
|