GCZLLayer.cs 21 KB

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