GCZLLayer.cs 19 KB

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