RoomFile.cs 8.7 KB

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