using UnityEngine; using TMPro; public class TRANS : MonoBehaviour { public static string This(string txt) { TryThis(txt, out string text); return text; } // Vrai si la clé existe dans une des tables. Le texte sort inchangé sinon, // pour qu'un appelant puisse laisser l'étiquette telle quelle. public static bool TryThis(string key, out string text) { text = key; if (string.IsNullOrEmpty(key)) return false; bool isT = key.Length >= 2 && key[0] == 'T' && key[1] == '_'; string[] table = isT ? _T.TRANS_T : _T.TRANS; int ind = System.Array.IndexOf(table, key); if (ind < 0) return false; int slot = ind + _G.L; if (slot < 0 || slot >= table.Length) return false; text = Retext(table[slot]); return true; } // public static string CabinetSubCategory(string Category, string txt) // { // Category += _G.L;S // return Category switch // { // "BASE1" => _SC.BASE1[_SC.BASE1.IndexOf(txt)], // "BASE2" => _SC.BASE2[_SC.BASE1.IndexOf(txt)], // "BASE3" => _SC.BASE3[_SC.BASE1.IndexOf(txt)], // "WALL1" => _SC.WALL1[_SC.WALL1.IndexOf(txt)], // "WALL2" => _SC.WALL2[_SC.WALL1.IndexOf(txt)], // "WALL3" => _SC.WALL3[_SC.WALL1.IndexOf(txt)], // "TALL1" => _SC.TALL1[_SC.TALL1.IndexOf(txt)], // "TALL2" => _SC.TALL2[_SC.TALL1.IndexOf(txt)], // "TALL3" => _SC.TALL3[_SC.TALL1.IndexOf(txt)], // "CBASE1" => _SC.CBASE1[_SC.CBASE1.IndexOf(txt)], // "CBASE2" => _SC.CBASE2[_SC.CBASE1.IndexOf(txt)], // "CBASE3" => _SC.CBASE3[_SC.CBASE1.IndexOf(txt)], // "CWALL1" => _SC.CWALL1[_SC.CWALL1.IndexOf(txt)], // "CWALL2" => _SC.CWALL2[_SC.CWALL1.IndexOf(txt)], // "CWALL3" => _SC.CWALL3[_SC.CWALL1.IndexOf(txt)], // _ => "Oups", // }; // } // Traduit toutes les étiquettes marquées du tag "txtpro" : le nom de l'objet // est la clé. Une clé absente des tables laisse le texte en place. // // Le tag "txt" de l'ancienne version n'existe pas dans ce projet : le chercher // levait une exception. public static void go() { GameObject[] gospro = GameObject.FindGameObjectsWithTag("txtpro"); foreach (GameObject go in gospro) { if (!TryThis(go.name, out string texte)) continue; TMP_Text label = go.GetComponent(); if (label != null) label.text = texte; } } public static string color(string txt) { int ind = System.Array.IndexOf(_C.TRANS, txt); if (ind < 0) return txt; int slot = ind + _G.L; if (slot < 0 || slot >= _C.TRANS.Length) return txt; return _C.TRANS[slot]; } public static string Retext(string T ){ if(_G.Lexique.ContainsKey(T)){return _G.Lexique[T];} return T; } }