BaseFilePrefabItem.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using LitJson;
  5. using TMPro;
  6. using UnityEngine;
  7. using UnityEngine.EventSystems;
  8. using UnityEngine.UI;
  9. using XRTool.Util;
  10. public class BaseFilePrefabItem : MonoBehaviour,IPointerHandler
  11. {
  12. public Text nameText;
  13. protected FileConfig fileConfig;
  14. public SCButton deleteBtn;
  15. public SCButton hideBtn;
  16. public GameObject ChooseKuang;
  17. private BoundingBox boundBox;
  18. protected virtual void Start()
  19. {
  20. //RoomFile.OnFilePrefabListAction += DeletFilePrefab;
  21. deleteBtn.onClick.AddListener(ClickOnDeleteBtn);
  22. hideBtn.onClick.AddListener(ClickOnHideBtn);
  23. //WSHandler.Rtc.OnDeleteFileSucess += DeleteFileSucess;
  24. //WSHandler.Rtc.OnDeleteFile += NotifyDeleteFile;
  25. }
  26. private void ClickOnHideBtn()
  27. {
  28. if (this.fileConfig != null && this.fileConfig.FileType == RoomFileType.mp4)
  29. return;
  30. if (RoomFile.Instance.FilePrefabConfigList.Contains(this.fileConfig))
  31. {
  32. RoomFile.Instance.FilePrefabConfigList.Remove(this.fileConfig);
  33. }
  34. this.gameObject.SetActive(false);
  35. if (this.fileConfig != null)
  36. {
  37. RoomFile.HidefileChooseAction?.Invoke(this.fileConfig);
  38. }
  39. }
  40. private void NotifyDeleteFile(JsonData data)
  41. {
  42. if (this.fileConfig != null && data["data"]["path"].ToString() == this.fileConfig.Path)
  43. {
  44. if (RoomFile.Instance.FilePrefabConfigList.Contains(this.fileConfig))
  45. {
  46. RoomFile.Instance.FilePrefabConfigList.Remove(this.fileConfig);
  47. }
  48. Destroy(this.gameObject);
  49. }
  50. }
  51. private void ClickOnDeleteBtn()
  52. {
  53. if (this.fileConfig != null)
  54. {
  55. deleteBtn.enabled = false;
  56. WSHandler.Rtc.deleteFile(this.fileConfig.Path);
  57. }
  58. }
  59. private void DeleteFileSucess(JsonData data)
  60. {
  61. if (data["data"]["code"].ToString() == "200")
  62. {
  63. string path = data["data"]["data"]["path"].ToString();
  64. if (!string.IsNullOrEmpty(path))
  65. {
  66. if (this.fileConfig != null && this.fileConfig.Path == path)
  67. {
  68. //RoomFile.OnFileListAction?.Invoke(this.fileConfig);
  69. if (RoomFile.Instance.FilePrefabConfigList.Contains(this.fileConfig))
  70. {
  71. RoomFile.Instance.FilePrefabConfigList.Remove(this.fileConfig);
  72. }
  73. Destroy(this.gameObject);
  74. }
  75. }
  76. }
  77. }
  78. private void OnAction(FileConfig fileConfig)
  79. {
  80. if (this.fileConfig != null && this.fileConfig == fileConfig)
  81. {
  82. //gameObject.SetActive(true);
  83. ChooseKuang.SetActive(true);
  84. }
  85. }
  86. private void OnHideAction(FileConfig fileConfig)
  87. {
  88. if (this.fileConfig != null && this.fileConfig == fileConfig)
  89. {
  90. ChooseKuang.SetActive(false);
  91. }
  92. }
  93. public virtual void Init(FileConfig fileConfig)
  94. {
  95. if (RoomMainInfo.isCreator == "0")
  96. {
  97. deleteBtn.gameObject.SetActive(true);
  98. }
  99. else
  100. {
  101. deleteBtn.gameObject.SetActive(false);
  102. }
  103. this.fileConfig = fileConfig;
  104. nameText.text = fileConfig.FileName;
  105. RoomFile.IfFilePrefabConfigListAction += OnAction;
  106. RoomFile.HideChooseKuangAction += OnHideAction;
  107. if (!boundBox)
  108. {
  109. boundBox = GetComponent<BoundingBox>();
  110. if (!boundBox)
  111. {
  112. UnityLog.LogError(gameObject.name + "this is no XBoundingBox");
  113. }
  114. else
  115. {
  116. boundBox.ScaleStopped.AddListener(OnScaleStopped);
  117. boundBox.RotateStarted.AddListener(OnRotateStarted);
  118. boundBox.ScaleStarted.AddListener(OnScaleStarted);
  119. }
  120. }
  121. }
  122. public virtual void OnRotateStarted()
  123. {
  124. if (this.fileConfig != null)
  125. {
  126. RoomFile.ClickOnPrefabAction?.Invoke(this.fileConfig);
  127. }
  128. }
  129. public virtual void OnScaleStarted()
  130. {
  131. if (this.fileConfig != null)
  132. {
  133. RoomFile.ClickOnPrefabAction?.Invoke(this.fileConfig);
  134. }
  135. }
  136. public virtual void OnScaleStopped()
  137. {
  138. if (transform.localScale.x < 1f)
  139. {
  140. transform.localScale = Vector3.one;
  141. }
  142. }
  143. protected virtual void OnDestroy()
  144. {
  145. RoomFile.IfFilePrefabConfigListAction -= OnAction;
  146. //RoomFile.OnFilePrefabListAction -= DeletFilePrefab;
  147. RoomFile.HideChooseKuangAction -= OnHideAction;
  148. WSHandler.Rtc.OnDeleteFileSucess -= DeleteFileSucess;
  149. WSHandler.Rtc.OnDeleteFile -= NotifyDeleteFile;
  150. }
  151. public void OnPointerExit(PointerEventData eventData)
  152. {
  153. }
  154. public void OnPointerEnter(PointerEventData eventData)
  155. {
  156. }
  157. public void OnPointerDown(PointerEventData eventData)
  158. {
  159. }
  160. public void OnPointerClick(PointerEventData eventData)
  161. {
  162. if (this.fileConfig != null)
  163. {
  164. RoomFile.ClickOnPrefabAction?.Invoke(this.fileConfig);
  165. }
  166. }
  167. public void OnPointerUp(PointerEventData eventData)
  168. {
  169. }
  170. public void OnDrag(PointerEventData eventData)
  171. {
  172. }
  173. }