TianJiWindowManager.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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 showPoPdf(int i,string path)
  62. {
  63. PopWindowManager.pdfpath = path;
  64. PopWindowManager.indexwd =i;
  65. PopGo.SetActive(true);
  66. }
  67. public void showPoTexure2D(int i,Texture tex)
  68. {
  69. PopWindowManager.texture = tex;
  70. PopWindowManager.indexwd =i;
  71. PopGo.SetActive(true);
  72. }
  73. public void showPop(int i =0,string str ="")
  74. {
  75. PopWindowManager.info = str;
  76. PopWindowManager.indexwd =i;
  77. PopGo.SetActive(true);
  78. }
  79. public void closepop()
  80. {
  81. PopGo.SetActive(false);
  82. }
  83. public void showPop(int i =0)
  84. {
  85. PopWindowManager.indexwd =i;
  86. PopGo.SetActive(true);
  87. }
  88. public void showMain()
  89. {
  90. this.gameObject.SetActive(true);
  91. }
  92. public void showRTC()
  93. {
  94. this.gameObject.SetActive(false);
  95. }
  96. public void SelectEnglish(bool isY)
  97. {
  98. if(isY)
  99. {
  100. SetLanguage("en");
  101. }
  102. }
  103. public void SelectChinese(bool isY)
  104. {
  105. if(isY)
  106. {
  107. SetLanguage("zh");
  108. }
  109. }
  110. public void SetLanguage(string languageCode)
  111. {
  112. // 遍历所有可用的语言
  113. foreach (var locale in LocalizationSettings.AvailableLocales.Locales)
  114. {
  115. if (locale.Identifier.Code == languageCode)
  116. {
  117. LocalizationSettings.SelectedLocale = locale;
  118. Debug.Log("Language set to: " + languageCode);
  119. return;
  120. }
  121. }
  122. Debug.LogError("Language not found: " + languageCode);
  123. }
  124. StringTable stringTable ;
  125. // 通过 Key 获取对应的语言文本
  126. public string GetTextByKey(string key)
  127. {
  128. if(stringTable==null)
  129. stringTable= LocalizationSettings.StringDatabase.GetTable("tinaji");
  130. // 获取 TableEntry
  131. var tableEntry = stringTable.GetEntry(key);
  132. if (tableEntry != null)
  133. {
  134. // 返回翻译后的文本
  135. return tableEntry.GetLocalizedString();
  136. }
  137. else
  138. {
  139. return key;
  140. }
  141. }
  142. public static List<string> getConfigstr(int a,int b,int d)
  143. {
  144. List<string> strings =new List<string>();
  145. strings.Add("") ;
  146. strings.Add("") ;
  147. strings.Add("") ;
  148. for (int i = 0;i<WindowMainManager.instance.TJConfig.config.Count;i++)
  149. {
  150. if(WindowMainManager.instance.TJConfig.config[i].value == a)
  151. {
  152. strings[0]=WindowMainManager.instance.TJConfig.config[i].zh;
  153. Config c = WindowMainManager.instance.TJConfig.config[i];
  154. if(c.children!=null)
  155. {
  156. for (int j = 0;j<c.children.Count;j++)
  157. {
  158. if(c.children[j].value == b)
  159. {
  160. strings[1]=c.children[j].zh;
  161. if(c.children[j].children!=null)
  162. {
  163. for (int k = 0;k<c.children[j].children.Count;k++)
  164. {
  165. if(c.children[j].children[k].value == d)
  166. {
  167. strings[2]=c.children[j].children[k].zh;
  168. }
  169. }
  170. }
  171. }
  172. }
  173. }
  174. }
  175. }
  176. return strings;
  177. }
  178. public static List<string> getConfigServerTypestr(int a,int b)
  179. {
  180. List<string> strings =new List<string>();
  181. for (int i = 0;i<WindowMainManager.instance.TJConfig.config.Count;i++)
  182. {
  183. if(WindowMainManager.instance.TJConfig.config[i].value == a)
  184. {
  185. strings.Add(WindowMainManager.instance.TJConfig.config[i].zh);
  186. if(WindowMainManager.instance.TJConfig.config[i].serviceType!=null)
  187. {
  188. for (int j = 0;j<WindowMainManager.instance.TJConfig.config[i].serviceType.Count;j++)
  189. {
  190. if(b==WindowMainManager.instance.TJConfig.config[i].serviceType[j].value)
  191. {
  192. strings.Add(WindowMainManager.instance.TJConfig.config[i].serviceType[j].zh);
  193. }
  194. }
  195. }
  196. }
  197. }
  198. if(strings.Count<2)
  199. {
  200. strings.Add("");
  201. }
  202. return strings;
  203. }
  204. }