TianJiWindowManager.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using FantomLib;
  5. using UnityEngine;
  6. using UnityEngine.Events;
  7. using UnityEngine.Localization.Settings;
  8. using UnityEngine.Localization.Tables;
  9. using static DeMaTJConfig;
  10. public class TianJiWindowManager : MonoBehaviour
  11. {
  12. public DeviceTypeDetail dtdlist;
  13. public static TianJiWindowManager Instance ;
  14. public GameObject LoginGo;
  15. public GameObject MainGo;
  16. public GameObject PopGo;
  17. public string style = "android:Theme.Holo"; //Dialog theme
  18. void Awake()
  19. {
  20. Instance=this;
  21. Application.targetFrameRate=120;
  22. QualitySettings.vSyncCount = 0; // 禁用垂直同步
  23. // 设置首选语言为英语
  24. SetLanguage("zh");
  25. Invoke("Loadinginit",1f);
  26. }
  27. void OnEnable()
  28. {
  29. }
  30. public Action<string> OnResult;
  31. public void chooseDate(Action<string> callback)
  32. {
  33. OnResult=callback;
  34. AndroidPlugin.ShowDatePickerDialog(
  35. DateTime.Now.ToString() ,
  36. "yyyy'-'M'-'d",
  37. this.gameObject.name,
  38. "ReceiveResult",
  39. style);
  40. }
  41. //Returns value when 'OK' pressed.
  42. private void ReceiveResult(string result)
  43. {
  44. if (OnResult != null)
  45. OnResult.Invoke(result);
  46. }
  47. void Loadinginit()
  48. {
  49. gotoLogin();
  50. }
  51. public void gotoMain()
  52. {
  53. MainGo.SetActive(true);
  54. LoginGo.SetActive(false);
  55. }
  56. public void gotoLogin()
  57. {
  58. MainGo.SetActive(false);
  59. LoginGo.SetActive(true);
  60. }
  61. public void showPop(int i =0,string str ="")
  62. {
  63. PopWindowManager.info = str;
  64. PopWindowManager.indexwd =i;
  65. PopGo.SetActive(true);
  66. }
  67. public void showPop(int i =0)
  68. {
  69. PopWindowManager.indexwd =i;
  70. PopGo.SetActive(true);
  71. }
  72. public void showMain()
  73. {
  74. this.gameObject.SetActive(true);
  75. }
  76. public void showRTC()
  77. {
  78. this.gameObject.SetActive(false);
  79. }
  80. public void SelectEnglish(bool isY)
  81. {
  82. if(isY)
  83. {
  84. SetLanguage("en");
  85. }
  86. }
  87. public void SelectChinese(bool isY)
  88. {
  89. if(isY)
  90. {
  91. SetLanguage("zh");
  92. }
  93. }
  94. public void SetLanguage(string languageCode)
  95. {
  96. // 遍历所有可用的语言
  97. foreach (var locale in LocalizationSettings.AvailableLocales.Locales)
  98. {
  99. if (locale.Identifier.Code == languageCode)
  100. {
  101. LocalizationSettings.SelectedLocale = locale;
  102. Debug.Log("Language set to: " + languageCode);
  103. return;
  104. }
  105. }
  106. Debug.LogError("Language not found: " + languageCode);
  107. }
  108. StringTable stringTable ;
  109. // 通过 Key 获取对应的语言文本
  110. public string GetTextByKey(string key)
  111. {
  112. if(stringTable==null)
  113. stringTable= LocalizationSettings.StringDatabase.GetTable("tinaji");
  114. // 获取 TableEntry
  115. var tableEntry = stringTable.GetEntry(key);
  116. if (tableEntry != null)
  117. {
  118. // 返回翻译后的文本
  119. return tableEntry.GetLocalizedString();
  120. }
  121. else
  122. {
  123. return key;
  124. }
  125. }
  126. public static List<string> getConfigstr(int a,int b,int d)
  127. {
  128. List<string> strings =new List<string>();
  129. strings.Add("") ;
  130. strings.Add("") ;
  131. strings.Add("") ;
  132. for (int i = 0;i<WindowMainManager.instance.TJConfig.config.Count;i++)
  133. {
  134. if(WindowMainManager.instance.TJConfig.config[i].value == a)
  135. {
  136. strings[0]=WindowMainManager.instance.TJConfig.config[i].zh;
  137. Config c = WindowMainManager.instance.TJConfig.config[i];
  138. if(c.children!=null)
  139. {
  140. for (int j = 0;j<c.children.Count;j++)
  141. {
  142. if(c.children[j].value == b)
  143. {
  144. strings[1]=c.children[j].zh;
  145. if(c.children[j].children!=null)
  146. {
  147. for (int k = 0;k<c.children[j].children.Count;k++)
  148. {
  149. if(c.children[j].children[k].value == d)
  150. {
  151. strings[2]=c.children[j].children[k].zh;
  152. }
  153. }
  154. }
  155. }
  156. }
  157. }
  158. }
  159. }
  160. return strings;
  161. }
  162. public static List<string> getConfigServerTypestr(int a,int b)
  163. {
  164. List<string> strings =new List<string>();
  165. for (int i = 0;i<WindowMainManager.instance.TJConfig.config.Count;i++)
  166. {
  167. if(WindowMainManager.instance.TJConfig.config[i].value == a)
  168. {
  169. strings.Add(WindowMainManager.instance.TJConfig.config[i].zh);
  170. if(WindowMainManager.instance.TJConfig.config[i].serviceType!=null)
  171. {
  172. for (int j = 0;j<WindowMainManager.instance.TJConfig.config[i].serviceType.Count;j++)
  173. {
  174. if(b==WindowMainManager.instance.TJConfig.config[i].serviceType[j].value)
  175. {
  176. strings.Add(WindowMainManager.instance.TJConfig.config[i].serviceType[j].zh);
  177. }
  178. }
  179. }
  180. }
  181. }
  182. if(strings.Count<2)
  183. {
  184. strings.Add("");
  185. }
  186. return strings;
  187. }
  188. }