ZiYuanKuDlg.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. using SC.XR.Unity;
  2. using ShadowStudio.Model;
  3. using Studio.Scripts;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using UnityEngine;
  8. using UnityEngine.UI;
  9. using XRTool.Util;
  10. using XRTool.WorldUI;
  11. namespace ShadowStudio.UI
  12. {
  13. [RequireComponent(typeof(WorldDlg))]
  14. public class ZiYuanKuDlg : UnitySingleton<ZiYuanKuDlg>
  15. {
  16. private Transform fenleiAllTogglesTran;
  17. private ToggleGroup fenleiAllTogglesGroup;
  18. private ZiYuanFileList ziYuanFileList;
  19. private Transform wuwenjian;
  20. private Button closeBtn;
  21. private Button loadBtn;
  22. private Button canelBtn;
  23. private SCInputField searchInputField;
  24. private Button searchBtn;
  25. private Button clearBtn;
  26. public List<ArtInfo> NeedLoadartInfos;
  27. public Action<int> ShowOrHideGrayImage;
  28. public Action CanelLoadAction;
  29. protected override void Awake()
  30. {
  31. base.Awake();
  32. HomeProxy.Instance.SearchArtListAction += SearchArtList;
  33. HomeProxy.Instance.NoArtReturnAction += ShowNoArt;
  34. NeedLoadartInfos = new List<ArtInfo>();
  35. }
  36. void Start()
  37. {
  38. WorldDlg dlg = GetComponent<WorldDlg>();
  39. ziYuanFileList = dlg.GetBreadthChild<ZiYuanFileList>("ItemFileList");
  40. wuwenjian = dlg.GetBreadthChild<Transform>("Wuwenjian");
  41. fenleiAllTogglesTran = dlg.GetBreadthChild<Transform>("FenleiAllToggles");
  42. fenleiAllTogglesGroup = dlg.GetBreadthChild<ToggleGroup>("FenleiAllToggles");
  43. closeBtn = dlg.GetBreadthChild<Button>("CloseBtn");
  44. closeBtn.onClick.AddListener(ClickOnClose);
  45. loadBtn = dlg.GetBreadthChild<Button>("LoadBtn");
  46. loadBtn.onClick.AddListener(ClickOnLoad);
  47. canelBtn = dlg.GetBreadthChild<Button>("CanelBtn");
  48. canelBtn.onClick.AddListener(ClickOnCanel);
  49. searchBtn = dlg.GetBreadthChild<Button>("SearchBtn");
  50. searchBtn.onClick.AddListener(ClickOnSearch);
  51. clearBtn = dlg.GetBreadthChild<Button>("ClearBtn");
  52. clearBtn.onClick.AddListener(ClickOnClear);
  53. searchInputField = dlg.GetBreadthChild<SCInputField>("SearchInputField");
  54. //searchInputField.onEndEdit.AddListener(SearchInputEndEdit);
  55. searchInputField.onValueChanged.AddListener(SearchInputValueChanged);
  56. Toggle[] toggles = fenleiAllTogglesTran.GetComponentsInChildren<Toggle>(true);
  57. for (int i = 0; i < toggles.Length; i++)
  58. {
  59. Toggle toggle = toggles[i];
  60. toggles[i].onValueChanged.AddListener((bool isOn) => { OnToggle(isOn, toggle); });
  61. if (i == 0)
  62. {
  63. OnToggle(true, toggles[i]);
  64. }
  65. }
  66. }
  67. private void ClickOnClear()
  68. {
  69. searchInputField.text = "";
  70. clearBtn.gameObject.SetActive(false);
  71. GetToggleOn();
  72. }
  73. private void SearchInputValueChanged(string searchInput)
  74. {
  75. if (searchInput != "")
  76. {
  77. clearBtn.gameObject.SetActive(true);
  78. }
  79. else
  80. {
  81. ClickOnClear();
  82. }
  83. }
  84. private void ClickOnSearch()
  85. {
  86. if (searchInputField.text != "")
  87. {
  88. if (searchInputField.text.Trim() != string.Empty)
  89. {
  90. GetToggleOn();
  91. }
  92. else
  93. {
  94. ConsoleDlg.Instance.ShowTipPop("搜索内容不能全为空格");
  95. }
  96. }
  97. else
  98. {
  99. ConsoleDlg.Instance.ShowTipPop("搜索内容不能为空");
  100. }
  101. }
  102. public void GetToggleOn()
  103. {
  104. Toggle temptoggle = null;
  105. foreach (var toggle in fenleiAllTogglesGroup.ActiveToggles())
  106. {
  107. temptoggle = toggle;
  108. }
  109. if (temptoggle != null)
  110. {
  111. OnToggle(true, temptoggle);
  112. }
  113. }
  114. private void ClickOnCanel()
  115. {
  116. NeedLoadartInfos.Clear();
  117. CanelLoadAction?.Invoke();
  118. }
  119. private void ClickOnLoad()
  120. {
  121. if (NeedLoadartInfos.Count > 0)
  122. {
  123. for (int i = 0; i < NeedLoadartInfos.Count; i++)
  124. {
  125. WSHandler.Room.CreateGood(NeedLoadartInfos[i].AID, NeedLoadartInfos[i].ArtId, NeedLoadartInfos[i].ArtName, UnityUtil.ArtTransferInfo(NeedLoadartInfos[i], i), "", ShowViewMgr.Instance.roomId);
  126. }
  127. if (NeedLoadartInfos.Count == 1)
  128. {
  129. ConsoleDlg.IsOne = true;
  130. }
  131. else
  132. {
  133. ConsoleDlg.IsOne = false;
  134. }
  135. ClickOnClose();
  136. }
  137. }
  138. private void ClickOnClose()
  139. {
  140. if (ConsoleDlg.Instance)
  141. {
  142. ConsoleDlg.Instance.SetClose();
  143. }
  144. }
  145. private void OnDisable()
  146. {
  147. ClickOnCanel();
  148. }
  149. private void OnToggle(bool isOn, Toggle toggle)
  150. {
  151. if (isOn)
  152. {
  153. switch (toggle.name)
  154. {
  155. case "AllToggle":
  156. RequestSearch(-1);
  157. break;
  158. case "Model2DToggle":
  159. RequestSearch(5);
  160. break;
  161. case "Model3DToggle":
  162. RequestSearch(0);
  163. break;
  164. case "PicToggle":
  165. RequestSearch(1);
  166. break;
  167. case "MP4Toggle":
  168. RequestSearch(3);
  169. break;
  170. case "ProjectToggle":
  171. SearchArtList(null);
  172. break;
  173. }
  174. }
  175. }
  176. public void RequestSearch(int artType, int fileType = 2)
  177. {
  178. NeedLoadartInfos.Clear();
  179. HomeProxy.Instance.RequestSearchArtList(artType, fileType, searchInputField.text);
  180. }
  181. private void SearchArtList(List<ArtInfo> ArtInfoList)
  182. {
  183. if (gameObject.activeSelf)
  184. {
  185. wuwenjian.gameObject.SetActive(false);
  186. ziYuanFileList.DestoryAll();
  187. if (ArtInfoList != null && ArtInfoList.Count > 0)
  188. {
  189. for (int i = 0; i < ArtInfoList.Count; i++)
  190. {
  191. if (ziYuanFileList)
  192. {
  193. ziYuanFileList.AddFileItem(ArtInfoList[i]);
  194. }
  195. }
  196. }
  197. else
  198. {
  199. wuwenjian.gameObject.SetActive(true);
  200. }
  201. }
  202. }
  203. private void ShowNoArt()
  204. {
  205. if (gameObject.activeSelf)
  206. {
  207. ziYuanFileList.DestoryAll();
  208. wuwenjian.gameObject.SetActive(true);
  209. }
  210. }
  211. protected override void OnDestroy()
  212. {
  213. base.OnDestroy();
  214. if (HomeProxy.Instance)
  215. {
  216. HomeProxy.Instance.SearchArtListAction -= SearchArtList;
  217. HomeProxy.Instance.NoArtReturnAction -= ShowNoArt;
  218. }
  219. }
  220. }
  221. }