PrefabLocalizedTMPSetup.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #if UNITY_EDITOR
  2. using System.Collections.Generic;
  3. using TMPro;
  4. using UnityEditor;
  5. using UnityEngine;
  6. /// <summary>
  7. /// Adds LocalizedTMP to prefab static labels using a path→key map.
  8. /// Menu: Crazy Fruit / Localization / Attach LocalizedTMP To Prefabs
  9. /// </summary>
  10. static class PrefabLocalizedTMPSetup
  11. {
  12. static readonly (string prefab, string path, string key)[] Map =
  13. {
  14. ("01_lobby", "IMG_MainBoardFrame/IMG_NowServingBoard/TMP_NowServingTitle", "lobby.now_serving"),
  15. ("01_lobby", "IMG_BottomNavBG/IMG_ShopIcon/TMP_ShopLabel", "lobby.nav.shop"),
  16. ("02_game", "IMG_GameBoardFrame/IMG_FruitCounterBG/IMG_Title/TMP_Title", "game.still_no_stand"),
  17. ("02_game", "IMG_GameTip/TMP_GameTip", "game.tip.tap_drag"),
  18. ("02_game", "PowerUpsGroup/BTN_AddMoves/TMP_Name", "defs.item.moves.name"),
  19. ("02_game", "PowerUpsGroup/BTN_Hammer/TMP_Name", "defs.item.hammer.name"),
  20. ("02_game", "PowerUpsGroup/BTN_Key/TMP_Name", "defs.item.key.short"),
  21. ("02_game", "PowerUpsGroup/BTN_Shuffle/TMP_Name", "defs.item.shuffle.name"),
  22. ("11_setting", "IMG_BG/IMG_Title/TMP_Title", "settings.title"),
  23. };
  24. [MenuItem("Crazy Fruit/Localization/Attach LocalizedTMP To Prefabs")]
  25. static void Attach()
  26. {
  27. int count = 0;
  28. foreach (var entry in Map)
  29. {
  30. string assetPath = "Assets/CrazyFruitMaster/Resources/Prefab/" + entry.prefab + ".prefab";
  31. GameObject root = AssetDatabase.LoadAssetAtPath<GameObject>(assetPath);
  32. if (root == null)
  33. continue;
  34. Transform target = root.transform.Find(entry.path);
  35. if (target == null)
  36. continue;
  37. TMP_Text text = target.GetComponent<TMP_Text>();
  38. if (text == null)
  39. continue;
  40. LocalizedTMP loc = target.GetComponent<LocalizedTMP>();
  41. if (loc == null)
  42. loc = target.gameObject.AddComponent<LocalizedTMP>();
  43. SerializedObject so = new SerializedObject(loc);
  44. so.FindProperty("key").stringValue = entry.key;
  45. so.ApplyModifiedPropertiesWithoutUndo();
  46. count++;
  47. }
  48. AssetDatabase.SaveAssets();
  49. Debug.Log("[Locale] Attached LocalizedTMP components: " + count);
  50. }
  51. }
  52. #endif