RoomFile.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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 ScenesManager;
  9. public class RoomFile : RemoteSingleton<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. public override void Awake()
  34. {
  35. base.Awake();
  36. WSHandler.Rtc.OnReceiveFile += ReceiveFile;
  37. UpdataCountAction += OnUpdataCount;
  38. WSHandler.Rtc.OnClearFile += ClearFile;
  39. WSHandler.Rtc.OnCoordinate += Coordinate;
  40. WSHandler.Rtc.OnSharePrintscreen += ReceiveSharePrintscreen;
  41. MQTTClient.Instance.OnCoordinate += Coordinate;
  42. }
  43. private void ReceiveSharePrintscreen(JsonData data)
  44. {
  45. if (PrintscreenList.Instance)
  46. {
  47. PrintscreenList.Instance.AddItem(data);
  48. }
  49. }
  50. private void OnUpdataCount(int num)
  51. {
  52. msgRemind.SetActive(true);
  53. msgRemindText.text = num.ToString();
  54. }
  55. private void Start()
  56. {
  57. ClickFileItemAction += ClickFileItme;
  58. fileToggle.onValueChanged.AddListener(OnFileToggleValueChange);
  59. clearAllBtn.onClick.AddListener(ClickOnClearAllBtn);
  60. ClearAllfileAction += ClearAllfile;
  61. WSHandler.Rtc.OnClearFileSucess += ClearFileSucess;
  62. }
  63. private void ReceiveFile(JsonData data)
  64. {
  65. FileConfig fileConfig = new FileConfig();
  66. fileConfig.PeerId = data["data"]["peerId"].ToString();
  67. fileConfig.From = data["data"]["from"].ToString();
  68. fileConfig.CreateTime = data["data"]["createTime"].ToString();
  69. fileConfig.Url = data["data"]["url"].ToString();
  70. fileConfig.Path = data["data"]["path"].ToString();
  71. fileConfig.FileName = data["data"]["fileName"].ToString();
  72. InstantFileConfig(fileConfig);
  73. }
  74. private void InstantFileConfig(FileConfig fileConfig)
  75. {
  76. if (FileList.Instance)
  77. {
  78. FileList.Instance.AddItem(fileConfig);
  79. }
  80. }
  81. public override void initShow()
  82. {
  83. base.initShow();
  84. HideClearBtn();
  85. if (FileList.Instance)
  86. {
  87. fileUpdataCount = 0;
  88. FileList.Instance.Init(ShowRoom.Instance.fileConfiglist);
  89. }
  90. if (fileToggle)
  91. {
  92. fileToggle.isOn = true;
  93. }
  94. allFile.SetActive(true);
  95. tubiao1.SetActive(false);
  96. tubiao2.SetActive(true);
  97. msgRemind.SetActive(false);
  98. fileUpdataCount = 0;
  99. }
  100. public void ShowClearBtn()
  101. {
  102. clearAllBtn.gameObject.SetActive(true);
  103. //showfileCountText.transform.localPosition = new Vector3(15, 0, 0);
  104. }
  105. public void HideClearBtn()
  106. {
  107. clearAllBtn.gameObject.SetActive(false);
  108. //showfileCountText.transform.localPosition = new Vector3(-3, 0, 0);
  109. }
  110. private void OnFileToggleValueChange(bool isOn)
  111. {
  112. if (isOn)
  113. {
  114. allFile.SetActive(true);
  115. tubiao1.SetActive(false);
  116. tubiao2.SetActive(true);
  117. msgRemind.SetActive(false);
  118. fileUpdataCount = 0;
  119. }
  120. else
  121. {
  122. allFile.SetActive(false);
  123. tubiao1.SetActive(true);
  124. tubiao2.SetActive(false);
  125. }
  126. }
  127. public void ResetToggleValue()
  128. {
  129. if (!fileToggle.isOn)
  130. {
  131. fileToggle.isOn = true;
  132. }
  133. }
  134. private Action ClearAllfileAction;
  135. private void ClickOnClearAllBtn()
  136. {
  137. PopUpInfo.Instance.showPublic(PopUpInfo.PopType.Pop, RtcStrConfig.clearallFile, "确定", ClearAllfileAction);
  138. }
  139. private void ClearAllfile()
  140. {
  141. HideClearBtn();
  142. WSHandler.Rtc.clearFile();
  143. }
  144. private void ClearFileSucess(JsonData data)
  145. {
  146. if (data["data"]["code"].ToString() == "200")
  147. {
  148. ClearAllFileItem();
  149. }
  150. }
  151. private void ClearFile(JsonData data)
  152. {
  153. if (data["method"].ToString() == "clearFile")
  154. {
  155. ClearAllFileItem();
  156. }
  157. }
  158. public void ClearAllFileItem()
  159. {
  160. if (ShowRoom.Instance && ShowRoom.Instance.fileConfiglist != null && ShowRoom.Instance.fileConfiglist.Count > 0)
  161. {
  162. ShowRoom.Instance.fileConfiglist.Clear();
  163. }
  164. if (FileList.Instance)
  165. {
  166. msgRemind.SetActive(false);
  167. fileUpdataCount = 0;
  168. FileList.Instance.DestoryAll();
  169. }
  170. ClearAllFilePrefab();
  171. }
  172. public void ClearAllFilePrefab()
  173. {
  174. if (PngJpgList.Instance)
  175. {
  176. PngJpgList.Instance.DeleteAll();
  177. }
  178. if (Mp4List.Instance)
  179. {
  180. Mp4List.Instance.DeleteAll();
  181. }
  182. if (PdfList.Instance)
  183. {
  184. PdfList.Instance.DeleteAll();
  185. }
  186. if (ModelList.Instance)
  187. {
  188. ModelList.Instance.DeleteAll();
  189. }
  190. FilePrefabConfigList.Clear();
  191. }
  192. private void ClickFileItme(FileConfig fileConfig)
  193. {
  194. if (fileConfig != null)
  195. {
  196. switch (fileConfig.FileType)
  197. {
  198. case RoomFileType.png:
  199. if (PngJpgList.Instance)
  200. {
  201. PngJpgList.Instance.AddItem(fileConfig);
  202. }
  203. break;
  204. case RoomFileType.jpg:
  205. if (PngJpgList.Instance)
  206. {
  207. PngJpgList.Instance.AddItem(fileConfig);
  208. }
  209. break;
  210. case RoomFileType.jpeg:
  211. if (PngJpgList.Instance)
  212. {
  213. PngJpgList.Instance.AddItem(fileConfig);
  214. }
  215. break;
  216. case RoomFileType.mp4:
  217. if (Mp4List.Instance)
  218. {
  219. Mp4List.Instance.AddItem(fileConfig);
  220. }
  221. break;
  222. case RoomFileType.zip:
  223. if (ModelList.Instance)
  224. {
  225. ModelList.Instance.AddItem(fileConfig);
  226. }
  227. break;
  228. case RoomFileType.pdf:
  229. if (PdfList.Instance)
  230. {
  231. PdfList.Instance.AddItem(fileConfig);
  232. }
  233. break;
  234. }
  235. }
  236. }
  237. private void Coordinate(JsonData data)
  238. {
  239. string action = data["data"]["action"].ToString();
  240. switch (action)
  241. {
  242. case "10000":
  243. if (ArrowList.Instance)
  244. {
  245. float Valuex = float.Parse(data["data"]["params"]["x"].ToString());
  246. float Valuey = float.Parse(data["data"]["params"]["y"].ToString());
  247. ArrowList.Instance.AddArrow(Valuex, Valuey);
  248. }
  249. break;
  250. case "10001":
  251. if (RemoteRtc.Instance)
  252. {
  253. float Valuex = float.Parse(data["data"]["params"]["x"].ToString());
  254. float Valuey = float.Parse(data["data"]["params"]["y"].ToString());
  255. //RemoteRtc.Instance.webTex.autoFocusPoint = new Vector2(Valuex, 1 - Valuey);
  256. //TextMesh textMesh = obj.transform.Find("Text").GetComponent<TextMesh>();
  257. //textMesh.text = "**" + RemoteRtc.Instance.webTex.autoFocusPoint;
  258. }
  259. break;
  260. }
  261. }
  262. private void OnDestroy()
  263. {
  264. ClickFileItemAction -= ClickFileItme;
  265. WSHandler.Rtc.OnReceiveFile -= ReceiveFile;
  266. UpdataCountAction -= OnUpdataCount;
  267. ClearAllfileAction -= ClearAllfile;
  268. WSHandler.Rtc.OnClearFileSucess -= ClearFileSucess;
  269. WSHandler.Rtc.OnClearFile -= ClearFile;
  270. WSHandler.Rtc.OnCoordinate -= Coordinate;
  271. WSHandler.Rtc.OnSharePrintscreen -= ReceiveSharePrintscreen;
  272. MQTTClient.Instance.OnCoordinate -= Coordinate;
  273. }
  274. }