GCZLLayer.cs 20 KB

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