GCZLLayer.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityAsync;
  6. using WaitUntil = UnityAsync.WaitUntil;
  7. using System.Threading.Tasks;
  8. using UnityEngine.UI;
  9. public class GCZLLayer : MonoBehaviour
  10. {
  11. public GameObject classPrefab;
  12. public GameObject informationPrefab;
  13. public RectTransform classContent;
  14. public RectTransform informationContent;
  15. public YZTLayer zTLayer;
  16. public Sprite[] sprites;
  17. private List<GameObject> informations = new List<GameObject>();
  18. private GameObject lastClassBtn;
  19. private int currentClass = -99;
  20. private GameObject InfoPanel;
  21. private Button InfoExitButton;
  22. private Button Info_DetailButton;
  23. private Text InfoTitleText;
  24. private Text InfoClassText;
  25. private Text InfoNoText;
  26. private Text InfoDayText;
  27. private RawImage InfoFM;
  28. private GameObject DetailPanel;
  29. private Button DetailExitButton;
  30. private Text DetailTitleText;
  31. private LayerUnitData currentData;
  32. private Button OpenAniButton;
  33. private Button CloseAniButton;
  34. private Button detail_modelButton;
  35. private Button detail_designButton;
  36. private Button detail_photoButton;
  37. private Button detail_videoButton;
  38. private CanvasGroup detail_modelCG;
  39. private CanvasGroup detail_designCG;
  40. private CanvasGroup detail_photoCG;
  41. private CanvasGroup detail_videoCG;
  42. private RawImage showFrame;
  43. private Button lastPhotoButton;
  44. private Button nextPhotoButton;
  45. public RenderTexture modelRT;
  46. public string[] BY_PhotoUrl;
  47. public string[] TK_PhotoUrl;
  48. public int photoIndex;
  49. private void Awake()
  50. {
  51. InfoPanel = this.transform.Find("InfoPanel").gameObject;
  52. InfoTitleText = InfoPanel.transform.Find("Title").GetComponent<Text>();
  53. InfoClassText = InfoPanel.transform.Find("Class").GetComponent<Text>();
  54. InfoNoText = InfoPanel.transform.Find("No").GetComponent<Text>();
  55. InfoDayText = InfoPanel.transform.Find("Day").GetComponent<Text>();
  56. InfoFM = InfoPanel.transform.Find("fm").GetComponent<RawImage>();
  57. InfoExitButton = InfoPanel.transform.Find("CloseButton").GetComponent<Button>();
  58. InfoExitButton.onClick.AddListener(() => { InfoPanel.SetActive(false); });
  59. Info_DetailButton = InfoPanel.transform.Find("MoreButton").GetComponent<Button>();
  60. Info_DetailButton.onClick.AddListener(() =>
  61. {
  62. DetailTitleText.text = currentData.name;
  63. OpenAniButton.gameObject.SetActive(currentData.name_pri.Equals("BuYuan") ||
  64. currentData.name_pri.Equals("TaoKou"));
  65. CloseAniButton.gameObject.SetActive(currentData.name_pri.Equals("BuYuan") ||
  66. currentData.name_pri.Equals("TaoKou"));
  67. ModelCameraCtrl._Instance.SetCameraActive(true);
  68. ResetDetailPanel();
  69. DetailPanel.SetActive(true);
  70. });
  71. DetailPanel = this.transform.Find("DetailPanel").gameObject;
  72. DetailTitleText = DetailPanel.transform.Find("Title").GetComponent<Text>();
  73. DetailExitButton = DetailPanel.transform.Find("CloseButton").GetComponent<Button>();
  74. DetailExitButton.onClick.AddListener(() =>
  75. {
  76. DetailPanel.SetActive(false);
  77. ModelCameraCtrl._Instance.SetCameraActive(false);
  78. });
  79. detail_modelButton = DetailPanel.transform.Find("ModelButton").GetComponent<Button>();
  80. detail_designButton = DetailPanel.transform.Find("DesignButton").GetComponent<Button>();
  81. detail_photoButton = DetailPanel.transform.Find("PhotoButton").GetComponent<Button>();
  82. detail_videoButton = DetailPanel.transform.Find("VideoButton").GetComponent<Button>();
  83. detail_modelCG = detail_modelButton.GetComponent<CanvasGroup>();
  84. detail_designCG = detail_designButton.GetComponent<CanvasGroup>();
  85. detail_photoCG = detail_photoButton.GetComponent<CanvasGroup>();
  86. detail_videoCG = detail_videoButton.GetComponent<CanvasGroup>();
  87. detail_modelButton.onClick.AddListener(() => { DetailShowType(0); });
  88. detail_designButton.onClick.AddListener(() => { DetailShowType(1); });
  89. detail_photoButton.onClick.AddListener(() => { DetailShowType(2); });
  90. detail_videoButton.onClick.AddListener(() => { DetailShowType(3); });
  91. showFrame = DetailPanel.transform.Find("ShowFrame").GetComponent<RawImage>();
  92. showFrame.texture = modelRT;
  93. lastPhotoButton = DetailPanel.transform.Find("LastPhotoButton").GetComponent<Button>();
  94. lastPhotoButton.onClick.AddListener(()=>ChangePhoto(-1));
  95. nextPhotoButton = DetailPanel.transform.Find("NextPhotoButton").GetComponent<Button>();
  96. nextPhotoButton.onClick.AddListener(()=>ChangePhoto(1));
  97. OpenAniButton = DetailPanel.transform.Find("OpenAniButton").GetComponent<Button>();
  98. OpenAniButton.onClick.AddListener(() => { ActionInstance._Instance.ModelAni_On?.Invoke(); });
  99. CloseAniButton = DetailPanel.transform.Find("CloseAniButton").GetComponent<Button>();
  100. CloseAniButton.onClick.AddListener(() => { ActionInstance._Instance.ModelAni_Off?.Invoke(); });
  101. InfoPanel.SetActive(false);
  102. DetailPanel.SetActive(false);
  103. }
  104. // Start is called before the first frame update
  105. async void Start()
  106. {
  107. await InitData();
  108. StaticLod.instance.OnFoucusStatic(0);
  109. CameraManager.SwitchCamera(0);
  110. InitButton();
  111. InitInformation(0);
  112. }
  113. void InitButton()
  114. {
  115. for (int i = 0; i < zTLayer.layerDatas.Length; i++)
  116. {
  117. string name = zTLayer.layerDatas[i].layerName;
  118. int temp = i;
  119. GameObject obj = Instantiate(classPrefab);
  120. obj.transform.SetParent(classContent);
  121. obj.GetComponentInChildren<Text>().text = name;
  122. obj.transform.localScale = Vector3.one;
  123. if (i == 0)
  124. {
  125. obj.GetComponent<Image>().sprite = sprites[0];
  126. lastClassBtn = obj;
  127. }
  128. else
  129. {
  130. obj.GetComponent<Image>().sprite = sprites[1];
  131. }
  132. obj.GetComponent<Button>().onClick.AddListener(() =>
  133. {
  134. InitInformation(temp);
  135. lastClassBtn.GetComponent<Image>().sprite = sprites[1];
  136. obj.GetComponent<Image>().sprite = sprites[0];
  137. lastClassBtn = obj;
  138. });
  139. }
  140. }
  141. void InitInformation(int index)
  142. {
  143. if (currentClass == index) return;
  144. for (int i = informations.Count - 1; i >= 0; i--)
  145. {
  146. Destroy(informations[i]);
  147. }
  148. informations.Clear();
  149. currentClass = index;
  150. if (currentClass == 0)
  151. {
  152. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  153. {
  154. if (GlobalData.layerUnitDatas[i].special)
  155. {
  156. GameObject obj = Instantiate(informationPrefab);
  157. string realName = GlobalData.layerUnitDatas[i].name;
  158. string priName = GlobalData.layerUnitDatas[i].name_pri;
  159. var objType = GlobalData.layerUnitDatas[i].type;
  160. string className = GlobalData.layerUnitDatas[i].GetTypeName();
  161. obj.transform.SetParent(informationContent);
  162. obj.transform.Find("Name").GetComponentInChildren<Text>().text = realName;
  163. obj.transform.Find("Class").GetComponentInChildren<Text>().text = className;
  164. //todo
  165. obj.transform.Find("No").GetComponentInChildren<Text>().text = "未知";
  166. obj.transform.Find("Day").GetComponentInChildren<Text>().text = "近期";
  167. obj.transform.Find("fm").GetComponent<RawImage>().texture =
  168. TextureLoadHelp._Instance.GetTempTexture(priName);
  169. obj.transform.localScale = Vector3.one;
  170. informations.Add(obj);
  171. int dataIndex = i;
  172. obj.GetComponent<Button>().onClick.AddListener(() =>
  173. {
  174. currentData = GlobalData.layerUnitDatas[dataIndex];
  175. StaticLod.instance.OnFoucusStatic(priName);
  176. if (objType == LayerUnitType.ZZ || objType == LayerUnitType.BZ)
  177. {
  178. Info_DetailButton.gameObject.SetActive(true);
  179. }
  180. else
  181. {
  182. Info_DetailButton.gameObject.SetActive(false);
  183. }
  184. ShowInfoPanelData();
  185. });
  186. }
  187. }
  188. }
  189. else
  190. {
  191. for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
  192. {
  193. if (GlobalData.layerUnitDatas[i].type == (LayerUnitType)currentClass)
  194. {
  195. GameObject obj = Instantiate(informationPrefab);
  196. string realName = GlobalData.layerUnitDatas[i].name;
  197. string priName = GlobalData.layerUnitDatas[i].name_pri;
  198. var objType = GlobalData.layerUnitDatas[i].type;
  199. string className = GlobalData.layerUnitDatas[i].GetTypeName();
  200. obj.transform.SetParent(informationContent);
  201. obj.transform.Find("Name").GetComponentInChildren<Text>().text = realName;
  202. obj.transform.Find("Class").GetComponentInChildren<Text>().text = className;
  203. //todo
  204. obj.transform.Find("No").GetComponentInChildren<Text>().text = "未知";
  205. obj.transform.Find("Day").GetComponentInChildren<Text>().text = "近期";
  206. obj.transform.Find("fm").GetComponent<RawImage>().texture =
  207. TextureLoadHelp._Instance.GetTempTexture(priName);
  208. obj.transform.localScale = Vector3.one;
  209. informations.Add(obj);
  210. int dataIndex = i;
  211. obj.GetComponent<Button>().onClick.AddListener(() =>
  212. {
  213. currentData = GlobalData.layerUnitDatas[dataIndex];
  214. StaticLod.instance.OnFoucusStatic(priName);
  215. if (objType == LayerUnitType.ZZ || objType == LayerUnitType.BZ)
  216. {
  217. Info_DetailButton.gameObject.SetActive(true);
  218. }
  219. else
  220. {
  221. Info_DetailButton.gameObject.SetActive(false);
  222. }
  223. ShowInfoPanelData();
  224. });
  225. }
  226. }
  227. }
  228. }
  229. async Task InitData()
  230. {
  231. await new WaitUntil(() => { return GlobalData.layerUnitDatas.Count > 0; });
  232. }
  233. public void ShowInfoPanelData()
  234. {
  235. InfoTitleText.text = currentData.name;
  236. InfoClassText.text = currentData.GetTypeName();
  237. InfoFM.texture = TextureLoadHelp._Instance.GetTempTexture(currentData.name_pri);
  238. //todo
  239. InfoNoText.text = "未知";
  240. InfoDayText.text = "近期";
  241. InfoPanel.SetActive(true);
  242. }
  243. public void ResetDetailPanel()
  244. {
  245. photoIndex = 0;
  246. lastPhotoButton.gameObject.SetActive(false);
  247. nextPhotoButton.gameObject.SetActive(false);
  248. DetailShowType(0);
  249. }
  250. public void DetailShowType(int index)
  251. {
  252. switch (index)
  253. {
  254. case 0:
  255. detail_modelCG.alpha = 1;
  256. detail_designCG.alpha = 0.6f;
  257. detail_photoCG.alpha = 0.6f;
  258. detail_videoCG.alpha = 0.6f;
  259. showFrame.texture = modelRT;
  260. lastPhotoButton.gameObject.SetActive(false);
  261. nextPhotoButton.gameObject.SetActive(false);
  262. OpenAniButton.gameObject.SetActive(currentData.name_pri.Equals("BuYuan") ||
  263. currentData.name_pri.Equals("TaoKou"));
  264. CloseAniButton.gameObject.SetActive(currentData.name_pri.Equals("BuYuan") ||
  265. currentData.name_pri.Equals("TaoKou"));
  266. break;
  267. case 1:
  268. detail_modelCG.alpha = 0.6f;
  269. detail_designCG.alpha = 1f;
  270. detail_photoCG.alpha = 0.6f;
  271. detail_videoCG.alpha = 0.6f;
  272. showFrame.texture = null;
  273. lastPhotoButton.gameObject.SetActive(false);
  274. nextPhotoButton.gameObject.SetActive(false);
  275. OpenAniButton.gameObject.SetActive(false);
  276. CloseAniButton.gameObject.SetActive(false);
  277. break;
  278. case 2:
  279. detail_modelCG.alpha = 0.6f;
  280. detail_designCG.alpha = 0.6f;
  281. detail_photoCG.alpha = 1f;
  282. detail_videoCG.alpha = 0.6f;
  283. showFrame.texture = null;
  284. lastPhotoButton.gameObject.SetActive(true);
  285. nextPhotoButton.gameObject.SetActive(true);
  286. OpenAniButton.gameObject.SetActive(false);
  287. CloseAniButton.gameObject.SetActive(false);
  288. ChangePhoto(0);
  289. break;
  290. case 3:
  291. detail_modelCG.alpha = 0.6f;
  292. detail_designCG.alpha = 0.6f;
  293. detail_photoCG.alpha = 0.6f;
  294. detail_videoCG.alpha = 1f;
  295. showFrame.texture = null;
  296. lastPhotoButton.gameObject.SetActive(false);
  297. nextPhotoButton.gameObject.SetActive(false);
  298. OpenAniButton.gameObject.SetActive(false);
  299. CloseAniButton.gameObject.SetActive(false);
  300. break;
  301. }
  302. }
  303. public void ChangePhoto(int moveIndex)
  304. {
  305. if (currentData.name_pri.Equals("BuYuan"))
  306. {
  307. switch (moveIndex)
  308. {
  309. case -1:
  310. if (photoIndex - 1 >= 0)
  311. {
  312. photoIndex--;
  313. TextureLoadHelp._Instance.LoadTexFromUrl(BY_PhotoUrl[photoIndex], showFrame);
  314. }
  315. break;
  316. case 0:
  317. photoIndex = 0;
  318. TextureLoadHelp._Instance.LoadTexFromUrl(BY_PhotoUrl[photoIndex], showFrame);
  319. break;
  320. case 1:
  321. if (photoIndex + 1 <= BY_PhotoUrl.Length-1)
  322. {
  323. photoIndex++;
  324. TextureLoadHelp._Instance.LoadTexFromUrl(BY_PhotoUrl[photoIndex], showFrame);
  325. }
  326. break;
  327. }
  328. }
  329. if (currentData.name_pri.Equals("TaoKou"))
  330. {
  331. switch (moveIndex)
  332. {
  333. case -1:
  334. if (photoIndex - 1 >= 0)
  335. {
  336. photoIndex--;
  337. TextureLoadHelp._Instance.LoadTexFromUrl(TK_PhotoUrl[photoIndex], showFrame);
  338. }
  339. break;
  340. case 0:
  341. photoIndex = 0;
  342. TextureLoadHelp._Instance.LoadTexFromUrl(TK_PhotoUrl[photoIndex], showFrame);
  343. break;
  344. case 1:
  345. if (photoIndex + 1 <= TK_PhotoUrl.Length-1)
  346. {
  347. photoIndex++;
  348. TextureLoadHelp._Instance.LoadTexFromUrl(TK_PhotoUrl[photoIndex], showFrame);
  349. }
  350. break;
  351. }
  352. }
  353. }
  354. }