ShiPingJianKongManager.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using static Manager;
  6. public class ShiPingJianKongManager : UpdateManager
  7. {
  8. public static ShiPingJianKongManager Instance;
  9. // Start is called before the first frame update
  10. void Awake()
  11. {
  12. Instance = this;
  13. }
  14. int chooseroom = 0;
  15. public void chooseToggle(int index)
  16. {
  17. if(index!=0)
  18. {
  19. chooseroom = index;
  20. updateData();
  21. }
  22. }
  23. public IEnumerator show()
  24. {
  25. while(ServerRoomVideoManager.csid==0)
  26. {
  27. yield return null;
  28. }
  29. chooseroom = ServerRoomVideoManager.csid;
  30. Debug.Log("chooseroom=2=>" + chooseroom);
  31. updateData();
  32. }
  33. private void OnEnable()
  34. {
  35. StartCoroutine(show());
  36. }
  37. public GameObject togglelist;
  38. ServerData sData;
  39. public static bool isinit;
  40. public override void updateData()
  41. {
  42. base.updateData();
  43. Debug.Log("chooseroom=2=>" + chooseroom);
  44. if (chooseroom == 0)
  45. {
  46. return;
  47. }
  48. if (sData != null)
  49. {
  50. DataManager.Instance.GetVideo((data) => {
  51. List<ServerjiguiData> jiguilist = new List<ServerjiguiData>();
  52. for (int i = 0; i < data.serverList.Count; i++)
  53. {
  54. togglelist.GetComponentsInChildren<Toggle>()[i].GetComponentInChildren<Text>().text = sData.serverList[i].name;
  55. togglelist.GetComponentsInChildren<Toggle>()[i].GetComponent<RoomToggleChoose>().id = sData.serverList[i].id;
  56. }
  57. Toggle[] ts = togglelist.GetComponentsInChildren<Toggle>();
  58. for (int i = 0; i < ts.Length; i++)
  59. {
  60. if (ts[i].GetComponent<RoomToggleChoose>().id == chooseroom)
  61. {
  62. ts[i].isOn = true;
  63. break;
  64. }
  65. }
  66. updatejiankong();
  67. });
  68. }
  69. else
  70. {
  71. DataManager.Instance.GetWSD((data) => {
  72. sData = data;
  73. List<ServerjiguiData> jiguilist = new List<ServerjiguiData>();
  74. for (int i = 0; i < data.serverList.Count; i++)
  75. {
  76. togglelist.GetComponentsInChildren<Toggle>()[i].GetComponentInChildren<Text>().text = sData.serverList[i].name;
  77. togglelist.GetComponentsInChildren<Toggle>()[i].GetComponent<RoomToggleChoose>().id = sData.serverList[i].id;
  78. }
  79. Toggle[] ts = togglelist.GetComponentsInChildren<Toggle>();
  80. for (int i = 0; i < ts.Length; i++)
  81. {
  82. if (ts[i].GetComponent<RoomToggleChoose>().id == chooseroom)
  83. {
  84. ts[i].isOn = true;
  85. break;
  86. }
  87. }
  88. if (chooseroom != 0)
  89. {
  90. updatejiankong();
  91. }
  92. // updateRoomData();
  93. });
  94. }
  95. }
  96. private void updatejiankong()
  97. {
  98. DataManager.Instance.GetVideo((data) => {
  99. for (int i = 0; i < allgame.Count; i++)
  100. {
  101. Destroy(allgame[i]);
  102. }
  103. allgame = new List<GameObject>();
  104. int jlct = 0;
  105. int jfct = 0;
  106. for (int i = 0; i < data.serverList.Count; i++)
  107. {
  108. if (data.serverList[i].id == chooseroom)
  109. {
  110. for (int j = 0; j < data.serverList[i].videolist.Count; j++)
  111. {
  112. for (int z = 0; z < data.serverList[i].videolist[j].url.Count; z++)
  113. {
  114. if (data.serverList[i].videolist[j].type == 1)
  115. {
  116. //机笼
  117. jlct++;
  118. GameObject jll = GameObject.Instantiate(jilongleft.gameObject, jilongleft.transform.parent);
  119. GameObject jlr = GameObject.Instantiate(jilongright.gameObject, jilongright.transform.parent);
  120. jll.SetActive(true);
  121. jlr.SetActive(true);
  122. jll.GetComponent<VideoLefttem>().setdata(data.serverList[i].videolist[j].url[z], jlct);
  123. jlr.GetComponent<VideoRight>().setdata(data.serverList[i].videolist[j].url[z], jlct);
  124. allgame.Add(jll);
  125. allgame.Add(jlr);
  126. }
  127. else
  128. {
  129. //机房
  130. jfct++;
  131. GameObject jfl = GameObject.Instantiate(jifangleft.gameObject, jifangleft.transform.parent);
  132. GameObject jfr = GameObject.Instantiate(jifangright.gameObject, jifangright.transform.parent);
  133. jfl.SetActive(true);
  134. jfr.SetActive(true);
  135. jfl.GetComponent<VideoLefttem>().setdata(data.serverList[i].videolist[j].url[z], jfct);
  136. jfr.GetComponent<VideoRight>().setdata(data.serverList[i].videolist[j].url[z], jfct);
  137. allgame.Add(jfl);
  138. allgame.Add(jfr);
  139. }
  140. }
  141. }
  142. }
  143. }
  144. });
  145. }
  146. public GameObject jilongleft;
  147. public GameObject jilongright;
  148. public GameObject jifangleft;
  149. public GameObject jifangright;
  150. List<GameObject> allgame = new List<GameObject>();
  151. }