TabListManager.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Localization;
  5. using UnityEngine.Localization.Settings;
  6. using UnityEngine.Localization.Tables;
  7. using UnityEngine.UI;
  8. public class TabListManager : MonoBehaviour
  9. {
  10. public GameObject Texiao;
  11. public List<GameObject> Tablist;
  12. public InfoWindow infoWindow;
  13. public static TabListManager Instance;
  14. public GameObject Fgo;
  15. public GameObject Sgo;
  16. public GameObject Tgo;
  17. public DeMaConfig dc;
  18. // public Text windowTop;
  19. public List<GameObject> golist;
  20. public Animator animator;
  21. public void Awake()
  22. {
  23. Instance=this;
  24. Fgo.SetActive(false);
  25. Sgo.SetActive(false);
  26. Tgo.SetActive(false);
  27. // 设置首选语言为英语
  28. SetLanguage("en");
  29. }
  30. StringTable stringTable ;
  31. // 通过 Key 获取对应的语言文本
  32. public string GetTextByKey(string key)
  33. {
  34. if(stringTable==null)
  35. stringTable= LocalizationSettings.StringDatabase.GetTable("DeMa");
  36. // 获取 TableEntry
  37. var tableEntry = stringTable.GetEntry(key);
  38. if (tableEntry != null)
  39. {
  40. // 返回翻译后的文本
  41. return tableEntry.GetLocalizedString();
  42. }
  43. else
  44. {
  45. return key;
  46. }
  47. }
  48. public void SetLanguage(string languageCode)
  49. {
  50. // 遍历所有可用的语言
  51. foreach (var locale in LocalizationSettings.AvailableLocales.Locales)
  52. {
  53. if (locale.Identifier.Code == languageCode)
  54. {
  55. LocalizationSettings.SelectedLocale = locale;
  56. Debug.Log("Language set to: " + languageCode);
  57. return;
  58. }
  59. }
  60. Debug.LogError("Language not found: " + languageCode);
  61. }
  62. public void Start()
  63. {
  64. TableReference tableReference = "DeMa";
  65. for (int i = 0;i<dc.TaskList.Count;i++)
  66. {
  67. GameObject fgo = GameObject.Instantiate(Fgo,Fgo.transform.parent);
  68. fgo.name = GetTextByKey( dc.TaskList[i].key);
  69. fgo.SetActive(true);
  70. FItemGo fg= new FItemGo();
  71. fg.info = dc.TaskList[i].info;
  72. fg.url = dc.TaskList[i].imgandmp4;
  73. fg.showList=new List<GameObject>();
  74. //fgo.GetComponentInChildren<Text>().text = GetTextByKey( dc.TaskList[i].name);
  75. LocalizedText tt= fgo.GetComponentInChildren<Text>().gameObject.AddComponent<LocalizedText>();
  76. tt.localizedString= new LocalizedString();
  77. tt.localizedString.TableReference = tableReference;
  78. tt.changeKey(dc.TaskList[i].key); // 设置你的 Key
  79. for (int p=0;p<dc.TaskList[i].goidx.Count;p++)
  80. {
  81. fg.showList.Add(golist[dc.TaskList[i].goidx[p]]);
  82. }
  83. fg.Idx = i;
  84. fg.go = fgo;
  85. fg.init();
  86. fgoList.Add(fg);
  87. for (int j = 0;j<dc.TaskList[i].slist.Count;j++)
  88. {
  89. GameObject sgo = GameObject.Instantiate(Sgo,Sgo.transform.parent);
  90. sgo.name =GetTextByKey( dc.TaskList[i].slist[j].key);;
  91. sgo.SetActive(false);
  92. SItemGo sg= new SItemGo();
  93. sg.tab =Tablist[ dc.TaskList[i].slist[j].tabidx];
  94. sg.info = dc.TaskList[i].slist[j].info;
  95. sg.url = dc.TaskList[i].slist[j].imgandmp4;
  96. if(sg.tab)
  97. {
  98. Debug.Log(" sg.tab===>"+ sg.tab.name);
  99. //fgo.GetComponentInChildren<Text>().text = GetTextByKey( dc.TaskList[i].name);
  100. LocalizedText ttt= sg.tab.GetComponentInChildren<Text>().gameObject.AddComponent<LocalizedText>();
  101. ttt.localizedString= new LocalizedString();
  102. ttt.localizedString.TableReference = tableReference;
  103. ttt.changeKey(dc.TaskList[i].slist[j].key); // 设置你的 Key
  104. }
  105. sg.showList=new List<GameObject>();
  106. for (int p=0;p<dc.TaskList[i].slist[j].goidx.Count;p++)
  107. {
  108. sg.showList.Add(golist[dc.TaskList[i].slist[j].goidx[p]]);
  109. }
  110. sg.Idx = j;
  111. sg.go = sgo;
  112. sg.init();
  113. // sgo.GetComponentInChildren<Text>().text =GetTextByKey( dc.TaskList[i].slist[j].name);
  114. LocalizedText tt2= sgo.GetComponentInChildren<Text>().gameObject.AddComponent<LocalizedText>();
  115. tt2.localizedString= new LocalizedString();
  116. tt2.localizedString.TableReference = tableReference;
  117. tt2.changeKey( dc.TaskList[i].slist[j].key); // 设置你的 Key
  118. fgoList[i].slist.Add(sg);
  119. for (int z = 0;z<dc.TaskList[i].slist[j].tlist.Count;z++)
  120. {
  121. GameObject tgo = GameObject.Instantiate(Tgo,Tgo.transform.parent);
  122. tgo.name = GetTextByKey(dc.TaskList[i].slist[j].tlist[z].key);
  123. tgo.SetActive(false);
  124. TItemGo tg= new TItemGo();
  125. tg.application = dc.TaskList[i].slist[j].tlist[z].application;
  126. tg.title = dc.TaskList[i].slist[j].tlist[z].key;
  127. tg.Idx = dc.TaskList[i].slist[j].tlist[z].index;
  128. tg.info = dc.TaskList[i].slist[j].tlist[z].info;
  129. tg.info2 = dc.TaskList[i].slist[j].tlist[z].info2;
  130. tg.url = dc.TaskList[i].slist[j].tlist[z].imgandmp4;
  131. tg.showList=golist[dc.TaskList[i].slist[j].tlist[z].goidx];
  132. try
  133. {
  134. if(tg.showList.GetComponent<ModelXuHua>().TabGo!=null)
  135. {
  136. LocalizedText tt4 = tg.showList.GetComponent<ModelXuHua>().TabGo.GetComponentInChildren<Text>().gameObject.AddComponent<LocalizedText>();
  137. tt4.localizedString= new LocalizedString();
  138. tt4.localizedString.TableReference = tableReference;
  139. tt4.changeKey(dc.TaskList[i].slist[j].tlist[z].key); // 设置你的 Key
  140. }
  141. }catch
  142. {
  143. }
  144. tg.go = tgo;
  145. tg.init();
  146. // tgo.GetComponentInChildren<Text>().text =GetTextByKey(dc.TaskList[i].slist[j].tlist[z].name);
  147. LocalizedText tt3= tgo.GetComponentInChildren<Text>().gameObject.AddComponent<LocalizedText>();
  148. tt3.localizedString= new LocalizedString();
  149. tt3.localizedString.TableReference = tableReference;
  150. tt3.changeKey(dc.TaskList[i].slist[j].tlist[z].key); // 设置你的 Key
  151. fgoList[i].slist[j].tlist.Add(tg);
  152. }
  153. }
  154. }
  155. //StartCoroutine(Dh());
  156. TabListManager.Instance.infoWindow.gameObject.SetActive(true);
  157. TabListManager.Instance.infoWindow.init("300001","","",0,"301001","320001");
  158. }
  159. bool isstart=true;
  160. private IEnumerator Dh()
  161. {
  162. int idx=0;
  163. while (isstart)
  164. {
  165. yield return new WaitForSeconds(60f);
  166. if(idx==0)
  167. golist[1].GetComponent<ModelXuHua>().hide();
  168. else
  169. {
  170. golist[0].GetComponent<ModelXuHua>().hide();
  171. }
  172. idx++;
  173. yield return new WaitForSeconds(2f);
  174. if(idx>1)
  175. {
  176. yield return new WaitForSeconds(30f);
  177. idx=0;
  178. golist[0].GetComponent<ModelXuHua>().show();
  179. yield return new WaitForSeconds(0.5f);
  180. golist[0].GetComponent<ModelXuHua>().changemode();
  181. yield return new WaitForSeconds(30f);
  182. golist[1].GetComponent<ModelXuHua>().show();
  183. yield return new WaitForSeconds(0.5f);
  184. golist[1].GetComponent<ModelXuHua>().changemode();
  185. }
  186. }
  187. }
  188. int nowFindx=-1;
  189. public void showF(int index,bool isF=true)
  190. {
  191. for (int i=0;i<Tablist.Count;i++)
  192. {
  193. Tablist[i].SetActive(false);
  194. }
  195. TabListManager.Instance.infoWindow.gameObject.SetActive(true);
  196. TabListManager.Instance.infoWindow.init("300001","","",0,"301001","320001");
  197. if(nowFindx==index&&isF)
  198. {
  199. nowFindx=-1;
  200. isstart=true;
  201. //StartCoroutine(Dh());
  202. showAllModel();
  203. }
  204. else
  205. {
  206. isstart=false;
  207. StopAllCoroutines();
  208. nowFindx=index;
  209. for (int i=0;i<fgoList[nowFindx].slist.Count;i++)
  210. {
  211. fgoList[nowFindx].slist[i].go.SetActive(true);
  212. }
  213. closeAllModel();
  214. for (int j=0;j< fgoList[nowFindx].showList.Count;j++)
  215. {
  216. fgoList[nowFindx].showList[j].GetComponent<ModelXuHua>().showModel();
  217. }
  218. }
  219. }
  220. public void showT(int index)
  221. {
  222. TabListManager.Instance.infoWindow.gameObject.SetActive(false);
  223. showF(nowFindx,false);
  224. for (int i=0;i<fgoList[nowFindx].slist[index].tlist.Count;i++)
  225. {
  226. fgoList[nowFindx].slist[index].tlist[i].go.SetActive(true);
  227. }
  228. for (int i=0;i<Tablist.Count;i++)
  229. {
  230. Tablist[i].SetActive(false);
  231. }
  232. fgoList[nowFindx].slist[index].tab.SetActive(true);
  233. }
  234. public void closeAllModel()
  235. {
  236. for (int i=0;i<golist.Count;i++)
  237. {
  238. if(golist[i]&&golist[i].GetComponent<ModelXuHua>())
  239. golist[i].GetComponent<ModelXuHua>().showBaiMo();
  240. }
  241. }
  242. public void showAllModel()
  243. {
  244. for (int i=0;i<golist.Count;i++)
  245. {
  246. golist[i].GetComponent<ModelXuHua>().showModel(false);
  247. }
  248. for (int i=0;i<Tablist.Count;i++)
  249. {
  250. Tablist[i].SetActive(false);
  251. }
  252. Texiao.SetActive(false);
  253. animator.enabled=true;
  254. }
  255. public void showInfo(GameObject go)
  256. {
  257. // windowTop.transform.parent.parent.gameObject.SetActive(true);
  258. // windowTop.text = go.GetComponentInChildren<Text>().text;
  259. }
  260. public GameObject TabGoList;
  261. public void showTab(GameObject go)
  262. {
  263. TabGoList.SetActive(false);
  264. for (int i=0;i<TabGoList.GetAllChildren().Count;i++)
  265. {
  266. TabGoList.transform.GetChild(i).gameObject.SetActive(false);
  267. }
  268. if(go.GetComponent<ModelXuHua>().TabGo)
  269. go.GetComponent<ModelXuHua>().TabGo.SetActive(true);
  270. // windowTop.transform.parent.parent.gameObject.SetActive(true);
  271. // windowTop.text = go.GetComponentInChildren<Text>().text;
  272. for (int i=0;i<Tablist.Count;i++)
  273. {
  274. Tablist[i].SetActive(false);
  275. }
  276. }
  277. public void closeTab()
  278. {
  279. TabGoList.SetActive(false);
  280. }
  281. public void clossAll()
  282. {
  283. // windowTop.transform.parent.parent.gameObject.SetActive(false);
  284. for (int i = 0;i<fgoList.Count;i++)
  285. {
  286. for (int j = 0;j<fgoList[i].slist.Count;j++)
  287. {
  288. fgoList[i].slist[j].go.SetActive(false);
  289. for (int z = 0;z<fgoList[i].slist[j].tlist.Count;z++)
  290. {
  291. fgoList[i].slist[j].tlist[z].go.SetActive(false);
  292. }
  293. }
  294. }
  295. }
  296. List<FItemGo> fgoList = new List<FItemGo>();
  297. [System.Serializable]
  298. public class FItemGo
  299. {
  300. public string info;
  301. public string url;
  302. public int Idx;
  303. public GameObject go;
  304. public List<SItemGo> slist= new List<SItemGo>();
  305. public List<GameObject> showList =new List<GameObject>();
  306. public void init()
  307. {
  308. go.GetComponent<Button>().onClick.AddListener(()=>{
  309. TabListManager.Instance.clossAll();
  310. TabListManager.Instance.showF(Idx);
  311. Debug.Log("TabListManager.Instance.nowFindx"+TabListManager.Instance.nowFindx);
  312. if( TabListManager.Instance.nowFindx!=-1)
  313. {
  314. TabListManager.Instance.animator.Play("Take 001", 0, 0f);
  315. TabListManager.Instance.animator.speed =0;
  316. TabListManager.Instance.showInfo(go);
  317. TabListManager.Instance.closeAllModel();
  318. for (int j=0;j< showList.Count;j++)
  319. {
  320. showList[j].GetComponent<ModelXuHua>().showModel();
  321. }
  322. }
  323. else
  324. {
  325. TabListManager.Instance.animator.Play("Take 001", 0, 0f);
  326. TabListManager.Instance.animator.speed =1;
  327. }
  328. TabListManager.Instance.closeTab();
  329. TabListManager.Instance.Texiao.SetActive(false);
  330. });
  331. }
  332. }
  333. public class SItemGo
  334. {
  335. public GameObject tab;
  336. public string info;
  337. public string url;
  338. public int Idx;
  339. public GameObject go;
  340. public List<TItemGo> tlist= new List<TItemGo>();
  341. public List<GameObject> showList =new List<GameObject>();
  342. public void init()
  343. {
  344. go.GetComponent<Button>().onClick.AddListener(()=>{
  345. TabListManager.Instance.clossAll();
  346. TabListManager.Instance.showT(Idx);
  347. TabListManager.Instance.showInfo(go);
  348. TabListManager.Instance.closeAllModel();
  349. for (int j=0;j< showList.Count;j++)
  350. {
  351. showList[j].GetComponent<ModelXuHua>().showModel();
  352. }
  353. TabListManager.Instance.closeTab();
  354. TabListManager.Instance.infoWindow.gameObject.SetActive(false);
  355. TabListManager.Instance.Texiao.SetActive(false);
  356. TabListManager.Instance.animator.Play("Take 001", 0, 0f);
  357. TabListManager.Instance.animator.speed =0;
  358. });
  359. }
  360. }
  361. public class TItemGo
  362. {
  363. public string info;
  364. public string info2;
  365. public string url;
  366. public string title;
  367. public string application;
  368. public int Idx;
  369. public GameObject go;
  370. public GameObject showList =new GameObject();
  371. public void init()
  372. {
  373. go.GetComponent<Button>().onClick.AddListener(()=>{
  374. TabListManager.Instance.showInfo(go);
  375. TabListManager.Instance.closeAllModel();
  376. showList.GetComponent<ModelXuHua>().showModel();
  377. TabListManager.Instance.showTab(showList);
  378. TabListManager.Instance.infoWindow.gameObject.SetActive(true);
  379. TabListManager.Instance.infoWindow.init(info,url,info2,Idx,title,application);
  380. TabListManager.Instance.Texiao.SetActive(true);
  381. TabListManager.Instance.animator.Play("Take 001", 0, 0f);
  382. TabListManager.Instance.animator.speed =0;
  383. });
  384. }
  385. }
  386. }