RoomFile.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. using System;
  2. using System.Collections.Generic;
  3. using LitJson;
  4. using SC.XR.Unity;
  5. using TMPro;
  6. using UnityEngine;
  7. using UnityEngine.UI;
  8. using static WindowsManager;
  9. public class RoomFile : SingletonMono<RoomFile>
  10. {
  11. public Toggle fileToggle;
  12. public GameObject tubiao1;
  13. public GameObject tubiao2;
  14. public GameObject allFile;
  15. public Button clearAllBtn;
  16. public GameObject msgRemind;
  17. public TextMeshProUGUI msgRemindText;
  18. public TextMeshProUGUI showfileCountText;
  19. public static int fileUpdataCount = 0;
  20. public Action<int> UpdataCountAction;
  21. public static Action<FileConfig> ClickFileItemAction;
  22. public List<FileConfig> FilePrefabConfigList = new List<FileConfig>();//是否实例化的List
  23. public static Action<FileConfig> IfFilePrefabConfigListAction;//点击知道是否实例化的监听
  24. public static Action<FileConfig> ClickOnPrefabAction;
  25. public static Action<FileConfig> HideChooseKuangAction;
  26. public static Action<FileConfig> HidefileChooseAction;
  27. public static Action SetIsOnFalse;
  28. public Transform PngJpgPoint;
  29. public Transform PrintscreenPoint;
  30. public Transform Mp4Point;
  31. public Transform PdfPoint;
  32. public Transform ModelPoint;
  33. void Awake()
  34. {
  35. UpdataCountAction += OnUpdataCount;
  36. // MQTTClient.Instance.OnCoordinate += Coordinate;
  37. }
  38. private void ReceiveSharePrintscreen(JsonData data)
  39. {
  40. if (PrintscreenList.Instance)
  41. {
  42. PrintscreenList.Instance.AddItem(data);
  43. }
  44. }
  45. private void OnUpdataCount(int num)
  46. {
  47. msgRemind.SetActive(true);
  48. msgRemindText.text = num.ToString();
  49. }
  50. private void Start()
  51. {
  52. ClickFileItemAction += ClickFileItme;
  53. fileToggle.onValueChanged.AddListener(OnFileToggleValueChange);
  54. clearAllBtn.onClick.AddListener(ClickOnClearAllBtn);
  55. ClearAllfileAction += ClearAllfile;
  56. }
  57. private void ReceiveFile(JsonData data)
  58. {
  59. FileConfig fileConfig = new FileConfig();
  60. fileConfig.PeerId = data["data"]["peerId"].ToString();
  61. fileConfig.From = data["data"]["from"].ToString();
  62. fileConfig.CreateTime = data["data"]["createTime"].ToString();
  63. fileConfig.Url = data["data"]["url"].ToString();
  64. fileConfig.Path = data["data"]["path"].ToString();
  65. fileConfig.FileName = data["data"]["fileName"].ToString();
  66. InstantFileConfig(fileConfig);
  67. }
  68. private void InstantFileConfig(FileConfig fileConfig)
  69. {
  70. if (FileList.Instance)
  71. {
  72. FileList.Instance.AddItem(fileConfig);
  73. }
  74. }
  75. void initShow()
  76. {
  77. HideClearBtn();
  78. if (FileList.Instance)
  79. {
  80. fileUpdataCount = 0;
  81. // FileList.Instance.Init(ShowRoom.Instance.fileConfiglist);
  82. }
  83. if (fileToggle)
  84. {
  85. fileToggle.isOn = true;
  86. }
  87. allFile.SetActive(true);
  88. tubiao1.SetActive(false);
  89. tubiao2.SetActive(true);
  90. msgRemind.SetActive(false);
  91. fileUpdataCount = 0;
  92. }
  93. public void ShowClearBtn()
  94. {
  95. clearAllBtn.gameObject.SetActive(true);
  96. //showfileCountText.transform.localPosition = new Vector3(15, 0, 0);
  97. }
  98. public void HideClearBtn()
  99. {
  100. clearAllBtn.gameObject.SetActive(false);
  101. //showfileCountText.transform.localPosition = new Vector3(-3, 0, 0);
  102. }
  103. private void OnFileToggleValueChange(bool isOn)
  104. {
  105. if (isOn)
  106. {
  107. allFile.SetActive(true);
  108. tubiao1.SetActive(false);
  109. tubiao2.SetActive(true);
  110. msgRemind.SetActive(false);
  111. fileUpdataCount = 0;
  112. }
  113. else
  114. {
  115. allFile.SetActive(false);
  116. tubiao1.SetActive(true);
  117. tubiao2.SetActive(false);
  118. }
  119. }
  120. public void ResetToggleValue()
  121. {
  122. if (!fileToggle.isOn)
  123. {
  124. fileToggle.isOn = true;
  125. }
  126. }
  127. private Action ClearAllfileAction;
  128. private void ClickOnClearAllBtn()
  129. {
  130. // PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Pop, RtcStrConfig.clearallFile, "确定", ClearAllfileAction);
  131. }
  132. private void ClearAllfile()
  133. {
  134. HideClearBtn();
  135. }
  136. private void ClearFileSucess(JsonData data)
  137. {
  138. if (data["data"]["code"].ToString() == "200")
  139. {
  140. ClearAllFileItem();
  141. }
  142. }
  143. private void ClearFile(JsonData data)
  144. {
  145. if (data["method"].ToString() == "clearFile")
  146. {
  147. ClearAllFileItem();
  148. }
  149. }
  150. public void ClearAllFileItem()
  151. {
  152. //if (ShowRoom.Instance && ShowRoom.Instance.fileConfiglist != null && ShowRoom.Instance.fileConfiglist.Count > 0)
  153. //{
  154. // ShowRoom.Instance.fileConfiglist.Clear();
  155. //}
  156. if (FileList.Instance)
  157. {
  158. msgRemind.SetActive(false);
  159. fileUpdataCount = 0;
  160. FileList.Instance.DestoryAll();
  161. }
  162. ClearAllFilePrefab();
  163. }
  164. public void ClearAllFilePrefab()
  165. {
  166. if (PngJpgList.Instance)
  167. {
  168. PngJpgList.Instance.DeleteAll();
  169. }
  170. if (Mp4List.Instance)
  171. {
  172. Mp4List.Instance.DeleteAll();
  173. }
  174. if (PdfList.Instance)
  175. {
  176. PdfList.Instance.DeleteAll();
  177. }
  178. //if (ModelList.Instance)
  179. //{
  180. // ModelList.Instance.DeleteAll();
  181. //}
  182. FilePrefabConfigList.Clear();
  183. }
  184. private void ClickFileItme(FileConfig fileConfig)
  185. {
  186. if (fileConfig != null)
  187. {
  188. switch (fileConfig.FileType)
  189. {
  190. case RoomFileType.png:
  191. if (PngJpgList.Instance)
  192. {
  193. PngJpgList.Instance.AddItem(fileConfig);
  194. }
  195. break;
  196. case RoomFileType.jpg:
  197. if (PngJpgList.Instance)
  198. {
  199. PngJpgList.Instance.AddItem(fileConfig);
  200. }
  201. break;
  202. case RoomFileType.jpeg:
  203. if (PngJpgList.Instance)
  204. {
  205. PngJpgList.Instance.AddItem(fileConfig);
  206. }
  207. break;
  208. case RoomFileType.mp4:
  209. if (Mp4List.Instance)
  210. {
  211. Mp4List.Instance.AddItem(fileConfig);
  212. }
  213. break;
  214. case RoomFileType.zip:
  215. //if (ModelList.Instance)
  216. //{
  217. // ModelList.Instance.AddItem(fileConfig);
  218. //}
  219. break;
  220. case RoomFileType.pdf:
  221. if (PdfList.Instance)
  222. {
  223. PdfList.Instance.AddItem(fileConfig);
  224. }
  225. break;
  226. }
  227. }
  228. }
  229. private void OnDestroy()
  230. {
  231. ClickFileItemAction -= ClickFileItme;
  232. UpdataCountAction -= OnUpdataCount;
  233. ClearAllfileAction -= ClearAllfile;
  234. }
  235. }