BaseFilePrefabItem.cs 5.2 KB

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