BaseFilePrefabItem.cs 5.2 KB

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