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 LanguageEnum currentLanguageEnum = LanguageEnum.Chinese; static LanguageDefault language = null; static HashSet textAutoLanguages = new HashSet(); public string[] textFormatArgs = {}; [SerializeField] LanguageFontSize[] languageFontSizes = {}; private static bool inited = false; public static void Init() { if (inited) return; inited = true; int id = PlayerPrefs.GetInt("Language", 0); ChangeLanguage((LanguageEnum) id); } public static void ChangeLanguage(LanguageEnum languageEnum) { currentLanguageEnum = languageEnum; if (languageEnum == LanguageEnum.English) { language = new LanguageEnglish(); } else if (languageEnum == LanguageEnum.Japan) { language = new LanguageJapan(); } else { language = new LanguageDefault(); } PlayerPrefs.SetInt("Language", ((int)languageEnum)); foreach (var textAutoLanguage in textAutoLanguages) { try { textAutoLanguage.ApplyText(); } catch (Exception e) { Debug.LogError(e.Message); } } } public static LanguageEnum GetLanguage() { Init(); if (language is LanguageEnglish) { return LanguageEnum.English; } else if (language is LanguageJapan) { return LanguageEnum.Japan; } return LanguageEnum.Chinese; } void Awake() { Init(); } void Start() { textAutoLanguages.Add(this); ApplyText(); } void OnDestroy() { textAutoLanguages.Remove(this); } /**记录组件的默认字体大小 */ private int defaultFontSize = -1; 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); } Text textComp = GetComponent(); textComp.text = text; //如果有指定当前语言的字体大小,就更新字体大小,否则恢复默认字体大小 if (defaultFontSize == -1) { //首次记录组件的默认字体大小 defaultFontSize = textComp.fontSize; } else { textComp.fontSize = defaultFontSize; } if (languageFontSizes.Length > 0) { foreach (var languageFontSize in languageFontSizes) { if (languageFontSize.language == currentLanguageEnum) { textComp.fontSize = languageFontSize.fontSize; } } } //重置指定节点的布局 if (layoutRebuildObject) { LayoutRebuilder.ForceRebuildLayoutImmediate(layoutRebuildObject); } } public int GetTextID() { return this.textID; } void ApplyText() { SetText(textID); } } 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 text117 = "长度{0}~{1}位,限英文和数字"; public string text118 = "靶子已超出当前射程,请加大拉距或去商城装备射速卡!"; public string text119 = "长度{0}~{1}位,可使用中文"; //设备页面 public string text500 = "陀螺仪初始化"; public string text501 = "地磁计初始化"; public string text502 = "视角回正"; public string text503 = "16G加速计"; public string text504 = "64G加速计"; //主页面 public string text122 = "排行榜"; public string text123 = "好友"; public string text124 = "开始游戏"; public string text125 = "联机游戏"; //我的 public string text126 = "编 号 :"; //开始游戏 public string text133 = "开始游戏"; public string text127 = "闯关游戏"; public string text128 = "限时游戏"; public string text129 = "PK游戏"; //PK模式选择页面 public string text132 = "PK模式"; public string text130 = "静止靶PK"; public string text131 = "闯关PK"; public string text401 = "选择关卡"; //关卡选择 public string text134 = "游戏模式"; public string text135 = "野兔关卡"; public string text136 = "野鸡关卡"; public string text137 = "野狼关卡"; //设置页面 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 text313 = "实际箭重"; public string text314 = "{0}克"; //SetUpView1 public string text315 = "游戏设置"; public string text318 = "新手引导"; public string text301 = "关于我们"; public string text316 = "用户协议"; public string text317 = "隐私政策"; public string text300 = "退出登录"; public string text400 = "退出游戏"; //设备校准页面 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 = "重新初始化"; public string text120 = "校准效果不理想,请重新校准!"; public string text121 = "取消初始化"; //游戏场景通用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 text200000 = "反曲弓"; public string text201000 = "18磅反曲弓"; public string text201001 = "25磅反曲弓"; public string text201002 = "碳纤维箭"; // 设备介绍 public string text211000 = "奥运比赛专用比赛弓"; public string text211001 = "奥运比赛专用比赛弓"; public string text211002 = "奥运比赛专用比赛箭"; //审核时用到的临时文字-设置页面 public string text1234560 = "基础设置"; public string text1234561 = "退出应用"; public string text1234562 = "开始"; public string text1234563 = "联机"; } 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 = "My"; public new string text14 = "Connect"; public new string text15 = "Connecting"; public new string text16 = "Connected"; public new string text17 = " Break "; 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 = "Account:"; public new string text25 = "Password:"; public new string text26 = "Retrieve Password"; public new string text27 = "New User Register"; public new string text28 = "Account :"; 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 = "Account"; public new string text40 = "Phone Number"; public new string text41 = "Please Enter Account"; 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 = "Account 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 = "Select PFP"; 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 = "Select Range"; 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 = "Challenge"; public new string text100 = "Limit"; public new string text101 = "Rank"; public new string text102 = "Game"; public new string text103 = "Bind"; 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 text117 = "Limit {0}~{1} Bit, English And Figures"; 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!"; public new string text119 = "Limit {0}~{1} Bit, Can Use Chinese"; //设备页面 public new string text500 = "Gyr Init"; public new string text501 = "Mag Init"; public new string text502 = "ResetView"; public new string text503 = "16G Acc"; public new string text504 = "64G Acc"; //主页面 public new string text122 = "Rank"; public new string text123 = "Friend"; public new string text124 = "Start"; public new string text125 = "Online"; //我的 public new string text126 = "ID :"; //开始游戏 public new string text133 = "Stand Alone"; public new string text127 = "Hunting"; public new string text128 = "Target"; public new string text129 = "1 v 1"; //PK模式选择页面 public new string text132 = "Dart Game"; public new string text130 = "TARGET"; public new string text131 = "HUNTING"; public new string text401 = "Select Level"; //关卡选择 public new string text134 = "Hunting"; public new string text135 = "Hare"; public new string text136 = "Pheasant"; public new string text137 = "Wild Wolf"; //设置页面 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 text313 = "ArrowWeight"; public new string text314 = "{0}Gram"; //SetUpView1 public new string text315 = "Game Settings"; public new string text318 = "Novice Guidance"; public new string text301 = "About Us"; public new string text316 = "User Agreement"; public new string text317 = "Privacy Policy"; public new string text300 = "Quit Login"; public new string text400 = "Quit Game"; //设备校准页面 public new string text76 = "ResetView"; public new string text77 = "Back"; public new string text78 = "Next"; public new string text79 = "Complete"; public new string text80 = "ResetView"; 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"; public new string text120 = "The calibration effect is not ideal, please recalibrate!"; public new string text121 = "Cancel"; //游戏场景通用UI信息 public new string text200 = "Tips"; public new string text201 = "Scope"; public new string text202 = "Acc"; public new string text203 = "Aim Reset"; public new string text204 = "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 speed increases by {0} times."; //设备名称 public new string text200000 = "Recurve Bow"; 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."; //审核时用到的临时文字-设置页面 public new string text1234560 = "Base Settings"; public new string text1234561 = "Quit App"; public new string text1234562 = "Start"; public new string text1234563 = "Online"; } class LanguageJapan: 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 = "2回のパスワードが一致しません"; 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 text117 = "{0}~{1}文字、英数字のみ使用可能"; public string text118 = "的が射程外です。引きを強くするか、ショップで射速カードを購入してください!"; public string text119 = "{0}~{1}文字、中国語も使用可能"; // デバイスページ public string text500 = "ジャイロ初期化"; public string text501 = "地磁気センサー初期化"; public string text502 = "視点リセット"; public string text503 = "16G加速度計"; public string text504 = "64G加速度計"; // メインページ public string text122 = "ランキング"; public string text123 = "フレンド"; public string text124 = "ゲーム開始"; public string text125 = "オンライン対戦"; // マイページ public string text126 = "ID :"; // ゲーム開始 public string text133 = "ゲーム開始"; public string text127 = "ステージモード"; public string text128 = "タイムアタック"; public string text129 = "PKゲーム"; // PKモード選択 public string text132 = "PKモード"; public string text130 = "静止ターゲットPK"; public string text131 = "ステージPK"; public string text401 = "ステージ選択"; // ステージ選択 public string text134 = "ゲームモード"; public string text135 = "ウサギステージ"; public string text136 = "ニワトリステージ"; public string text137 = "オオカミステージ"; // 設定ページ public string text302 = "BGM"; 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 text313 = "実際の矢の重さ"; public string text314 = "{0}グラム"; // 設定ページその2 public string text315 = "ゲーム設定"; public string text318 = "初心者ガイド"; public string text301 = "私たちについて"; public string text316 = "利用規約"; public string text317 = "プライバシーポリシー"; public string text300 = "ログアウト"; public string text400 = "ゲーム終了"; // デバイスキャリブレーション 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 = "再初期化"; public string text120 = "キャリブレーションがうまくいきません。再試行してください!"; public string text121 = "初期化をキャンセル"; // ゲーム共通UI public string text200 = "ガイド"; public string text201 = "スコープON"; public string text202 = "加速"; public string text203 = "視点リセット"; public string text204 = "的を確認"; public string text205 = "閉じる"; // ゲームルール public string text1000 = "制限時間内にできるだけ多くの矢を射ちましょう。"; public string text1001 = "総得点が徐々に増え、自分の記録に挑戦します。"; public string text2000 = "2人で交互に矢を放ち、オリンピックルールで対戦します。"; public string text2001 = "最大5ラウンド、各ラウンド3本の矢を交互に射ちます。"; public string text2002 = "勝者に2点、引き分けは各1点、敗者は0点です。"; public string text2003 = "先に6点を取った方が勝利。5ラウンド終了で同点の場合、1本勝負で決着します。"; // アイテム名 public string text101000 = "{0}倍スコープ"; public string text101001 = "{0}倍射速カード"; // アイテム説明 public string text111000 = "照準時、視野が{0}倍に拡大されます。"; public string text111001 = "矢を射つ速度が{0}倍に上がります。"; // デバイス名 public string text200000 = "リカーブボウ"; public string text201000 = "18ポンド リカーブボウ"; public string text201001 = "25ポンド リカーブボウ"; public string text201002 = "カーボンアロー"; // デバイス説明 public string text211000 = "オリンピック競技用のリカーブボウ"; public string text211001 = "オリンピック競技用のリカーブボウ"; public string text211002 = "オリンピック競技用の矢"; // 審査用一時テキスト public string text1234560 = "基本設定"; public string text1234561 = "アプリ終了"; public string text1234562 = "開始"; public string text1234563 = "オンライン"; }