RoomFile.cs 9.5 KB

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