#if UNITY_EDITOR
using System.Collections.Generic;
using TMPro;
using UnityEditor;
using UnityEngine;
///
/// Adds LocalizedTMP to prefab static labels using a path→key map.
/// Menu: Crazy Fruit / Localization / Attach LocalizedTMP To Prefabs
///
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(assetPath);
if (root == null)
continue;
Transform target = root.transform.Find(entry.path);
if (target == null)
continue;
TMP_Text text = target.GetComponent();
if (text == null)
continue;
LocalizedTMP loc = target.GetComponent();
if (loc == null)
loc = target.gameObject.AddComponent();
SerializedObject so = new SerializedObject(loc);
so.FindProperty("key").stringValue = entry.key;
so.ApplyModifiedPropertiesWithoutUndo();
count++;
}
AssetDatabase.SaveAssets();
Debug.Log("[Locale] Attached LocalizedTMP components: " + count);
}
}
#endif