GCZLLayer.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Runtime.InteropServices;
  5. using UnityEngine;
  6. using UnityAsync;
  7. using WaitUntil = UnityAsync.WaitUntil;
  8. using System.Threading.Tasks;
  9. using UnityEngine.UI;
  10. public class GCZLLayer : MonoBehaviour
  11. {
  12. public GameObject classPrefab;
  13. public GameObject informationPrefab;
  14. public RectTransform classContent;
  15. public RectTransform informationContent;
  16. public InputField informationSearchInput;
  17. public YZTLayer zTLayer;
  18. public Sprite[] sprites;
  19. private List<GameObject> informations = new List<GameObject>();
  20. private GameObject lastClassBtn;
  21. private int currentClass = -99;
  22. private GameObject InfoPanel;
  23. private Button InfoExitButton;
  24. private Button Info_DetailButton;
  25. private Text InfoTitleText;
  26. private Text InfoClassText;
  27. private Text InfoNoText;
  28. private Text InfoDayText;
  29. private RawImage InfoFM;
  30. private GameObject DetailPanel;
  31. private Button DetailExitButton;
  32. private Text DetailTitleText;
  33. private LayerUnitData currentData;
  34. //private Button OpenAniButton;
  35. //private Button CloseAniButton;
  36. private Button detail_modelButton;
  37. private Button detail_designButton;
  38. private Button detail_photoButton;
  39. private Button detail_videoButton;
  40. private CanvasGroup detail_modelCG;
  41. private CanvasGroup detail_designCG;
  42. private CanvasGroup detail_photoCG;
  43. private CanvasGroup detail_videoCG;
  44. private RawImage showFrame;
  45. private Button lastPhotoButton;
  46. private Button nextPhotoButton;
  47. public RenderTexture modelRT;
  48. public string[] BY_PhotoUrl;
  49. public string[] TK_PhotoUrl;
  50. public int photoIndex;
  51. public string[] BY_PdfUrl;
  52. public string[] TK_PdfUrl;
  53. public int pdfIndex;
  54. public string[] BY_PdfDownloadUrl;
  55. public string[] TK_PdfDownloadUrl;
  56. private Button downloadPdfButton;
  57. private int showTypeIndex = 0;
  58. [DllImport("__Internal")]
  59. private static extern void OpenNewWebsite(string str);
  60. private void Awake()
  61. {
  62. InfoPanel = this.transform.Find("InfoPanel").gameObject;
  63. InfoTitleText = InfoPanel.transform.Find("Title").GetComponent<Text>();
  64. InfoClassText = InfoPanel.transform.Find("Class").GetComponent<Text>();
  65. InfoNoText = InfoPanel.transform.Find("No").GetComponent<Text>();
  66. InfoDayText = InfoPanel.transform.Find("Day").GetComponent<Text>();
  67. InfoFM = InfoPanel.transform.Find("fm").GetComponent<RawImage>();
  68. InfoExitButton = InfoPanel.transform.Find("CloseButton").GetComponent<Button>();
  69. InfoExitButton.onClick.AddListener(() => { InfoPanel.SetActive(false); });
  70. Info_DetailButton = InfoPanel.transform.Find("MoreButton").GetComponent<Button>();
  71. Info_DetailButton.onClick.AddListener(() =>
  72. {
  73. DetailTitleText.text = currentData.name;
  74. // OpenAniButton.gameObject.SetActive(currentData.namePri.Equals("BuYuan") ||
  75. // currentData.namePri.Equals("TaoKou"));
  76. // CloseAniButton.gameObject.SetActive(currentData.namePri.Equals("BuYuan") ||
  77. // currentData.namePri.Equals("TaoKou"));
  78. ModelCameraCtrl._Instance.SetCameraActive(true);
  79. ResetDetailPanel();
  80. DetailPanel.SetActive(true);
  81. });
  82. DetailPanel = this.transform.Find("DetailPanel").gameObject;
  83. DetailTitleText = DetailPanel.transform.Find("Title").GetComponent<Text>();
  84. DetailExitButton = DetailPanel.transform.Find("CloseButton").GetComponent<Button>();
  85. DetailExitButton.onClick.AddListener(() =>
  86. {
  87. DetailPanel.SetActive(false);
  88. ModelCameraCtrl._Instance.SetCameraActive(false);
  89. });
  90. detail_modelButton = DetailPanel.transform.Find("ModelButton").GetComponent<Button>();
  91. detail_designButton = DetailPanel.transform.Find("DesignButton").GetComponent<Button>();
  92. detail_photoButton = DetailPanel.transform.Find("PhotoButton").GetComponent<Button>();
  93. detail_videoButton = DetailPanel.transform.Find("VideoButton").GetComponent<Button>();
  94. detail_modelCG = detail_modelButton.GetComponent<CanvasGroup>();
  95. detail_designCG = detail_designButton.GetComponent<CanvasGroup>();
  96. detail_photoCG = detail_photoButton.GetComponent<CanvasGroup>();
  97. detail_videoCG = detail_videoButton.GetComponent<CanvasGroup>();
  98. detail_modelButton.onClick.AddListener(() => { DetailShowType(0); });
  99. detail_designButton.onClick.AddListener(() => { DetailShowType(1); });
  100. detail_photoButton.onClick.AddListener(() => { DetailShowType(2); });
  101. detail_videoButton.onClick.AddListener(() => { DetailShowType(3); });
  102. showFrame = DetailPanel.transform.Find("ShowFrame").GetComponent<RawImage>();
  103. showFrame.texture = modelRT;
  104. lastPhotoButton = DetailPanel.transform.Find("LastPhotoButton").GetComponent<Button>();
  105. lastPhotoButton.onClick.AddListener(()=>
  106. {
  107. switch (showTypeIndex)
  108. {
  109. case 1:
  110. ChangePDF((-1));
  111. break;
  112. case 2:
  113. ChangePhoto(-1);
  114. break;
  115. }
  116. });
  117. nextPhotoButton = DetailPanel.transform.Find("NextPhotoButton").GetComponent<Button>();
  118. nextPhotoButton.onClick.AddListener(()=>
  119. {
  120. switch (showTypeIndex)
  121. {
  122. case 1:
  123. ChangePDF((1));
  124. break;
  125. case 2:
  126. ChangePhoto(1);
  127. break;
  128. }
  129. });
  130. downloadPdfButton = DetailPanel.transform.Find("DownButton").GetComponent<Button>();
  131. downloadPdfButton.onClick.AddListener(DownLoadPDF);
  132. // OpenAniButton = DetailPanel.transform.Find("OpenAniButton").GetComponent<Button>();
  133. // OpenAniButton.onClick.AddListener(() =>
  134. // {
  135. // float[] openValues=new float[1];
  136. // if (currentData.namePri.Equals("BuYuan"))
  137. // {
  138. // openValues=new float[GlobalData.buYuanSensorData.data.Count];
  139. // for (int i = 0; i < openValues.Length; i++)
  140. // {
  141. // openValues[i] = GlobalData.buYuanSensorData.data[i].opening_degree*0.01f;
  142. // }
  143. // }
  144. // if (currentData.namePri.Equals("TaoKou"))
  145. // {
  146. // openValues=new float[GlobalData.taoKouSensorData.data.Count];
  147. // for (int i = 0; i < openValues.Length; i++)
  148. // {
  149. // openValues[i] = GlobalData.taoKouSensorData.data[i].opening_degree*0.01f;
  150. // }
  151. // }
  152. // ActionInstance._Instance.ModelAni_On?.Invoke(openValues);
  153. // });
  154. // CloseAniButton = DetailPanel.transform.Find("CloseAniButton").GetComponent<Button>();
  155. // CloseAniButton.onClick.AddListener(() => { ActionInstance._Instance.ModelAni_Off?.Invoke(); });
  156. InfoPanel.SetActive(false);
  157. DetailPanel.SetActive(false);
  158. }
  159. // Start is called before the first frame update
  160. async void Start()
  161. {
  162. await InitData();
  163. //StaticLod.instance.OnFoucusStatic(0);
  164. CameraManager.SwitchCamera(0);
  165. InitButton();
  166. InitInformation(0);
  167. informationSearchInput.onValueChanged.AddListener(SearchInformationItem);
  168. }
  169. void InitButton()
  170. {
  171. for (int i = 0; i < zTLayer.layerDatas.Length; i++)
  172. {
  173. string name = zTLayer.layerDatas[i].layerName;
  174. int temp = i;
  175. GameObject obj = Instantiate(classPrefab);
  176. obj.transform.SetParent(classContent);
  177. obj.GetComponentInChildren<Text>().text = name;
  178. obj.transform.localScale = Vector3.one;
  179. if (i == 0)
  180. {
  181. obj.GetComponent<Image>().sprite = sprites[0];
  182. lastClassBtn = obj;
  183. }
  184. else
  185. {
  186. obj.GetComponent<Image>().sprite = sprites[1];
  187. }
  188. obj.GetComponent<Button>().onClick.AddListener(() =>
  189. {
  190. InitInformation(temp);
  191. lastClassBtn.GetComponent<Image>().sprite = sprites[1];
  192. obj.GetComponent<Image>().sprite = sprites[0];
  193. lastClassBtn = obj;
  194. });
  195. }
  196. }
  197. void InitInformation(int index)
  198. {
  199. if (currentClass == index) return;
  200. for (int i = informations.Count - 1; i >= 0; i--)
  201. {
  202. Destroy(informations[i]);
  203. }
  204. informations.Clear();
  205. currentClass = index;
  206. if (currentClass == 0)
  207. {
  208. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  209. {
  210. if (GlobalData.layerUnitDatas[i].special == "1")
  211. {
  212. GameObject obj = Instantiate(informationPrefab);
  213. string realName = GlobalData.layerUnitDatas[i].name;
  214. string priName = GlobalData.layerUnitDatas[i].namePri;
  215. priName = priName.Replace("TaoKou", "NewTaoKou");
  216. var objType = GlobalData.layerUnitDatas[i].type;
  217. string className = GlobalData.layerUnitDatas[i].GetTypeName();
  218. obj.transform.SetParent(informationContent);
  219. obj.transform.Find("Name").GetComponentInChildren<Text>().text = realName;
  220. obj.transform.Find("Class").GetComponentInChildren<Text>().text = className;
  221. //todo
  222. obj.transform.Find("No").GetComponentInChildren<Text>().text = "未知";
  223. obj.transform.Find("Day").GetComponentInChildren<Text>().text = "近期";
  224. obj.transform.Find("fm").GetComponent<RawImage>().texture =
  225. TextureLoadHelp._Instance.GetTempTexture(priName);
  226. obj.transform.localScale = Vector3.one;
  227. informations.Add(obj);
  228. int dataIndex = i;
  229. obj.GetComponent<Button>().onClick.AddListener(() =>
  230. {
  231. currentData = GlobalData.layerUnitDatas[dataIndex];
  232. StaticLod.instance.OnFoucusStatic(priName);
  233. if (objType == LayerUnitType.ZZ || objType == LayerUnitType.BZ)
  234. {
  235. Info_DetailButton.gameObject.SetActive(true);
  236. }
  237. else
  238. {
  239. Info_DetailButton.gameObject.SetActive(false);
  240. }
  241. ShowInfoPanelData();
  242. });
  243. }
  244. }
  245. }
  246. else
  247. {
  248. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  249. {
  250. if (GlobalData.layerUnitDatas[i].type == (LayerUnitType)currentClass)
  251. {
  252. GameObject obj = Instantiate(informationPrefab);
  253. string realName = GlobalData.layerUnitDatas[i].name;
  254. string priName = GlobalData.layerUnitDatas[i].namePri;
  255. var objType = GlobalData.layerUnitDatas[i].type;
  256. string className = GlobalData.layerUnitDatas[i].GetTypeName();
  257. obj.transform.SetParent(informationContent);
  258. obj.transform.Find("Name").GetComponentInChildren<Text>().text = realName;
  259. obj.transform.Find("Class").GetComponentInChildren<Text>().text = className;
  260. //todo
  261. obj.transform.Find("No").GetComponentInChildren<Text>().text = "未知";
  262. obj.transform.Find("Day").GetComponentInChildren<Text>().text = "近期";
  263. obj.transform.Find("fm").GetComponent<RawImage>().texture =
  264. TextureLoadHelp._Instance.GetTempTexture(priName);
  265. obj.transform.localScale = Vector3.one;
  266. informations.Add(obj);
  267. int dataIndex = i;
  268. obj.GetComponent<Button>().onClick.AddListener(() =>
  269. {
  270. currentData = GlobalData.layerUnitDatas[dataIndex];
  271. StaticLod.instance.OnFoucusStatic(priName);
  272. if (objType == LayerUnitType.ZZ || objType == LayerUnitType.BZ)
  273. {
  274. Info_DetailButton.gameObject.SetActive(true);
  275. }
  276. else
  277. {
  278. Info_DetailButton.gameObject.SetActive(false);
  279. }
  280. ShowInfoPanelData();
  281. });
  282. }
  283. }
  284. }
  285. }
  286. public void SearchInformationItem(string s_name)
  287. {
  288. if (s_name.Equals(""))
  289. {
  290. for (int i = 0; i < informations.Count; i++)
  291. {
  292. informations[i].gameObject.SetActive(true);
  293. }
  294. }
  295. else
  296. {
  297. for (int i = 0; i < informations.Count; i++)
  298. {
  299. informations[i].gameObject.SetActive(informations[i].transform.Find("Name").GetComponentInChildren<Text>().text.Contains(s_name));
  300. }
  301. }
  302. }
  303. async Task InitData()
  304. {
  305. await new WaitUntil(() => { return GlobalData.layerUnitDatas.Count > 0; });
  306. }
  307. public void ShowInfoPanelData()
  308. {
  309. InfoTitleText.text = currentData.name;
  310. InfoClassText.text = currentData.GetTypeName();
  311. InfoFM.texture = TextureLoadHelp._Instance.GetTempTexture(currentData.namePri);
  312. //todo
  313. InfoNoText.text = "未知";
  314. InfoDayText.text = "近期";
  315. InfoPanel.SetActive(true);
  316. }
  317. public void ResetDetailPanel()
  318. {
  319. photoIndex = 0;
  320. pdfIndex = 0;
  321. lastPhotoButton.gameObject.SetActive(false);
  322. nextPhotoButton.gameObject.SetActive(false);
  323. downloadPdfButton.gameObject.SetActive(false);
  324. DetailShowType(0);
  325. }
  326. public void DetailShowType(int index)
  327. {
  328. showTypeIndex = index;
  329. switch (index)
  330. {
  331. case 0:
  332. detail_modelCG.alpha = 1;
  333. detail_designCG.alpha = 0.6f;
  334. detail_photoCG.alpha = 0.6f;
  335. detail_videoCG.alpha = 0.6f;
  336. showFrame.texture = modelRT;
  337. lastPhotoButton.gameObject.SetActive(false);
  338. nextPhotoButton.gameObject.SetActive(false);
  339. // OpenAniButton.gameObject.SetActive(currentData.namePri.Equals("BuYuan") ||
  340. // currentData.namePri.Equals("TaoKou"));
  341. // CloseAniButton.gameObject.SetActive(currentData.namePri.Equals("BuYuan") ||
  342. // currentData.namePri.Equals("TaoKou"));
  343. downloadPdfButton.gameObject.SetActive(false);
  344. break;
  345. case 1:
  346. detail_modelCG.alpha = 0.6f;
  347. detail_designCG.alpha = 1f;
  348. detail_photoCG.alpha = 0.6f;
  349. detail_videoCG.alpha = 0.6f;
  350. showFrame.texture = null;
  351. lastPhotoButton.gameObject.SetActive(true);
  352. nextPhotoButton.gameObject.SetActive(true);
  353. // OpenAniButton.gameObject.SetActive(false);
  354. // CloseAniButton.gameObject.SetActive(false);
  355. ChangePDF(0);
  356. break;
  357. case 2:
  358. detail_modelCG.alpha = 0.6f;
  359. detail_designCG.alpha = 0.6f;
  360. detail_photoCG.alpha = 1f;
  361. detail_videoCG.alpha = 0.6f;
  362. showFrame.texture = null;
  363. lastPhotoButton.gameObject.SetActive(true);
  364. nextPhotoButton.gameObject.SetActive(true);
  365. // OpenAniButton.gameObject.SetActive(false);
  366. // CloseAniButton.gameObject.SetActive(false);
  367. downloadPdfButton.gameObject.SetActive(false);
  368. ChangePhoto(0);
  369. break;
  370. case 3:
  371. detail_modelCG.alpha = 0.6f;
  372. detail_designCG.alpha = 0.6f;
  373. detail_photoCG.alpha = 0.6f;
  374. detail_videoCG.alpha = 1f;
  375. showFrame.texture = null;
  376. lastPhotoButton.gameObject.SetActive(false);
  377. nextPhotoButton.gameObject.SetActive(false);
  378. // OpenAniButton.gameObject.SetActive(false);
  379. // CloseAniButton.gameObject.SetActive(false);
  380. downloadPdfButton.gameObject.SetActive(false);
  381. break;
  382. }
  383. }
  384. public void ChangePhoto(int moveIndex)
  385. {
  386. if (currentData.namePri.Equals("BuYuan"))
  387. {
  388. switch (moveIndex)
  389. {
  390. case -1:
  391. if (photoIndex - 1 >= 0)
  392. {
  393. photoIndex--;
  394. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PhotoUrl[photoIndex], showFrame);
  395. }
  396. break;
  397. case 0:
  398. photoIndex = 0;
  399. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PhotoUrl[photoIndex], showFrame);
  400. break;
  401. case 1:
  402. if (photoIndex + 1 <= BY_PhotoUrl.Length-1)
  403. {
  404. photoIndex++;
  405. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PhotoUrl[photoIndex], showFrame);
  406. }
  407. break;
  408. }
  409. }
  410. if (currentData.namePri.Equals("TaoKou"))
  411. {
  412. switch (moveIndex)
  413. {
  414. case -1:
  415. if (photoIndex - 1 >= 0)
  416. {
  417. photoIndex--;
  418. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PhotoUrl[photoIndex], showFrame);
  419. }
  420. break;
  421. case 0:
  422. photoIndex = 0;
  423. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PhotoUrl[photoIndex], showFrame);
  424. break;
  425. case 1:
  426. if (photoIndex + 1 <= TK_PhotoUrl.Length-1)
  427. {
  428. photoIndex++;
  429. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PhotoUrl[photoIndex], showFrame);
  430. }
  431. break;
  432. }
  433. }
  434. }
  435. public void ChangePDF(int moveIndex)
  436. {
  437. if (currentData.namePri.Equals("BuYuan"))
  438. {
  439. switch (moveIndex)
  440. {
  441. case -1:
  442. if (pdfIndex - 1 >= 0)
  443. {
  444. pdfIndex--;
  445. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PdfUrl[pdfIndex], showFrame);
  446. }
  447. break;
  448. case 0:
  449. downloadPdfButton.gameObject.SetActive(true);
  450. pdfIndex = 0;
  451. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PdfUrl[pdfIndex], showFrame);
  452. break;
  453. case 1:
  454. if (pdfIndex + 1 <= BY_PdfUrl.Length-1)
  455. {
  456. pdfIndex++;
  457. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PdfUrl[pdfIndex], showFrame);
  458. }
  459. break;
  460. }
  461. }
  462. if (currentData.namePri.Equals("TaoKou"))
  463. {
  464. switch (moveIndex)
  465. {
  466. case -1:
  467. if (pdfIndex - 1 >= 0)
  468. {
  469. pdfIndex--;
  470. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PdfUrl[pdfIndex], showFrame);
  471. }
  472. break;
  473. case 0:
  474. downloadPdfButton.gameObject.SetActive(true);
  475. pdfIndex = 0;
  476. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PdfUrl[pdfIndex], showFrame);
  477. break;
  478. case 1:
  479. if (pdfIndex + 1 <= TK_PdfUrl.Length-1)
  480. {
  481. pdfIndex++;
  482. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PdfUrl[pdfIndex], showFrame);
  483. }
  484. break;
  485. }
  486. }
  487. }
  488. public void DownLoadPDF()
  489. {
  490. if (currentData.namePri.Equals("BuYuan"))
  491. {
  492. for (int i = 0; i < BY_PdfDownloadUrl.Length; i++)
  493. {
  494. OpenNewWebsite(ServerAddress.Server_UploadPath + BY_PdfDownloadUrl[i]);
  495. }
  496. }
  497. if (currentData.namePri.Equals("TaoKou"))
  498. {
  499. for (int i = 0; i < TK_PdfDownloadUrl.Length; i++)
  500. {
  501. OpenNewWebsite(ServerAddress.Server_UploadPath + TK_PdfDownloadUrl[i]);
  502. }
  503. }
  504. }
  505. }