GCZLLayer.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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. priName = priName.Replace("TaoKou", "NewTaoKou");
  214. var objType = GlobalData.layerUnitDatas[i].type;
  215. string className = GlobalData.layerUnitDatas[i].GetTypeName();
  216. obj.transform.SetParent(informationContent);
  217. obj.transform.Find("Name").GetComponentInChildren<Text>().text = realName;
  218. obj.transform.Find("Class").GetComponentInChildren<Text>().text = className;
  219. //todo
  220. obj.transform.Find("No").GetComponentInChildren<Text>().text = "未知";
  221. obj.transform.Find("Day").GetComponentInChildren<Text>().text = "近期";
  222. obj.transform.Find("fm").GetComponent<RawImage>().texture =
  223. TextureLoadHelp._Instance.GetTempTexture(priName);
  224. obj.transform.localScale = Vector3.one;
  225. informations.Add(obj);
  226. int dataIndex = i;
  227. obj.GetComponent<Button>().onClick.AddListener(() =>
  228. {
  229. currentData = GlobalData.layerUnitDatas[dataIndex];
  230. StaticLod.instance.OnFoucusStatic(priName);
  231. if (objType == LayerUnitType.ZZ || objType == LayerUnitType.BZ)
  232. {
  233. Info_DetailButton.gameObject.SetActive(true);
  234. }
  235. else
  236. {
  237. Info_DetailButton.gameObject.SetActive(false);
  238. }
  239. ShowInfoPanelData();
  240. });
  241. }
  242. }
  243. }
  244. else
  245. {
  246. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  247. {
  248. if (GlobalData.layerUnitDatas[i].type == (LayerUnitType)currentClass)
  249. {
  250. GameObject obj = Instantiate(informationPrefab);
  251. string realName = GlobalData.layerUnitDatas[i].name;
  252. string priName = GlobalData.layerUnitDatas[i].namePri;
  253. var objType = GlobalData.layerUnitDatas[i].type;
  254. string className = GlobalData.layerUnitDatas[i].GetTypeName();
  255. obj.transform.SetParent(informationContent);
  256. obj.transform.Find("Name").GetComponentInChildren<Text>().text = realName;
  257. obj.transform.Find("Class").GetComponentInChildren<Text>().text = className;
  258. //todo
  259. obj.transform.Find("No").GetComponentInChildren<Text>().text = "未知";
  260. obj.transform.Find("Day").GetComponentInChildren<Text>().text = "近期";
  261. obj.transform.Find("fm").GetComponent<RawImage>().texture =
  262. TextureLoadHelp._Instance.GetTempTexture(priName);
  263. obj.transform.localScale = Vector3.one;
  264. informations.Add(obj);
  265. int dataIndex = i;
  266. obj.GetComponent<Button>().onClick.AddListener(() =>
  267. {
  268. currentData = GlobalData.layerUnitDatas[dataIndex];
  269. StaticLod.instance.OnFoucusStatic(priName);
  270. if (objType == LayerUnitType.ZZ || objType == LayerUnitType.BZ)
  271. {
  272. Info_DetailButton.gameObject.SetActive(true);
  273. }
  274. else
  275. {
  276. Info_DetailButton.gameObject.SetActive(false);
  277. }
  278. ShowInfoPanelData();
  279. });
  280. }
  281. }
  282. }
  283. }
  284. async Task InitData()
  285. {
  286. await new WaitUntil(() => { return GlobalData.layerUnitDatas.Count > 0; });
  287. }
  288. public void ShowInfoPanelData()
  289. {
  290. InfoTitleText.text = currentData.name;
  291. InfoClassText.text = currentData.GetTypeName();
  292. InfoFM.texture = TextureLoadHelp._Instance.GetTempTexture(currentData.namePri);
  293. //todo
  294. InfoNoText.text = "未知";
  295. InfoDayText.text = "近期";
  296. InfoPanel.SetActive(true);
  297. }
  298. public void ResetDetailPanel()
  299. {
  300. photoIndex = 0;
  301. pdfIndex = 0;
  302. lastPhotoButton.gameObject.SetActive(false);
  303. nextPhotoButton.gameObject.SetActive(false);
  304. downloadPdfButton.gameObject.SetActive(false);
  305. DetailShowType(0);
  306. }
  307. public void DetailShowType(int index)
  308. {
  309. showTypeIndex = index;
  310. switch (index)
  311. {
  312. case 0:
  313. detail_modelCG.alpha = 1;
  314. detail_designCG.alpha = 0.6f;
  315. detail_photoCG.alpha = 0.6f;
  316. detail_videoCG.alpha = 0.6f;
  317. showFrame.texture = modelRT;
  318. lastPhotoButton.gameObject.SetActive(false);
  319. nextPhotoButton.gameObject.SetActive(false);
  320. // OpenAniButton.gameObject.SetActive(currentData.namePri.Equals("BuYuan") ||
  321. // currentData.namePri.Equals("TaoKou"));
  322. // CloseAniButton.gameObject.SetActive(currentData.namePri.Equals("BuYuan") ||
  323. // currentData.namePri.Equals("TaoKou"));
  324. downloadPdfButton.gameObject.SetActive(false);
  325. break;
  326. case 1:
  327. detail_modelCG.alpha = 0.6f;
  328. detail_designCG.alpha = 1f;
  329. detail_photoCG.alpha = 0.6f;
  330. detail_videoCG.alpha = 0.6f;
  331. showFrame.texture = null;
  332. lastPhotoButton.gameObject.SetActive(true);
  333. nextPhotoButton.gameObject.SetActive(true);
  334. // OpenAniButton.gameObject.SetActive(false);
  335. // CloseAniButton.gameObject.SetActive(false);
  336. ChangePDF(0);
  337. break;
  338. case 2:
  339. detail_modelCG.alpha = 0.6f;
  340. detail_designCG.alpha = 0.6f;
  341. detail_photoCG.alpha = 1f;
  342. detail_videoCG.alpha = 0.6f;
  343. showFrame.texture = null;
  344. lastPhotoButton.gameObject.SetActive(true);
  345. nextPhotoButton.gameObject.SetActive(true);
  346. // OpenAniButton.gameObject.SetActive(false);
  347. // CloseAniButton.gameObject.SetActive(false);
  348. downloadPdfButton.gameObject.SetActive(false);
  349. ChangePhoto(0);
  350. break;
  351. case 3:
  352. detail_modelCG.alpha = 0.6f;
  353. detail_designCG.alpha = 0.6f;
  354. detail_photoCG.alpha = 0.6f;
  355. detail_videoCG.alpha = 1f;
  356. showFrame.texture = null;
  357. lastPhotoButton.gameObject.SetActive(false);
  358. nextPhotoButton.gameObject.SetActive(false);
  359. // OpenAniButton.gameObject.SetActive(false);
  360. // CloseAniButton.gameObject.SetActive(false);
  361. downloadPdfButton.gameObject.SetActive(false);
  362. break;
  363. }
  364. }
  365. public void ChangePhoto(int moveIndex)
  366. {
  367. if (currentData.namePri.Equals("BuYuan"))
  368. {
  369. switch (moveIndex)
  370. {
  371. case -1:
  372. if (photoIndex - 1 >= 0)
  373. {
  374. photoIndex--;
  375. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PhotoUrl[photoIndex], showFrame);
  376. }
  377. break;
  378. case 0:
  379. photoIndex = 0;
  380. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PhotoUrl[photoIndex], showFrame);
  381. break;
  382. case 1:
  383. if (photoIndex + 1 <= BY_PhotoUrl.Length-1)
  384. {
  385. photoIndex++;
  386. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PhotoUrl[photoIndex], showFrame);
  387. }
  388. break;
  389. }
  390. }
  391. if (currentData.namePri.Equals("TaoKou"))
  392. {
  393. switch (moveIndex)
  394. {
  395. case -1:
  396. if (photoIndex - 1 >= 0)
  397. {
  398. photoIndex--;
  399. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PhotoUrl[photoIndex], showFrame);
  400. }
  401. break;
  402. case 0:
  403. photoIndex = 0;
  404. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PhotoUrl[photoIndex], showFrame);
  405. break;
  406. case 1:
  407. if (photoIndex + 1 <= TK_PhotoUrl.Length-1)
  408. {
  409. photoIndex++;
  410. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PhotoUrl[photoIndex], showFrame);
  411. }
  412. break;
  413. }
  414. }
  415. }
  416. public void ChangePDF(int moveIndex)
  417. {
  418. if (currentData.namePri.Equals("BuYuan"))
  419. {
  420. switch (moveIndex)
  421. {
  422. case -1:
  423. if (pdfIndex - 1 >= 0)
  424. {
  425. pdfIndex--;
  426. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PdfUrl[pdfIndex], showFrame);
  427. }
  428. break;
  429. case 0:
  430. downloadPdfButton.gameObject.SetActive(true);
  431. pdfIndex = 0;
  432. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PdfUrl[pdfIndex], showFrame);
  433. break;
  434. case 1:
  435. if (pdfIndex + 1 <= BY_PdfUrl.Length-1)
  436. {
  437. pdfIndex++;
  438. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PdfUrl[pdfIndex], showFrame);
  439. }
  440. break;
  441. }
  442. }
  443. if (currentData.namePri.Equals("TaoKou"))
  444. {
  445. switch (moveIndex)
  446. {
  447. case -1:
  448. if (pdfIndex - 1 >= 0)
  449. {
  450. pdfIndex--;
  451. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PdfUrl[pdfIndex], showFrame);
  452. }
  453. break;
  454. case 0:
  455. downloadPdfButton.gameObject.SetActive(true);
  456. pdfIndex = 0;
  457. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PdfUrl[pdfIndex], showFrame);
  458. break;
  459. case 1:
  460. if (pdfIndex + 1 <= TK_PdfUrl.Length-1)
  461. {
  462. pdfIndex++;
  463. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PdfUrl[pdfIndex], showFrame);
  464. }
  465. break;
  466. }
  467. }
  468. }
  469. public void DownLoadPDF()
  470. {
  471. if (currentData.namePri.Equals("BuYuan"))
  472. {
  473. for (int i = 0; i < BY_PdfDownloadUrl.Length; i++)
  474. {
  475. OpenNewWebsite(ServerAddress.Server_UploadPath + BY_PdfDownloadUrl[i]);
  476. }
  477. }
  478. if (currentData.namePri.Equals("TaoKou"))
  479. {
  480. for (int i = 0; i < TK_PdfDownloadUrl.Length; i++)
  481. {
  482. OpenNewWebsite(ServerAddress.Server_UploadPath + TK_PdfDownloadUrl[i]);
  483. }
  484. }
  485. }
  486. }