GCZLLayer.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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. public Texture[] mTexs;
  59. public GameObject currentObj;
  60. [DllImport("__Internal")]
  61. private static extern void OpenNewWebsite(string str);
  62. private void Awake()
  63. {
  64. InfoPanel = this.transform.Find("InfoPanel").gameObject;
  65. InfoTitleText = InfoPanel.transform.Find("Title").GetComponent<Text>();
  66. InfoClassText = InfoPanel.transform.Find("Class").GetComponent<Text>();
  67. InfoNoText = InfoPanel.transform.Find("No").GetComponent<Text>();
  68. InfoDayText = InfoPanel.transform.Find("Day").GetComponent<Text>();
  69. InfoFM = InfoPanel.transform.Find("fm").GetComponent<RawImage>();
  70. InfoExitButton = InfoPanel.transform.Find("CloseButton").GetComponent<Button>();
  71. InfoExitButton.onClick.AddListener(() => { InfoPanel.SetActive(false); });
  72. Info_DetailButton = InfoPanel.transform.Find("MoreButton").GetComponent<Button>();
  73. Info_DetailButton.onClick.AddListener(() =>
  74. {
  75. DetailTitleText.text = currentData.name;
  76. // OpenAniButton.gameObject.SetActive(currentData.namePri.Equals("BuYuan") ||
  77. // currentData.namePri.Equals("TaoKou"));
  78. // CloseAniButton.gameObject.SetActive(currentData.namePri.Equals("BuYuan") ||
  79. // currentData.namePri.Equals("TaoKou"));
  80. ModelCameraCtrl._Instance.SetCameraActive(true);
  81. ResetDetailPanel();
  82. DetailPanel.SetActive(true);
  83. });
  84. DetailPanel = this.transform.Find("DetailPanel").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].opening_degree*0.01f;
  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].opening_degree*0.01f;
  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. await InitData();
  165. //StaticLod.instance.OnFoucusStatic(0);
  166. CameraManager.SwitchCamera(0);
  167. InitButton();
  168. InitInformation(0);
  169. informationSearchInput.onValueChanged.AddListener(SearchInformationItem);
  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. async 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. await new WaitUntil(() =>
  207. {
  208. return GlobalData.obsDatas_by.Count > 0 && GlobalData.obsDatas_tk.Count > 0;
  209. });
  210. informations.Clear();
  211. currentClass = index;
  212. if (currentClass == 0)
  213. {
  214. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  215. {
  216. if (GlobalData.layerUnitDatas[i].special == "1")
  217. {
  218. GameObject obj = Instantiate(informationPrefab);
  219. string realName = GlobalData.layerUnitDatas[i].name;
  220. string priName = GlobalData.layerUnitDatas[i].namePri;
  221. //priName = priName.Replace("TaoKou", "NewTaoKou");
  222. var objType = GlobalData.layerUnitDatas[i].type;
  223. string className = GlobalData.layerUnitDatas[i].GetTypeName();
  224. obj.transform.SetParent(informationContent);
  225. obj.transform.Find("Name").GetComponentInChildren<Text>().text = realName;
  226. obj.transform.Find("Class").GetComponentInChildren<Text>().text = className;
  227. //todo
  228. obj.transform.Find("No").GetComponentInChildren<Text>().text = "未知";
  229. obj.transform.Find("Day").GetComponentInChildren<Text>().text = "近期";
  230. obj.transform.Find("fm").GetComponent<RawImage>().texture =
  231. TextureLoadHelp._Instance.GetTempTexture(priName);
  232. obj.transform.localScale = Vector3.one;
  233. informations.Add(obj);
  234. int dataIndex = i;
  235. obj.GetComponent<Button>().onClick.AddListener(() =>
  236. {
  237. currentData = GlobalData.layerUnitDatas[dataIndex];
  238. currentObj = obj;
  239. StaticLod.instance.OnFoucusStatic(priName);
  240. if (objType == LayerUnitType.ZZ || objType == LayerUnitType.BZ)
  241. {
  242. Info_DetailButton.gameObject.SetActive(true);
  243. }
  244. else
  245. {
  246. Info_DetailButton.gameObject.SetActive(false);
  247. }
  248. ShowInfoPanelData();
  249. });
  250. }
  251. }
  252. }
  253. else
  254. {
  255. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  256. {
  257. if (GlobalData.layerUnitDatas[i].type == (LayerUnitType)zTLayer.layerDatas[currentClass].layerID)
  258. {
  259. GameObject obj = Instantiate(informationPrefab);
  260. string realName = GlobalData.layerUnitDatas[i].name;
  261. string priName = GlobalData.layerUnitDatas[i].namePri;
  262. var objType = GlobalData.layerUnitDatas[i].type;
  263. string className = GlobalData.layerUnitDatas[i].GetTypeName();
  264. obj.transform.SetParent(informationContent);
  265. obj.transform.Find("Name").GetComponentInChildren<Text>().text = realName;
  266. obj.transform.Find("Class").GetComponentInChildren<Text>().text = className;
  267. //todo
  268. if (currentClass == 4)
  269. {
  270. string noName;
  271. if (GlobalData.obsDeviceIDLib.TryGetValue(realName, out noName))
  272. {
  273. obj.transform.Find("No").GetComponentInChildren<Text>().text = noName;
  274. }
  275. else
  276. {
  277. obj.transform.Find("No").GetComponentInChildren<Text>().text = "未知";
  278. }
  279. }
  280. else {
  281. obj.transform.Find("No").GetComponentInChildren<Text>().text = "未知";
  282. }
  283. obj.transform.Find("Day").GetComponentInChildren<Text>().text = "近期";
  284. obj.transform.Find("fm").GetComponent<RawImage>().texture = mTexs[currentClass - 1];
  285. Texture tex = TextureLoadHelp._Instance.GetTempTexture(priName);
  286. if (tex != null)
  287. obj.transform.Find("fm").GetComponent<RawImage>().texture = tex;
  288. obj.transform.localScale = Vector3.one;
  289. informations.Add(obj);
  290. int dataIndex = i;
  291. obj.GetComponent<Button>().onClick.AddListener(() =>
  292. {
  293. currentObj = obj;
  294. currentData = GlobalData.layerUnitDatas[dataIndex];
  295. StaticLod.instance.OnFoucusStatic(priName);
  296. if (objType == LayerUnitType.ZZ || objType == LayerUnitType.BZ)
  297. {
  298. Info_DetailButton.gameObject.SetActive(true);
  299. }
  300. else
  301. {
  302. Info_DetailButton.gameObject.SetActive(false);
  303. }
  304. ShowInfoPanelData();
  305. });
  306. }
  307. }
  308. }
  309. }
  310. public void SearchInformationItem(string s_name)
  311. {
  312. if (s_name.Equals(""))
  313. {
  314. for (int i = 0; i < informations.Count; i++)
  315. {
  316. informations[i].gameObject.SetActive(true);
  317. }
  318. }
  319. else
  320. {
  321. for (int i = 0; i < informations.Count; i++)
  322. {
  323. informations[i].gameObject.SetActive(informations[i].transform.Find("Name").GetComponentInChildren<Text>().text.Contains(s_name));
  324. }
  325. }
  326. }
  327. async Task InitData()
  328. {
  329. await new WaitUntil(() => { return GlobalData.layerUnitDatas.Count > 0; });
  330. }
  331. public void ShowInfoPanelData()
  332. {
  333. InfoTitleText.text = currentData.name;
  334. InfoClassText.text = currentData.GetTypeName();
  335. //InfoFM.texture = TextureLoadHelp._Instance.GetTempTexture(currentData.namePri);
  336. InfoFM.texture = currentObj.transform.Find("fm").GetComponent<RawImage>().texture;
  337. //todo
  338. InfoNoText.text = currentObj.transform.Find("No").GetComponentInChildren<Text>().text;
  339. InfoDayText.text = "近期";
  340. InfoPanel.SetActive(true);
  341. }
  342. public void ResetDetailPanel()
  343. {
  344. photoIndex = 0;
  345. pdfIndex = 0;
  346. lastPhotoButton.gameObject.SetActive(false);
  347. nextPhotoButton.gameObject.SetActive(false);
  348. downloadPdfButton.gameObject.SetActive(false);
  349. DetailShowType(0);
  350. }
  351. public void DetailShowType(int index)
  352. {
  353. showTypeIndex = index;
  354. switch (index)
  355. {
  356. case 0:
  357. detail_modelCG.alpha = 1;
  358. detail_designCG.alpha = 0.6f;
  359. detail_photoCG.alpha = 0.6f;
  360. detail_videoCG.alpha = 0.6f;
  361. showFrame.texture = modelRT;
  362. lastPhotoButton.gameObject.SetActive(false);
  363. nextPhotoButton.gameObject.SetActive(false);
  364. // OpenAniButton.gameObject.SetActive(currentData.namePri.Equals("BuYuan") ||
  365. // currentData.namePri.Equals("TaoKou"));
  366. // CloseAniButton.gameObject.SetActive(currentData.namePri.Equals("BuYuan") ||
  367. // currentData.namePri.Equals("TaoKou"));
  368. downloadPdfButton.gameObject.SetActive(false);
  369. break;
  370. case 1:
  371. detail_modelCG.alpha = 0.6f;
  372. detail_designCG.alpha = 1f;
  373. detail_photoCG.alpha = 0.6f;
  374. detail_videoCG.alpha = 0.6f;
  375. showFrame.texture = null;
  376. lastPhotoButton.gameObject.SetActive(true);
  377. nextPhotoButton.gameObject.SetActive(true);
  378. // OpenAniButton.gameObject.SetActive(false);
  379. // CloseAniButton.gameObject.SetActive(false);
  380. ChangePDF(0);
  381. break;
  382. case 2:
  383. detail_modelCG.alpha = 0.6f;
  384. detail_designCG.alpha = 0.6f;
  385. detail_photoCG.alpha = 1f;
  386. detail_videoCG.alpha = 0.6f;
  387. showFrame.texture = null;
  388. lastPhotoButton.gameObject.SetActive(true);
  389. nextPhotoButton.gameObject.SetActive(true);
  390. // OpenAniButton.gameObject.SetActive(false);
  391. // CloseAniButton.gameObject.SetActive(false);
  392. downloadPdfButton.gameObject.SetActive(false);
  393. ChangePhoto(0);
  394. break;
  395. case 3:
  396. detail_modelCG.alpha = 0.6f;
  397. detail_designCG.alpha = 0.6f;
  398. detail_photoCG.alpha = 0.6f;
  399. detail_videoCG.alpha = 1f;
  400. showFrame.texture = null;
  401. lastPhotoButton.gameObject.SetActive(false);
  402. nextPhotoButton.gameObject.SetActive(false);
  403. // OpenAniButton.gameObject.SetActive(false);
  404. // CloseAniButton.gameObject.SetActive(false);
  405. downloadPdfButton.gameObject.SetActive(false);
  406. break;
  407. }
  408. }
  409. public void ChangePhoto(int moveIndex)
  410. {
  411. if (currentData.namePri.Equals("BuYuan"))
  412. {
  413. switch (moveIndex)
  414. {
  415. case -1:
  416. if (photoIndex - 1 >= 0)
  417. {
  418. photoIndex--;
  419. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PhotoUrl[photoIndex], showFrame);
  420. }
  421. break;
  422. case 0:
  423. photoIndex = 0;
  424. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PhotoUrl[photoIndex], showFrame);
  425. break;
  426. case 1:
  427. if (photoIndex + 1 <= BY_PhotoUrl.Length-1)
  428. {
  429. photoIndex++;
  430. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PhotoUrl[photoIndex], showFrame);
  431. }
  432. break;
  433. }
  434. }
  435. if (currentData.namePri.Equals("TaoKou"))
  436. {
  437. switch (moveIndex)
  438. {
  439. case -1:
  440. if (photoIndex - 1 >= 0)
  441. {
  442. photoIndex--;
  443. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PhotoUrl[photoIndex], showFrame);
  444. }
  445. break;
  446. case 0:
  447. photoIndex = 0;
  448. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PhotoUrl[photoIndex], showFrame);
  449. break;
  450. case 1:
  451. if (photoIndex + 1 <= TK_PhotoUrl.Length-1)
  452. {
  453. photoIndex++;
  454. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PhotoUrl[photoIndex], showFrame);
  455. }
  456. break;
  457. }
  458. }
  459. }
  460. public void ChangePDF(int moveIndex)
  461. {
  462. if (currentData.namePri.Equals("BuYuan"))
  463. {
  464. switch (moveIndex)
  465. {
  466. case -1:
  467. if (pdfIndex - 1 >= 0)
  468. {
  469. pdfIndex--;
  470. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PdfUrl[pdfIndex], showFrame);
  471. }
  472. break;
  473. case 0:
  474. downloadPdfButton.gameObject.SetActive(true);
  475. pdfIndex = 0;
  476. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PdfUrl[pdfIndex], showFrame);
  477. break;
  478. case 1:
  479. if (pdfIndex + 1 <= BY_PdfUrl.Length-1)
  480. {
  481. pdfIndex++;
  482. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + BY_PdfUrl[pdfIndex], showFrame);
  483. }
  484. break;
  485. }
  486. }
  487. if (currentData.namePri.Equals("TaoKou"))
  488. {
  489. switch (moveIndex)
  490. {
  491. case -1:
  492. if (pdfIndex - 1 >= 0)
  493. {
  494. pdfIndex--;
  495. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PdfUrl[pdfIndex], showFrame);
  496. }
  497. break;
  498. case 0:
  499. downloadPdfButton.gameObject.SetActive(true);
  500. pdfIndex = 0;
  501. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PdfUrl[pdfIndex], showFrame);
  502. break;
  503. case 1:
  504. if (pdfIndex + 1 <= TK_PdfUrl.Length-1)
  505. {
  506. pdfIndex++;
  507. TextureLoadHelp._Instance.LoadTexFromUrl(ServerAddress.Server_UploadPath + TK_PdfUrl[pdfIndex], showFrame);
  508. }
  509. break;
  510. }
  511. }
  512. }
  513. public void DownLoadPDF()
  514. {
  515. if (currentData.namePri.Equals("BuYuan"))
  516. {
  517. for (int i = 0; i < BY_PdfDownloadUrl.Length; i++)
  518. {
  519. OpenNewWebsite(ServerAddress.Server_UploadPath + BY_PdfDownloadUrl[i]);
  520. }
  521. }
  522. if (currentData.namePri.Equals("TaoKou"))
  523. {
  524. for (int i = 0; i < TK_PdfDownloadUrl.Length; i++)
  525. {
  526. OpenNewWebsite(ServerAddress.Server_UploadPath + TK_PdfDownloadUrl[i]);
  527. }
  528. }
  529. }
  530. }