using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class TextAutoLanguage : MonoBehaviour { [SerializeField] int textID; [SerializeField] RectTransform layoutRebuildObject; // static LanguageDefault language = new LanguageDefault(); static LanguageDefault language = new LanguageDefault(); static HashSet textAutoLanguages = new HashSet(); public string[] textFormatArgs = {}; public static void Init() { int id = PlayerPrefs.GetInt("Language", 0); ChangeLanguage((LanguageEnum) id); } public static void ChangeLanguage(LanguageEnum languageEnum) { if (languageEnum == LanguageEnum.Chinese) { language = new LanguageDefault(); } else if (languageEnum == LanguageEnum.English) { language = new LanguageEnglish(); } PlayerPrefs.SetInt("Language", ((int)languageEnum)); foreach (var textAutoLanguage in textAutoLanguages) { try { textAutoLanguage.ApplyText(); } catch (Exception) {} } } public static LanguageEnum GetLanguage() { if (language is LanguageEnglish) { return LanguageEnum.English; } return LanguageEnum.Chinese; } void Start() { textAutoLanguages.Add(this); ApplyText(); } void OnDestroy() { textAutoLanguages.Remove(this); } public void SetText(int textID) { this.textID = textID; string text = language.GetType().GetField("text" + textID).GetValue(language).ToString(); if (textFormatArgs.Length > 0) { text = String.Format(text, textFormatArgs); } this.GetComponent().text = text; if (layoutRebuildObject) { LayoutRebuilder.ForceRebuildLayoutImmediate(layoutRebuildObject); } } public int GetTextID() { return this.textID; } void ApplyText() { SetText(textID); } } public enum LanguageEnum { Chinese, English } class LanguageDefault { public string text0 = ""; public string text1 = "昵 称 :"; public string text2 = "手 机 号 :"; public string text3 = "性 别 :"; public string text4 = "出生日期 :"; public string text5 = "国 籍 :"; public string text6 = "所在地区 :"; public string text7 = "保存"; public string text8 = "男"; public string text9 = "女"; public string text10 = "未填写"; public string text11 = "昵称不能为空"; public string text12 = "保存成功"; public string text13 = "我的"; public string text14 = "连接"; public string text15 = "正在连接"; public string text16 = "连接成功"; public string text17 = "连接失败"; public string text18 = "神弓"; public string text19 = "神箭"; public string text20 = "设置"; public string text21 = "教程"; public string text22 = "商城"; public string text23 = "设备"; public string text24 = "用 户 名 :"; public string text25 = "密 码 :"; public string text26 = "忘记密码"; public string text27 = "注册"; public string text28 = "用 户 名 :"; public string text29 = "密 码 :"; public string text30 = "确认密码 :"; public string text31 = "昵 称 :"; public string text32 = "性 别 :"; public string text33 = "登录"; public string text34 = "手 机 号 :"; public string text35 = "验 证 码 :"; public string text36 = "新 密 码 :"; public string text37 = "确认密码 :"; public string text38 = "获取"; public string text39 = "用户登录"; public string text40 = "手机登录"; public string text41 = "请输入用户名"; public string text42 = "请输入密码"; public string text43 = "登录成功"; public string text44 = "密码错误"; public string text45 = "该用户尚未注册"; public string text46 = "用户名长度至少6位"; public string text47 = "密码长度至少6位"; public string text48 = "两次输入的密码不一致"; public string text49 = "请输入游戏昵称"; public string text50 = "该用户无法重复注册"; public string text51 = "注册成功"; public string text61 = "请连接设备"; public string text62 = "关闭"; public string text63 = "商品"; public string text64 = "背包"; public string text65 = "已装备"; public string text66 = "购买"; public string text67 = "属性"; public string text68 = "操作难度 : "; public string text69 = "设备教程"; public string text70 = "游戏教程"; public string text71 = "角色选择"; public string text72 = "玩家1"; public string text73 = "玩家2"; public string text74 = "开始游戏"; public string text87 = "本轮玩家"; public string text88 = "继续"; public string text89 = "主页"; public string text90 = "分享"; public string text91 = "再来"; public string text92 = "友谊赛"; public string text93 = "当前玩家"; public string text94 = "距离选择"; public string text95 = "得分:"; public string text96 = "新手教程"; public string text97 = "返回主页"; public string text98 = "完成"; public string text99 = "闯关"; public string text100 = "限时"; public string text101 = "排行榜"; public string text102 = "游戏"; public string text103 = "登录"; public string text104 = "结束"; public string text105 = "胜利"; public string text106 = "失败"; public string text107 = "已售罄"; public string text108 = "使用"; public string text109 = "使用中"; public string text110 = "取消"; public string text111 = "需要装备倍镜"; public string text112 = "需要装备射程卡"; public string text113 = "弓"; public string text114 = "箭"; public string text115 = "第 {0} 局"; //设备页面 public string text500 = "陀螺仪校准"; public string text501 = "地磁计校准"; public string text502 = "视角回正"; public string text503 = "16G加速计"; public string text504 = "64G加速计"; //主页面 public string text400 = "退出游戏"; //设置页面 public string text300 = "退出登录"; public string text301 = "关于我们"; public string text302 = "背景音乐"; public string text303 = "音效"; public string text304 = "语言"; public string text305 = "简体中文"; public string text306 = "十字准心"; public string text307 = "开"; public string text308 = "关"; public string text309 = "射箭难度"; public string text310 = "简单"; public string text311 = "普通"; public string text312 = "困难"; //设备校准页面 public string text76 = "视角归位"; public string text77 = "上一步"; public string text78 = "下一步"; public string text79 = "返回"; public string text80 = "视角回正"; public string text81 = "实体弓指向正前方,然后点击视角回正。"; public string text82 = "开始校准"; public string text83 = "停止校准"; public string text84 = "尽量尝试多角度旋转模块,直到XYZ三个象限中多点形成圆形为止。"; public string text85 = "开始校准"; public string text86 = "校准时需要将瞄准模块静止放在桌面上。"; public string text116 = "重新校准"; //游戏场景通用UI信息 public string text200 = "引导"; public string text201 = "开镜"; public string text202 = "加速"; public string text203 = "视角归位"; public string text204 = "查看靶子"; public string text205 = "关闭"; // 游戏规则 public string text1000 = "在固定的时间内尽量射更多的箭。"; public string text1001 = "总环数逐渐增加,挑战自己的纪录。"; public string text2000 = "两个人轮流射箭,使用奥运会的规则进行PK。"; public string text2001 = "比赛最多为5局,每局3支箭,交替射箭。"; public string text2002 = "获胜者获得积分2分,打平各1分,输者不得积分。"; public string text2003 = "先得6分者胜利,如5局打完是平局,则加赛一箭定胜负。"; //道具名称 public string text101000 = "{0}倍镜"; public string text101001 = "{0}倍射程卡"; // 道具介绍 public string text111000 = "射箭瞄准时,视距放大{0}倍。"; public string text111001 = "射箭时,射程增加{0}倍。"; //设备名称 public string text201000 = "18磅反曲弓"; public string text201001 = "25磅反曲弓"; public string text201002 = "碳纤维箭"; // 设备介绍 public string text211000 = "奥运比赛专用比赛弓"; public string text211001 = "奥运比赛专用比赛弓"; public string text211002 = "奥运比赛专用比赛箭"; } class LanguageEnglish : LanguageDefault { public new string text1 = "Name :"; public new string text2 = "Phone :"; public new string text3 = "Gender :"; public new string text4 = "Birthday :"; public new string text5 = "Country :"; public new string text6 = "Region :"; public new string text7 = "Save"; public new string text8 = "Male"; public new string text9 = "Female"; public new string text10 = "Not Filled In"; public new string text11 = "Name Cannot Be Empty"; public new string text12 = "Saved Successfully"; public new string text13 = "Me"; public new string text14 = "Connect"; public new string text15 = "Trying"; public new string text16 = "Activated"; public new string text17 = "Failed"; public new string text18 = "Bow"; public new string text19 = "Arrow"; public new string text20 = "SetUp"; public new string text21 = "Course"; public new string text22 = "Shop"; public new string text23 = "Device"; public new string text24 = "Username:"; public new string text25 = "Password:"; public new string text26 = "Forget Password"; public new string text27 = "Register"; public new string text28 = "Username :"; public new string text29 = "Password :"; public new string text30 = "Confirm Password :"; public new string text31 = "Nickname :"; public new string text32 = "Gender :"; public new string text33 = "Login"; public new string text34 = "Phone :"; public new string text35 = "Code :"; public new string text36 = "Password :"; public new string text37 = "Confirm Password :"; public new string text38 = "Get"; public new string text39 = "User Login"; public new string text40 = "Phone Login"; public new string text41 = "Please Enter Username"; public new string text42 = "Please Enter Password"; public new string text43 = "Login Successful"; public new string text44 = "Wrong Password"; public new string text45 = "User Not Register"; public new string text46 = "Username At Least 6 Digits"; public new string text47 = "Password At Least 6 Digits"; public new string text48 = "Two Passwords Are Inconsistent"; public new string text49 = "Please Enter Nickname"; public new string text50 = "Unable To Re Register"; public new string text51 = "Register Successful"; public new string text61 = "Please Connect Device"; public new string text62 = "Close"; public new string text63 = "Products"; public new string text64 = "Bag"; public new string text65 = "Equipped"; public new string text66 = "Buy"; public new string text67 = "Property"; public new string text68 = "Difficulty : "; public new string text69 = "Device Course"; public new string text70 = "Game Course"; public new string text71 = "Role Select"; public new string text72 = "Player1"; public new string text73 = "Player2"; public new string text74 = "Start"; public new string text87 = "Current Round Player"; public new string text88 = "Continue"; public new string text89 = "Home"; public new string text90 = "Share"; public new string text91 = "Again"; public new string text92 = "PVP"; public new string text93 = "Player"; public new string text94 = "Distance Select"; public new string text95 = "Score:"; public new string text96 = "New Player Guide"; public new string text97 = "Back"; public new string text98 = "Complete"; public new string text99 = "Pass"; public new string text100 = "Limit"; public new string text101 = "Rank"; public new string text102 = "Game"; public new string text103 = "Login"; public new string text104 = "Over"; public new string text105 = "Win"; public new string text106 = "Lose"; public new string text107 = "SoldOut"; public new string text108 = "Use"; public new string text109 = "Inuse"; public new string text110 = "Cancel"; public new string text111 = "Multiple Mirrors Is Required"; public new string text112 = "Shoot Card Is Required"; public new string text113 = "Bow"; public new string text114 = "Arrow"; public new string text115 = "Round {0}"; //设备页面 public new string text500 = "GyrCalibrate"; public new string text501 = "MagCalibrate"; public new string text502 = "Identity"; public new string text503 = "16G Acc"; public new string text504 = "64G Acc"; //主页面 public new string text400 = "Quit Game"; //设置页面 public new string text300 = "Quit Login"; public new string text301 = "About Us"; public new string text302 = "BGM"; public new string text303 = "Sound"; public new string text304 = "Language"; public new string text305 = "English"; public new string text306 = "CrossHair"; public new string text307 = "ON"; public new string text308 = "OFF"; public new string text309 = "ShootLevel"; public new string text310 = "Easy"; public new string text311 = "Normal"; public new string text312 = "Hard"; //设备校准页面 public new string text76 = "Identity"; public new string text77 = "Back"; public new string text78 = "Next"; public new string text79 = "Complete"; public new string text80 = "Identity"; public new string text81 = "Point the solid bow to the front, and then click \nthe angle of view to return to the front."; public new string text82 = "Calibrate"; public new string text83 = "Stop"; public new string text84 = "Try to rotate the module at multiple angles until \nmultiple points in the three quadrants of XYZ form a circle."; public new string text85 = "Calibrate"; public new string text86 = "During calibration, the aiming module needs to be placed on the desktop."; public new string text116 = "Redo"; //游戏场景通用UI信息 public new string text200 = "Guide"; public new string text201 = "Scope"; public new string text202 = "Acc"; public new string text203 = "Identity"; public new string text204 = "View Target"; public new string text205 = "Close"; // 游戏规则 public new string text1000 = "Shoot as many arrows as you can at a fixed time."; public new string text1001 = "The total number of rings gradually increased, \nchallenging their own records."; public new string text2000 = "Two people arched in turn, using the rules of the Olympic Games PK."; public new string text2001 = "The maximum number of games is 5, 3 arrows in each game, \nshooting arrows alternately."; public new string text2002 = "The winner will get 2 points and 1 draw each. \nThe loser will not get points."; 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."; //道具名称 public new string text101000 = "{0}X Mirrors"; public new string text101001 = "{0}X Shoot"; // 道具介绍 public new string text111000 = "When shooting, the sight distance is enlarged by {0} times."; public new string text111001 = "In archery, the range increases by {0} times."; //设备名称 public new string text201000 = "18 Pound Bow"; public new string text201001 = "25 Pound Bow"; public new string text201002 = "Carbon Giber Arrow"; // 设备介绍 public new string text211000 = "Special bow for Olympic Games."; public new string text211001 = "Special bow for Olympic Games."; public new string text211002 = "Special competition arrow for Olympic Games."; }