123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- 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;
- // Start is called before the first frame update
- async void Start()
- {
- await InitData();
- StaticLod.instance.OnFoucusStatic(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;
- obj.transform.SetParent(informationContent);
- obj.transform.Find("Name").GetComponentInChildren<Text>().text = realName;
- obj.transform.localScale = Vector3.one;
- informations.Add(obj);
- obj.GetComponent<Button>().onClick.AddListener(() =>
- {
- StaticLod.instance.OnFoucusStatic(priName);
- });
- }
- }
- }
- 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;
- obj.transform.SetParent(informationContent);
- obj.transform.Find("Name").GetComponentInChildren<Text>().text = realName;
- obj.transform.localScale = Vector3.one;
- informations.Add(obj);
- obj.GetComponent<Button>().onClick.AddListener(() =>
- {
- StaticLod.instance.OnFoucusStatic(priName);
- });
- }
- }
- }
- }
- async Task InitData()
- {
- await new WaitUntil(() =>
- {
- return GlobalData.layerUnitDatas.Count > 0;
- });
- }
- // Update is called once per frame
- void Update()
- {
-
- }
- }
|