TextAutoLanguage.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class TextAutoLanguage : MonoBehaviour
  7. {
  8. [SerializeField] int textID;
  9. [SerializeField] RectTransform layoutRebuildObject;
  10. // static LanguageDefault language = new LanguageDefault();
  11. static LanguageDefault language = new LanguageDefault();
  12. static HashSet<TextAutoLanguage> textAutoLanguages = new HashSet<TextAutoLanguage>();
  13. public string[] textFormatArgs = {};
  14. public static void Init()
  15. {
  16. int id = PlayerPrefs.GetInt("Language", 0);
  17. ChangeLanguage((LanguageEnum) id);
  18. }
  19. public static void ChangeLanguage(LanguageEnum languageEnum)
  20. {
  21. if (languageEnum == LanguageEnum.Chinese) {
  22. language = new LanguageDefault();
  23. } else if (languageEnum == LanguageEnum.English) {
  24. language = new LanguageEnglish();
  25. }
  26. PlayerPrefs.SetInt("Language", ((int)languageEnum));
  27. foreach (var textAutoLanguage in textAutoLanguages)
  28. {
  29. try {
  30. textAutoLanguage.ApplyText();
  31. } catch (Exception) {}
  32. }
  33. }
  34. public static LanguageEnum GetLanguage()
  35. {
  36. if (language is LanguageEnglish) {
  37. return LanguageEnum.English;
  38. }
  39. return LanguageEnum.Chinese;
  40. }
  41. void Start()
  42. {
  43. textAutoLanguages.Add(this);
  44. ApplyText();
  45. }
  46. void OnDestroy()
  47. {
  48. textAutoLanguages.Remove(this);
  49. }
  50. public void SetText(int textID)
  51. {
  52. this.textID = textID;
  53. string text = language.GetType().GetField("text" + textID).GetValue(language).ToString();
  54. if (textFormatArgs.Length > 0)
  55. {
  56. text = String.Format(text, textFormatArgs);
  57. }
  58. this.GetComponent<Text>().text = text;
  59. if (layoutRebuildObject)
  60. {
  61. LayoutRebuilder.ForceRebuildLayoutImmediate(layoutRebuildObject);
  62. }
  63. }
  64. public int GetTextID()
  65. {
  66. return this.textID;
  67. }
  68. void ApplyText()
  69. {
  70. SetText(textID);
  71. }
  72. }
  73. public enum LanguageEnum {
  74. Chinese, English
  75. }
  76. class LanguageDefault {
  77. public string text0 = "";
  78. public string text1 = "昵 称 :";
  79. public string text2 = "手 机 号 :";
  80. public string text3 = "性 别 :";
  81. public string text4 = "出生日期 :";
  82. public string text5 = "国 籍 :";
  83. public string text6 = "所在地区 :";
  84. public string text7 = "保存";
  85. public string text8 = "男";
  86. public string text9 = "女";
  87. public string text10 = "未填写";
  88. public string text11 = "昵称不能为空";
  89. public string text12 = "保存成功";
  90. public string text13 = "我的";
  91. public string text14 = "连接";
  92. public string text15 = "正在连接";
  93. public string text16 = "连接成功";
  94. public string text17 = "连接失败";
  95. public string text18 = "神弓";
  96. public string text19 = "神箭";
  97. public string text20 = "设置";
  98. public string text21 = "教程";
  99. public string text22 = "商城";
  100. public string text23 = "设备";
  101. public string text24 = "用 户 名 :";
  102. public string text25 = "密 码 :";
  103. public string text26 = "忘记密码";
  104. public string text27 = "注册";
  105. public string text28 = "用 户 名 :";
  106. public string text29 = "密 码 :";
  107. public string text30 = "确认密码 :";
  108. public string text31 = "昵 称 :";
  109. public string text32 = "性 别 :";
  110. public string text33 = "登录";
  111. public string text34 = "手 机 号 :";
  112. public string text35 = "验 证 码 :";
  113. public string text36 = "新 密 码 :";
  114. public string text37 = "确认密码 :";
  115. public string text38 = "获取";
  116. public string text39 = "用户登录";
  117. public string text40 = "手机登录";
  118. public string text41 = "请输入用户名";
  119. public string text42 = "请输入密码";
  120. public string text43 = "登录成功";
  121. public string text44 = "密码错误";
  122. public string text45 = "该用户尚未注册";
  123. public string text46 = "用户名长度至少6位";
  124. public string text47 = "密码长度至少6位";
  125. public string text48 = "两次输入的密码不一致";
  126. public string text49 = "请输入游戏昵称";
  127. public string text50 = "该用户无法重复注册";
  128. public string text51 = "注册成功";
  129. public string text61 = "请连接设备";
  130. public string text62 = "关闭";
  131. public string text63 = "商品";
  132. public string text64 = "背包";
  133. public string text65 = "已装备";
  134. public string text66 = "购买";
  135. public string text67 = "属性";
  136. public string text68 = "操作难度 : ";
  137. public string text69 = "设备教程";
  138. public string text70 = "游戏教程";
  139. public string text71 = "角色选择";
  140. public string text72 = "玩家1";
  141. public string text73 = "玩家2";
  142. public string text74 = "开始游戏";
  143. public string text87 = "本轮玩家";
  144. public string text88 = "继续";
  145. public string text89 = "主页";
  146. public string text90 = "分享";
  147. public string text91 = "再来";
  148. public string text92 = "友谊赛";
  149. public string text93 = "当前玩家";
  150. public string text94 = "距离选择";
  151. public string text95 = "得分:";
  152. public string text96 = "新手教程";
  153. public string text97 = "返回主页";
  154. public string text98 = "完成";
  155. public string text99 = "闯关";
  156. public string text100 = "限时";
  157. public string text101 = "排行榜";
  158. public string text102 = "游戏";
  159. public string text103 = "登录";
  160. public string text104 = "结束";
  161. public string text105 = "胜利";
  162. public string text106 = "失败";
  163. public string text107 = "已售罄";
  164. public string text108 = "使用";
  165. public string text109 = "使用中";
  166. public string text110 = "取消";
  167. public string text111 = "需要装备倍镜";
  168. public string text112 = "需要装备射程卡";
  169. public string text113 = "弓";
  170. public string text114 = "箭";
  171. public string text115 = "第 {0} 局";
  172. //设备页面
  173. public string text500 = "陀螺仪校准";
  174. public string text501 = "地磁计校准";
  175. public string text502 = "视角回正";
  176. public string text503 = "16G加速计";
  177. public string text504 = "64G加速计";
  178. //主页面
  179. public string text400 = "退出游戏";
  180. //设置页面
  181. public string text300 = "退出登录";
  182. public string text301 = "关于我们";
  183. public string text302 = "背景音乐";
  184. public string text303 = "音效";
  185. public string text304 = "语言";
  186. public string text305 = "简体中文";
  187. public string text306 = "十字准心";
  188. public string text307 = "开";
  189. public string text308 = "关";
  190. public string text309 = "射箭难度";
  191. public string text310 = "简单";
  192. public string text311 = "普通";
  193. public string text312 = "困难";
  194. //设备校准页面
  195. public string text76 = "视角归位";
  196. public string text77 = "上一步";
  197. public string text78 = "下一步";
  198. public string text79 = "返回";
  199. public string text80 = "视角回正";
  200. public string text81 = "实体弓指向正前方,然后点击视角回正。";
  201. public string text82 = "开始校准";
  202. public string text83 = "停止校准";
  203. public string text84 = "尽量尝试多角度旋转模块,直到XYZ三个象限中多点形成圆形为止。";
  204. public string text85 = "开始校准";
  205. public string text86 = "校准时需要将瞄准模块静止放在桌面上。";
  206. public string text116 = "重新校准";
  207. //游戏场景通用UI信息
  208. public string text200 = "引导";
  209. public string text201 = "开镜";
  210. public string text202 = "加速";
  211. public string text203 = "视角归位";
  212. public string text204 = "查看靶子";
  213. public string text205 = "关闭";
  214. // 游戏规则
  215. public string text1000 = "在固定的时间内尽量射更多的箭。";
  216. public string text1001 = "总环数逐渐增加,挑战自己的纪录。";
  217. public string text2000 = "两个人轮流射箭,使用奥运会的规则进行PK。";
  218. public string text2001 = "比赛最多为5局,每局3支箭,交替射箭。";
  219. public string text2002 = "获胜者获得积分2分,打平各1分,输者不得积分。";
  220. public string text2003 = "先得6分者胜利,如5局打完是平局,则加赛一箭定胜负。";
  221. //道具名称
  222. public string text101000 = "{0}倍镜";
  223. public string text101001 = "{0}倍射程卡";
  224. // 道具介绍
  225. public string text111000 = "射箭瞄准时,视距放大{0}倍。";
  226. public string text111001 = "射箭时,射程增加{0}倍。";
  227. //设备名称
  228. public string text201000 = "18磅反曲弓";
  229. public string text201001 = "25磅反曲弓";
  230. public string text201002 = "碳纤维箭";
  231. // 设备介绍
  232. public string text211000 = "奥运比赛专用比赛弓";
  233. public string text211001 = "奥运比赛专用比赛弓";
  234. public string text211002 = "奥运比赛专用比赛箭";
  235. }
  236. class LanguageEnglish : LanguageDefault {
  237. public new string text1 = "Name :";
  238. public new string text2 = "Phone :";
  239. public new string text3 = "Gender :";
  240. public new string text4 = "Birthday :";
  241. public new string text5 = "Country :";
  242. public new string text6 = "Region :";
  243. public new string text7 = "Save";
  244. public new string text8 = "Male";
  245. public new string text9 = "Female";
  246. public new string text10 = "Not Filled In";
  247. public new string text11 = "Name Cannot Be Empty";
  248. public new string text12 = "Saved Successfully";
  249. public new string text13 = "Me";
  250. public new string text14 = "Connect";
  251. public new string text15 = "Trying";
  252. public new string text16 = "Activated";
  253. public new string text17 = "Failed";
  254. public new string text18 = "Bow";
  255. public new string text19 = "Arrow";
  256. public new string text20 = "SetUp";
  257. public new string text21 = "Course";
  258. public new string text22 = "Shop";
  259. public new string text23 = "Device";
  260. public new string text24 = "Username:";
  261. public new string text25 = "Password:";
  262. public new string text26 = "Forget Password";
  263. public new string text27 = "Register";
  264. public new string text28 = "Username :";
  265. public new string text29 = "Password :";
  266. public new string text30 = "Confirm Password :";
  267. public new string text31 = "Nickname :";
  268. public new string text32 = "Gender :";
  269. public new string text33 = "Login";
  270. public new string text34 = "Phone :";
  271. public new string text35 = "Code :";
  272. public new string text36 = "Password :";
  273. public new string text37 = "Confirm Password :";
  274. public new string text38 = "Get";
  275. public new string text39 = "User Login";
  276. public new string text40 = "Phone Login";
  277. public new string text41 = "Please Enter Username";
  278. public new string text42 = "Please Enter Password";
  279. public new string text43 = "Login Successful";
  280. public new string text44 = "Wrong Password";
  281. public new string text45 = "User Not Register";
  282. public new string text46 = "Username At Least 6 Digits";
  283. public new string text47 = "Password At Least 6 Digits";
  284. public new string text48 = "Two Passwords Are Inconsistent";
  285. public new string text49 = "Please Enter Nickname";
  286. public new string text50 = "Unable To Re Register";
  287. public new string text51 = "Register Successful";
  288. public new string text61 = "Please Connect Device";
  289. public new string text62 = "Close";
  290. public new string text63 = "Products";
  291. public new string text64 = "Bag";
  292. public new string text65 = "Equipped";
  293. public new string text66 = "Buy";
  294. public new string text67 = "Property";
  295. public new string text68 = "Difficulty : ";
  296. public new string text69 = "Device Course";
  297. public new string text70 = "Game Course";
  298. public new string text71 = "Role Select";
  299. public new string text72 = "Player1";
  300. public new string text73 = "Player2";
  301. public new string text74 = "Start";
  302. public new string text87 = "Current Round Player";
  303. public new string text88 = "Continue";
  304. public new string text89 = "Home";
  305. public new string text90 = "Share";
  306. public new string text91 = "Again";
  307. public new string text92 = "PVP";
  308. public new string text93 = "Player";
  309. public new string text94 = "Distance Select";
  310. public new string text95 = "Score:";
  311. public new string text96 = "New Player Guide";
  312. public new string text97 = "Back";
  313. public new string text98 = "Complete";
  314. public new string text99 = "Pass";
  315. public new string text100 = "Limit";
  316. public new string text101 = "Rank";
  317. public new string text102 = "Game";
  318. public new string text103 = "Login";
  319. public new string text104 = "Over";
  320. public new string text105 = "Win";
  321. public new string text106 = "Lose";
  322. public new string text107 = "SoldOut";
  323. public new string text108 = "Use";
  324. public new string text109 = "Inuse";
  325. public new string text110 = "Cancel";
  326. public new string text111 = "Multiple Mirrors Is Required";
  327. public new string text112 = "Shoot Card Is Required";
  328. public new string text113 = "Bow";
  329. public new string text114 = "Arrow";
  330. public new string text115 = "Round {0}";
  331. //设备页面
  332. public new string text500 = "GyrCalibrate";
  333. public new string text501 = "MagCalibrate";
  334. public new string text502 = "Identity";
  335. public new string text503 = "16G Acc";
  336. public new string text504 = "64G Acc";
  337. //主页面
  338. public new string text400 = "Quit Game";
  339. //设置页面
  340. public new string text300 = "Quit Login";
  341. public new string text301 = "About Us";
  342. public new string text302 = "BGM";
  343. public new string text303 = "Sound";
  344. public new string text304 = "Language";
  345. public new string text305 = "English";
  346. public new string text306 = "CrossHair";
  347. public new string text307 = "ON";
  348. public new string text308 = "OFF";
  349. public new string text309 = "ShootLevel";
  350. public new string text310 = "Easy";
  351. public new string text311 = "Normal";
  352. public new string text312 = "Hard";
  353. //设备校准页面
  354. public new string text76 = "Identity";
  355. public new string text77 = "Back";
  356. public new string text78 = "Next";
  357. public new string text79 = "Complete";
  358. public new string text80 = "Identity";
  359. public new string text81 = "Point the solid bow to the front, and then click \nthe angle of view to return to the front.";
  360. public new string text82 = "Calibrate";
  361. public new string text83 = "Stop";
  362. public new string text84 = "Try to rotate the module at multiple angles until \nmultiple points in the three quadrants of XYZ form a circle.";
  363. public new string text85 = "Calibrate";
  364. public new string text86 = "During calibration, the aiming module needs to be placed on the desktop.";
  365. public new string text116 = "Redo";
  366. //游戏场景通用UI信息
  367. public new string text200 = "Guide";
  368. public new string text201 = "Scope";
  369. public new string text202 = "Acc";
  370. public new string text203 = "Identity";
  371. public new string text204 = "View Target";
  372. public new string text205 = "Close";
  373. // 游戏规则
  374. public new string text1000 = "Shoot as many arrows as you can at a fixed time.";
  375. public new string text1001 = "The total number of rings gradually increased, \nchallenging their own records.";
  376. public new string text2000 = "Two people arched in turn, using the rules of the Olympic Games PK.";
  377. public new string text2001 = "The maximum number of games is 5, 3 arrows in each game, \nshooting arrows alternately.";
  378. public new string text2002 = "The winner will get 2 points and 1 draw each. \nThe loser will not get points.";
  379. 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.";
  380. //道具名称
  381. public new string text101000 = "{0}X Mirrors";
  382. public new string text101001 = "{0}X Shoot";
  383. // 道具介绍
  384. public new string text111000 = "When shooting, the sight distance is enlarged by {0} times.";
  385. public new string text111001 = "In archery, the range increases by {0} times.";
  386. //设备名称
  387. public new string text201000 = "18 Pound Bow";
  388. public new string text201001 = "25 Pound Bow";
  389. public new string text201002 = "Carbon Giber Arrow";
  390. // 设备介绍
  391. public new string text211000 = "Special bow for Olympic Games.";
  392. public new string text211001 = "Special bow for Olympic Games.";
  393. public new string text211002 = "Special competition arrow for Olympic Games.";
  394. }