123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityAsync;
- using WaitUntil = UnityAsync.WaitUntil;
- using System.Threading.Tasks;
- using UnityEngine.UI;
- public class GCZLLayer : MonoBehaviour
- {
- public GameObject classPrefab;
- public GameObject informationPrefab;
- public RectTransform classContent;
- public RectTransform informationContent;
- public YZTLayer zTLayer;
- public Sprite[] sprites;
-
- private List<GameObject> informations = new List<GameObject>();
- private GameObject lastClassBtn;
- private int currentClass = -99;
- private GameObject InfoPanel;
- private Button InfoExitButton;
- private Button Info_DetailButton;
- private Text InfoTitleText;
- private Text InfoClassText;
- private Text InfoNoText;
- private Text InfoDayText;
- private RawImage InfoFM;
- private GameObject DetailPanel;
- private Button DetailExitButton;
- private Text DetailTitleText;
- private LayerUnitData currentData;
-
- private void Awake()
- {
- InfoPanel = this.transform.Find("InfoPanel").gameObject;
- InfoTitleText = InfoPanel.transform.Find("Title").GetComponent<Text>();
- InfoClassText= InfoPanel.transform.Find("Class").GetComponent<Text>();
- InfoNoText= InfoPanel.transform.Find("No").GetComponent<Text>();
- InfoDayText= InfoPanel.transform.Find("Day").GetComponent<Text>();
- InfoFM = InfoPanel.transform.Find("fm").GetComponent<RawImage>();
- InfoExitButton = InfoPanel.transform.Find("CloseButton").GetComponent<Button>();
- InfoExitButton.onClick.AddListener(() =>
- {
- InfoPanel.SetActive(false);
- });
- Info_DetailButton = InfoPanel.transform.Find("MoreButton").GetComponent<Button>();
- Info_DetailButton.onClick.AddListener(() =>
- {
- DetailTitleText.text = currentData.name;
- DetailPanel.SetActive(true);
- });
- DetailPanel = this.transform.Find("DetailPanel").gameObject;
- DetailTitleText = DetailPanel.transform.Find("Title").GetComponent<Text>();
- DetailExitButton = DetailPanel.transform.Find("CloseButton").GetComponent<Button>();
- DetailExitButton.onClick.AddListener(() =>
- {
- DetailPanel.SetActive(false);
- });
- InfoPanel.SetActive(false);
- DetailPanel.SetActive(false);
- }
- // Start is called before the first frame update
- async void Start()
- {
- await InitData();
- StaticLod.instance.OnFoucusStatic(0);
- CameraManager.SwitchCamera(0);
- InitButton();
- InitInformation(0);
- }
- void InitButton() {
- for (int i = 0; i < zTLayer.layerDatas.Length; i++) {
- string name = zTLayer.layerDatas[i].layerName;
- int temp = i;
- GameObject obj = Instantiate(classPrefab);
- obj.transform.SetParent(classContent);
- obj.GetComponentInChildren<Text>().text = name;
- obj.transform.localScale = Vector3.one;
- if (i == 0)
- {
- obj.GetComponent<Image>().sprite = sprites[0];
- lastClassBtn = obj;
- }
- else
- {
- obj.GetComponent<Image>().sprite = sprites[1];
- }
- obj.GetComponent<Button>().onClick.AddListener(()=> {
- InitInformation(temp);
- lastClassBtn.GetComponent<Image>().sprite = sprites[1];
- obj.GetComponent<Image>().sprite = sprites[0];
- lastClassBtn = obj;
- });
- }
- }
- void InitInformation(int index) {
- if (currentClass == index) return;
- for (int i = informations.Count - 1; i >= 0; i--) {
- Destroy(informations[i]);
- }
- informations.Clear();
- currentClass = index;
- if (currentClass == 0)
- {
- for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
- {
- if (GlobalData.layerUnitDatas[i].special)
- {
- GameObject obj = Instantiate(informationPrefab);
- string realName = GlobalData.layerUnitDatas[i].name;
- string priName = GlobalData.layerUnitDatas[i].name_pri;
- var objType = GlobalData.layerUnitDatas[i].type;
- string className = GlobalData.layerUnitDatas[i].GetTypeName();
- obj.transform.SetParent(informationContent);
- obj.transform.Find("Name").GetComponentInChildren<Text>().text = realName;
- obj.transform.Find("Class").GetComponentInChildren<Text>().text = className;
- //todo
- obj.transform.Find("No").GetComponentInChildren<Text>().text = "未知";
- obj.transform.Find("Day").GetComponentInChildren<Text>().text = "近期";
- obj.transform.Find("fm").GetComponent<RawImage>().texture =
- TextureLoadHelp._Instance.GetTempTexture(priName);
- obj.transform.localScale = Vector3.one;
- informations.Add(obj);
- int dataIndex = i;
- obj.GetComponent<Button>().onClick.AddListener(() =>
- {
-
- currentData = GlobalData.layerUnitDatas[dataIndex];
- StaticLod.instance.OnFoucusStatic(priName);
- if (objType == LayerUnitType.ZZ|| objType==LayerUnitType.BZ)
- {
- Info_DetailButton.gameObject.SetActive(true);
- }
- else
- {
- Info_DetailButton.gameObject.SetActive(false);
- }
- ShowInfoPanelData();
- });
- }
- }
- }
- else {
- for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
- {
- if (GlobalData.layerUnitDatas[i].type == (LayerUnitType)currentClass)
- {
- GameObject obj = Instantiate(informationPrefab);
- string realName = GlobalData.layerUnitDatas[i].name;
- string priName = GlobalData.layerUnitDatas[i].name_pri;
- var objType = GlobalData.layerUnitDatas[i].type;
- string className = GlobalData.layerUnitDatas[i].GetTypeName();
- obj.transform.SetParent(informationContent);
- obj.transform.Find("Name").GetComponentInChildren<Text>().text = realName;
- obj.transform.Find("Class").GetComponentInChildren<Text>().text = className;
- //todo
- obj.transform.Find("No").GetComponentInChildren<Text>().text = "未知";
- obj.transform.Find("Day").GetComponentInChildren<Text>().text = "近期";
- obj.transform.Find("fm").GetComponent<RawImage>().texture =
- TextureLoadHelp._Instance.GetTempTexture(priName);
- obj.transform.localScale = Vector3.one;
- informations.Add(obj);
- int dataIndex = i;
- obj.GetComponent<Button>().onClick.AddListener(() =>
- {
- currentData = GlobalData.layerUnitDatas[dataIndex];
- StaticLod.instance.OnFoucusStatic(priName);
- if (objType == LayerUnitType.ZZ|| objType==LayerUnitType.BZ)
- {
- Info_DetailButton.gameObject.SetActive(true);
- }
- else
- {
- Info_DetailButton.gameObject.SetActive(false);
- }
- ShowInfoPanelData();
- });
- }
- }
- }
- }
- async Task InitData()
- {
- await new WaitUntil(() =>
- {
- return GlobalData.layerUnitDatas.Count > 0;
- });
- }
- public void ShowInfoPanelData()
- {
- InfoTitleText.text = currentData.name;
- InfoClassText.text = currentData.GetTypeName();
- InfoFM.texture = TextureLoadHelp._Instance.GetTempTexture(currentData.name_pri);
- //todo
- InfoNoText.text = "未知";
- InfoDayText.text = "近期";
- InfoPanel.SetActive(true);
- }
- }
|