BaseFilePrefabItem.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. }
  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. }
  146. public void OnPointerExit(PointerEventData eventData)
  147. {
  148. }
  149. public void OnPointerEnter(PointerEventData eventData)
  150. {
  151. }
  152. public void OnPointerDown(PointerEventData eventData)
  153. {
  154. }
  155. public void OnPointerClick(PointerEventData eventData)
  156. {
  157. if (this.fileConfig != null)
  158. {
  159. RoomFile.ClickOnPrefabAction?.Invoke(this.fileConfig);
  160. }
  161. }
  162. public void OnPointerUp(PointerEventData eventData)
  163. {
  164. }
  165. public void OnDrag(PointerEventData eventData)
  166. {
  167. }
  168. }