RoomFile.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. Debug.Log("DGJ ====> ClearAllFileItem()");
  170. if (ShowRoom.Instance && ShowRoom.Instance.fileConfiglist != null && ShowRoom.Instance.fileConfiglist.Count > 0)
  171. {
  172. ShowRoom.Instance.fileConfiglist.Clear();
  173. }
  174. if (FileList.Instance)
  175. {
  176. msgRemind.SetActive(false);
  177. fileUpdataCount = 0;
  178. FileList.Instance.DestoryAll();
  179. }
  180. ClearAllFilePrefab();
  181. }
  182. public void ClearAllFilePrefab()
  183. {
  184. if (PngJpgList.Instance)
  185. {
  186. PngJpgList.Instance.DeleteAll();
  187. }
  188. if (Mp4List.Instance)
  189. {
  190. Mp4List.Instance.DeleteAll();
  191. }
  192. if (PdfList.Instance)
  193. {
  194. PdfList.Instance.DeleteAll();
  195. }
  196. if (ModelList.Instance)
  197. {
  198. ModelList.Instance.DeleteAll();
  199. }
  200. FilePrefabConfigList.Clear();
  201. fileIndex = 0;
  202. }
  203. private void ClickFileItme(FileConfig fileConfig)
  204. {
  205. if (fileConfig != null)
  206. {
  207. switch (fileConfig.FileType)
  208. {
  209. case RoomFileType.png:
  210. if (PngJpgList.Instance)
  211. {
  212. PngJpgList.Instance.AddItem(fileConfig);
  213. }
  214. break;
  215. case RoomFileType.jpg:
  216. if (PngJpgList.Instance)
  217. {
  218. PngJpgList.Instance.AddItem(fileConfig);
  219. }
  220. break;
  221. case RoomFileType.jpeg:
  222. if (PngJpgList.Instance)
  223. {
  224. PngJpgList.Instance.AddItem(fileConfig);
  225. }
  226. break;
  227. case RoomFileType.mp4:
  228. if (Mp4List.Instance)
  229. {
  230. Mp4List.Instance.AddItem(fileConfig);
  231. }
  232. break;
  233. case RoomFileType.zip:
  234. if (ModelList.Instance)
  235. {
  236. ModelList.Instance.AddItem(fileConfig);
  237. }
  238. break;
  239. case RoomFileType.pdf:
  240. if (PdfList.Instance)
  241. {
  242. PdfList.Instance.AddItem(fileConfig);
  243. }
  244. break;
  245. }
  246. fileIndex++;
  247. }
  248. }
  249. public Transform GetFilePos()
  250. {
  251. if (isOne)
  252. {
  253. isOne = false;
  254. if (filePos.localEulerAngles.y > 90)
  255. filePos.localEulerAngles = new Vector3(0, -15, 0);
  256. filePos.localEulerAngles += new Vector3(0, 30, 0);
  257. }
  258. return filePosPoint;
  259. }
  260. private void Coordinate(JsonData data)
  261. {
  262. string action = data["data"]["action"].ToString();
  263. switch (action)
  264. {
  265. case "10000":
  266. if (ArrowList.Instance)
  267. {
  268. float Valuex = float.Parse(data["data"]["params"]["x"].ToString());
  269. float Valuey = float.Parse(data["data"]["params"]["y"].ToString());
  270. ArrowList.Instance.AddArrow(Valuex, Valuey);
  271. }
  272. break;
  273. case "10001":
  274. if (RemoteRtc.Instance)
  275. {
  276. float Valuex = float.Parse(data["data"]["params"]["x"].ToString());
  277. float Valuey = float.Parse(data["data"]["params"]["y"].ToString());
  278. //RemoteRtc.Instance.webTex.autoFocusPoint = new Vector2(Valuex, 1 - Valuey);
  279. //TextMesh textMesh = obj.transform.Find("Text").GetComponent<TextMesh>();
  280. //textMesh.text = "**" + RemoteRtc.Instance.webTex.autoFocusPoint;
  281. }
  282. break;
  283. }
  284. }
  285. private void OnDestroy()
  286. {
  287. ClickFileItemAction -= ClickFileItme;
  288. WSHandler.Rtc.OnReceiveFile -= ReceiveFile;
  289. UpdataCountAction -= OnUpdataCount;
  290. ClearAllfileAction -= ClearAllfile;
  291. WSHandler.Rtc.OnClearFileSucess -= ClearFileSucess;
  292. WSHandler.Rtc.OnClearFile -= ClearFile;
  293. WSHandler.Rtc.OnCoordinate -= Coordinate;
  294. WSHandler.Rtc.OnSharePrintscreen -= ReceiveSharePrintscreen;
  295. MQTTClient.Instance.OnCoordinate -= Coordinate;
  296. }
  297. }