TextAutoLanguage.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. /* 自定义多语言组件 */
  7. public class TextAutoLanguage : MonoBehaviour
  8. {
  9. [SerializeField] int textID;
  10. [SerializeField] RectTransform layoutRebuildObject;
  11. static LanguageEnum currentLanguageEnum = LanguageEnum.Chinese;
  12. static LanguageDefault language = null;
  13. static HashSet<TextAutoLanguage> textAutoLanguages = new HashSet<TextAutoLanguage>();
  14. public string[] textFormatArgs = {};
  15. [SerializeField] LanguageFontSize[] languageFontSizes = {};
  16. private static bool inited = false;
  17. public static void Init()
  18. {
  19. if (inited) return;
  20. inited = true;
  21. int id = PlayerPrefs.GetInt("Language", 0);
  22. ChangeLanguage((LanguageEnum) id);
  23. }
  24. public static void ChangeLanguage(LanguageEnum languageEnum)
  25. {
  26. currentLanguageEnum = languageEnum;
  27. if (languageEnum == LanguageEnum.English) {
  28. language = new LanguageEnglish();
  29. } else {
  30. language = new LanguageDefault();
  31. }
  32. PlayerPrefs.SetInt("Language", ((int)languageEnum));
  33. foreach (var textAutoLanguage in textAutoLanguages)
  34. {
  35. try {
  36. textAutoLanguage.ApplyText();
  37. } catch (Exception e) { Debug.LogError(e.Message); }
  38. }
  39. }
  40. public static LanguageEnum GetLanguage()
  41. {
  42. Init();
  43. if (language is LanguageEnglish) {
  44. return LanguageEnum.English;
  45. }
  46. return LanguageEnum.Chinese;
  47. }
  48. void Awake()
  49. {
  50. Init();
  51. }
  52. void Start()
  53. {
  54. textAutoLanguages.Add(this);
  55. ApplyText();
  56. }
  57. void OnDestroy()
  58. {
  59. textAutoLanguages.Remove(this);
  60. }
  61. /**记录组件的默认字体大小 */
  62. private int defaultFontSize = -1;
  63. public void SetText(int textID)
  64. {
  65. this.textID = textID;
  66. string text = language.GetType().GetField("text" + textID).GetValue(language).ToString();
  67. if (textFormatArgs.Length > 0)
  68. {
  69. text = String.Format(text, textFormatArgs);
  70. }
  71. Text textComp = GetComponent<Text>();
  72. textComp.text = text;
  73. //如果有指定当前语言的字体大小,就更新字体大小,否则恢复默认字体大小
  74. if (defaultFontSize == -1) { //首次记录组件的默认字体大小
  75. defaultFontSize = textComp.fontSize;
  76. } else {
  77. textComp.fontSize = defaultFontSize;
  78. }
  79. if (languageFontSizes.Length > 0) {
  80. foreach (var languageFontSize in languageFontSizes)
  81. {
  82. if (languageFontSize.language == currentLanguageEnum) {
  83. textComp.fontSize = languageFontSize.fontSize;
  84. }
  85. }
  86. }
  87. //重置指定节点的布局
  88. if (layoutRebuildObject)
  89. {
  90. LayoutRebuilder.ForceRebuildLayoutImmediate(layoutRebuildObject);
  91. }
  92. }
  93. public int GetTextID()
  94. {
  95. return this.textID;
  96. }
  97. void ApplyText()
  98. {
  99. SetText(textID);
  100. }
  101. }
  102. class LanguageDefault {
  103. public string text0 = "";
  104. public string text1 = "昵 称 :";
  105. public string text2 = "手 机 号 :";
  106. public string text3 = "性 别 :";
  107. public string text4 = "出生日期 :";
  108. public string text5 = "国 籍 :";
  109. public string text6 = "所在地区 :";
  110. public string text7 = "保存";
  111. public string text8 = "男";
  112. public string text9 = "女";
  113. public string text10 = "未填写";
  114. public string text11 = "昵称不能为空";
  115. public string text12 = "保存成功";
  116. public string text13 = "我的";
  117. public string text14 = " 连接 ";
  118. public string text15 = "正在连接";
  119. public string text16 = "连接成功";
  120. public string text17 = "断开连接";
  121. public string text18 = "神弓";
  122. public string text19 = "神箭";
  123. public string text20 = "设置";
  124. public string text21 = "教程";
  125. public string text22 = "商城";
  126. public string text23 = "设备";
  127. public string text24 = "账 号 :";
  128. public string text25 = "密 码 :";
  129. public string text26 = "找回密码";
  130. public string text27 = "新用户注册";
  131. public string text28 = "账 号 :";
  132. public string text29 = "密 码 :";
  133. public string text30 = "确认密码 :";
  134. public string text31 = "昵 称 :";
  135. public string text32 = "性 别 :";
  136. public string text33 = "登录";
  137. public string text34 = "手 机 号 :";
  138. public string text35 = "验 证 码 :";
  139. public string text36 = "新 密 码 :";
  140. public string text37 = "确认密码 :";
  141. public string text38 = "获取";
  142. public string text39 = "账 号";
  143. public string text40 = "手机号";
  144. public string text41 = "请输入账号";
  145. public string text42 = "请输入密码";
  146. public string text43 = "登录成功";
  147. public string text44 = "密码错误";
  148. public string text45 = "该用户尚未注册";
  149. public string text46 = "账号长度至少6位";
  150. public string text47 = "密码长度至少6位";
  151. public string text48 = "两次输入的密码不一致";
  152. public string text49 = "请输入游戏昵称";
  153. public string text50 = "该用户无法重复注册";
  154. public string text51 = "注册成功";
  155. public string text61 = "请连接设备";
  156. public string text62 = "关闭";
  157. public string text63 = "商品";
  158. public string text64 = "背包";
  159. public string text65 = "已装备";
  160. public string text66 = "购买";
  161. public string text67 = "属性";
  162. public string text68 = "操作难度 : ";
  163. public string text69 = "设备教程";
  164. public string text70 = "游戏教程";
  165. public string text71 = "角色选择";
  166. public string text72 = "玩家1";
  167. public string text73 = "玩家2";
  168. public string text74 = "开始游戏";
  169. public string text87 = "本轮玩家";
  170. public string text88 = "继续";
  171. public string text89 = "主页";
  172. public string text90 = "分享";
  173. public string text91 = "再来";
  174. public string text92 = "友谊赛";
  175. public string text93 = "当前玩家";
  176. public string text94 = "选择距离";
  177. public string text95 = "得分:";
  178. public string text96 = "新手教程";
  179. public string text97 = "返回主页";
  180. public string text98 = "完成";
  181. public string text99 = "闯关";
  182. public string text100 = "限时";
  183. public string text101 = "排行榜";
  184. public string text102 = "游戏";
  185. public string text103 = "绑定";
  186. public string text104 = "结束";
  187. public string text105 = "胜利";
  188. public string text106 = "失败";
  189. public string text107 = "已售罄";
  190. public string text108 = "使用";
  191. public string text109 = "使用中";
  192. public string text110 = "取消";
  193. public string text111 = "需要装备倍镜";
  194. public string text112 = "需要装备射速卡";
  195. public string text113 = "弓";
  196. public string text114 = "箭";
  197. public string text115 = "第 {0} 局";
  198. public string text117 = "长度{0}~{1}位,限英文和数字";
  199. public string text118 = "靶子已超出当前射程,请加大拉距或去商城装备射速卡!";
  200. public string text119 = "长度{0}~{1}位,可使用中文";
  201. //设备页面
  202. public string text500 = "陀螺仪初始化";
  203. public string text501 = "地磁计初始化";
  204. public string text502 = "视角回正";
  205. public string text503 = "16G加速计";
  206. public string text504 = "64G加速计";
  207. //主页面
  208. public string text122 = "排行榜";
  209. public string text123 = "好友";
  210. public string text124 = "开始游戏";
  211. public string text125 = "联机游戏";
  212. //我的
  213. public string text126 = "编 号 :";
  214. //开始游戏
  215. public string text133 = "开始游戏";
  216. public string text127 = "闯关游戏";
  217. public string text128 = "限时游戏";
  218. public string text129 = "PK游戏";
  219. //PK模式选择页面
  220. public string text132 = "PK模式";
  221. public string text130 = "静止靶PK";
  222. public string text131 = "闯关PK";
  223. public string text401 = "选择关卡";
  224. //关卡选择
  225. public string text134 = "游戏模式";
  226. public string text135 = "野兔关卡";
  227. public string text136 = "野鸡关卡";
  228. public string text137 = "野狼关卡";
  229. //设置页面
  230. public string text302 = "背景音乐";
  231. public string text303 = "音效";
  232. public string text304 = "语言";
  233. public string text305 = "简体中文";
  234. public string text306 = "十字准心";
  235. public string text307 = "开";
  236. public string text308 = "关";
  237. public string text309 = "射箭难度";
  238. public string text310 = "简单";
  239. public string text311 = "普通";
  240. public string text312 = "困难";
  241. public string text313 = "实际箭重";
  242. public string text314 = "{0}克";
  243. //SetUpView1
  244. public string text315 = "游戏设置";
  245. public string text318 = "新手引导";
  246. public string text301 = "关于我们";
  247. public string text316 = "用户协议";
  248. public string text317 = "隐私政策";
  249. public string text300 = "退出登录";
  250. public string text400 = "退出游戏";
  251. //设备校准页面
  252. public string text76 = "视角归位";
  253. public string text77 = "上一步";
  254. public string text78 = "下一步";
  255. public string text79 = "完成";
  256. public string text80 = "视角回正";
  257. public string text81 = "实体弓指向正前方,然后点击视角回正。";
  258. public string text82 = "开始初始化";
  259. public string text83 = "停止初始化";
  260. public string text84 = "尽量尝试多角度旋转模块,直到XYZ三个象限中多点形成圆形为止。";
  261. public string text85 = "开始初始化";
  262. public string text86 = "校准时需要将瞄准模块静止放在桌面上。";
  263. public string text116 = "重新初始化";
  264. public string text120 = "校准效果不理想,请重新校准!";
  265. public string text121 = "取消初始化";
  266. //游戏场景通用UI信息
  267. public string text200 = "引导";
  268. public string text201 = "开镜";
  269. public string text202 = "加速";
  270. public string text203 = "视角归位";
  271. public string text204 = "查看靶子";
  272. public string text205 = "关闭";
  273. // 游戏规则
  274. public string text1000 = "在固定的时间内尽量射更多的箭。";
  275. public string text1001 = "总环数逐渐增加,挑战自己的纪录。";
  276. public string text2000 = "两个人轮流射箭,使用奥运会的规则进行PK。";
  277. public string text2001 = "比赛最多为5局,每局3支箭,交替射箭。";
  278. public string text2002 = "获胜者获得积分2分,打平各1分,输者不得积分。";
  279. public string text2003 = "先得6分者胜利,如5局打完是平局,则加赛一箭定胜负。";
  280. //道具名称
  281. public string text101000 = "{0}倍镜";
  282. public string text101001 = "{0}倍射速卡";
  283. // 道具介绍
  284. public string text111000 = "射箭瞄准时,视距放大{0}倍。";
  285. public string text111001 = "射箭时,射速增加{0}倍。";
  286. //设备名称
  287. public string text200000 = "反曲弓";
  288. public string text201000 = "18磅反曲弓";
  289. public string text201001 = "25磅反曲弓";
  290. public string text201002 = "碳纤维箭";
  291. // 设备介绍
  292. public string text211000 = "奥运比赛专用比赛弓";
  293. public string text211001 = "奥运比赛专用比赛弓";
  294. public string text211002 = "奥运比赛专用比赛箭";
  295. //审核时用到的临时文字-设置页面
  296. public string text1234560 = "基础设置";
  297. public string text1234561 = "退出应用";
  298. public string text1234562 = "开始";
  299. public string text1234563 = "联机";
  300. }
  301. class LanguageEnglish : LanguageDefault {
  302. public new string text1 = "Name :";
  303. public new string text2 = "Phone :";
  304. public new string text3 = "Gender :";
  305. public new string text4 = "Birthday :";
  306. public new string text5 = "Country :";
  307. public new string text6 = "Region :";
  308. public new string text7 = "Save";
  309. public new string text8 = "Male";
  310. public new string text9 = "Female";
  311. public new string text10 = "Not Filled In";
  312. public new string text11 = "Name Cannot Be Empty";
  313. public new string text12 = "Saved Successfully";
  314. public new string text13 = "My";
  315. public new string text14 = "Connect";
  316. public new string text15 = "Connecting";
  317. public new string text16 = "Connected";
  318. public new string text17 = " Break ";
  319. public new string text18 = "Bow";
  320. public new string text19 = "Arrow";
  321. public new string text20 = "SetUp";
  322. public new string text21 = "Course";
  323. public new string text22 = "Shop";
  324. public new string text23 = "Device";
  325. public new string text24 = "Account:";
  326. public new string text25 = "Password:";
  327. public new string text26 = "Retrieve Password";
  328. public new string text27 = "New User Register";
  329. public new string text28 = "Account :";
  330. public new string text29 = "Password :";
  331. public new string text30 = "Confirm Password :";
  332. public new string text31 = "Nickname :";
  333. public new string text32 = "Gender :";
  334. public new string text33 = "Login";
  335. public new string text34 = "Phone :";
  336. public new string text35 = "Code :";
  337. public new string text36 = "Password :";
  338. public new string text37 = "Confirm Password :";
  339. public new string text38 = "Get";
  340. public new string text39 = "Account";
  341. public new string text40 = "Phone Number";
  342. public new string text41 = "Please Enter Account";
  343. public new string text42 = "Please Enter Password";
  344. public new string text43 = "Login Successful";
  345. public new string text44 = "Wrong Password";
  346. public new string text45 = "User Not Register";
  347. public new string text46 = "Account At Least 6 Digits";
  348. public new string text47 = "Password At Least 6 Digits";
  349. public new string text48 = "Two Passwords Are Inconsistent";
  350. public new string text49 = "Please Enter Nickname";
  351. public new string text50 = "Unable To Re Register";
  352. public new string text51 = "Register Successful";
  353. public new string text61 = "Please Connect Device";
  354. public new string text62 = "Close";
  355. public new string text63 = "Products";
  356. public new string text64 = "Bag";
  357. public new string text65 = "Equipped";
  358. public new string text66 = "Buy";
  359. public new string text67 = "Property";
  360. public new string text68 = "Difficulty : ";
  361. public new string text69 = "Device Course";
  362. public new string text70 = "Game Course";
  363. public new string text71 = "Select PFP";
  364. public new string text72 = "Player1";
  365. public new string text73 = "Player2";
  366. public new string text74 = "Start";
  367. public new string text87 = "Current Round Player";
  368. public new string text88 = "Continue";
  369. public new string text89 = "Home";
  370. public new string text90 = "Share";
  371. public new string text91 = "Again";
  372. public new string text92 = "PvP";
  373. public new string text93 = "Player";
  374. public new string text94 = "Select Range";
  375. public new string text95 = "Score:";
  376. public new string text96 = "New Player Guide";
  377. public new string text97 = "Back";
  378. public new string text98 = "Complete";
  379. public new string text99 = "Challenge";
  380. public new string text100 = "Limit";
  381. public new string text101 = "Rank";
  382. public new string text102 = "Game";
  383. public new string text103 = "Bind";
  384. public new string text104 = "Over";
  385. public new string text105 = "Win";
  386. public new string text106 = "Lose";
  387. public new string text107 = "SoldOut";
  388. public new string text108 = "Use";
  389. public new string text109 = "Inuse";
  390. public new string text110 = "Cancel";
  391. public new string text111 = "Multiple Mirrors Is Required";
  392. public new string text112 = "Shoot Card Is Required";
  393. public new string text113 = "Bow";
  394. public new string text114 = "Arrow";
  395. public new string text115 = "Round {0}";
  396. public new string text117 = "Limit {0}~{1} Bit, English And Figures";
  397. public new string text118 = "The target has exceeded the current range, please increase the pull distance or go to the shop to equip the shoot card!";
  398. public new string text119 = "Limit {0}~{1} Bit, Can Use Chinese";
  399. //设备页面
  400. public new string text500 = "Gyr Init";
  401. public new string text501 = "Mag Init";
  402. public new string text502 = "ResetView";
  403. public new string text503 = "16G Acc";
  404. public new string text504 = "64G Acc";
  405. //主页面
  406. public new string text122 = "Rank";
  407. public new string text123 = "Friend";
  408. public new string text124 = "Start";
  409. public new string text125 = "Online";
  410. //我的
  411. public new string text126 = "ID :";
  412. //开始游戏
  413. public new string text133 = "Stand Alone";
  414. public new string text127 = "Hunting";
  415. public new string text128 = "Target";
  416. public new string text129 = "1 v 1";
  417. //PK模式选择页面
  418. public new string text132 = "Dart Game";
  419. public new string text130 = "TARGET";
  420. public new string text131 = "HUNTING";
  421. public new string text401 = "Select Level";
  422. //关卡选择
  423. public new string text134 = "Hunting";
  424. public new string text135 = "Hare";
  425. public new string text136 = "Pheasant";
  426. public new string text137 = "Wild Wolf";
  427. //设置页面
  428. public new string text302 = "BGM";
  429. public new string text303 = "Sound";
  430. public new string text304 = "Language";
  431. public new string text305 = "English";
  432. public new string text306 = "CrossHair";
  433. public new string text307 = "ON";
  434. public new string text308 = "OFF";
  435. public new string text309 = "ShootLevel";
  436. public new string text310 = "Easy";
  437. public new string text311 = "Normal";
  438. public new string text312 = "Hard";
  439. public new string text313 = "ArrowWeight";
  440. public new string text314 = "{0}Gram";
  441. //SetUpView1
  442. public new string text315 = "Game Settings";
  443. public new string text318 = "Novice Guidance";
  444. public new string text301 = "About Us";
  445. public new string text316 = "User Agreement";
  446. public new string text317 = "Privacy Policy";
  447. public new string text300 = "Quit Login";
  448. public new string text400 = "Quit Game";
  449. //设备校准页面
  450. public new string text76 = "ResetView";
  451. public new string text77 = "Back";
  452. public new string text78 = "Next";
  453. public new string text79 = "Complete";
  454. public new string text80 = "ResetView";
  455. public new string text81 = "Point the solid bow to the front, and then click \nthe angle of view to return to the front.";
  456. public new string text82 = "Calibrate";
  457. public new string text83 = "Stop";
  458. public new string text84 = "Try to rotate the module at multiple angles until \nmultiple points in the three quadrants of XYZ form a circle.";
  459. public new string text85 = "Calibrate";
  460. public new string text86 = "During calibration, the aiming module needs to be placed on the desktop.";
  461. public new string text116 = "Redo";
  462. public new string text120 = "The calibration effect is not ideal, please recalibrate!";
  463. public new string text121 = "Cancel";
  464. //游戏场景通用UI信息
  465. public new string text200 = "Tips";
  466. public new string text201 = "Scope";
  467. public new string text202 = "Acc";
  468. public new string text203 = "Aim Reset";
  469. public new string text204 = "Target";
  470. public new string text205 = "Close";
  471. // 游戏规则
  472. public new string text1000 = "Shoot as many arrows as you can at a fixed time.";
  473. public new string text1001 = "The total number of rings gradually increased, \nchallenging their own records.";
  474. public new string text2000 = "Two people arched in turn, using the rules of the Olympic Games PK.";
  475. public new string text2001 = "The maximum number of games is 5, 3 arrows in each game, \nshooting arrows alternately.";
  476. public new string text2002 = "The winner will get 2 points and 1 draw each. \nThe loser will not get points.";
  477. public new string text2003 = "If the first 6 points win, \nif it is a draw at the end of the 5 innings, \nthe game will be decided by one arrow.";
  478. //道具名称
  479. public new string text101000 = "{0}X Mirrors";
  480. public new string text101001 = "{0}X Shoot";
  481. // 道具介绍
  482. public new string text111000 = "When shooting, the sight distance is enlarged by {0} times.";
  483. public new string text111001 = "In archery, the speed increases by {0} times.";
  484. //设备名称
  485. public new string text200000 = "Recurve Bow";
  486. public new string text201000 = "18 Pound Bow";
  487. public new string text201001 = "25 Pound Bow";
  488. public new string text201002 = "Carbon Giber Arrow";
  489. // 设备介绍
  490. public new string text211000 = "Special bow for Olympic Games.";
  491. public new string text211001 = "Special bow for Olympic Games.";
  492. public new string text211002 = "Special competition arrow for Olympic Games.";
  493. //审核时用到的临时文字-设置页面
  494. public new string text1234560 = "Base Settings";
  495. public new string text1234561 = "Quit App";
  496. public new string text1234562 = "Start";
  497. public new string text1234563 = "Online";
  498. }