1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075 |
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- using UnityAsync;
- using WaitUntil = UnityAsync.WaitUntil;
- using DG.Tweening;
- using Unity.VisualScripting;
- using System.Reflection;
- [System.Serializable]
- public class YZTLayerData
- {
- public string layerName;
- public int layerID;
- }
- public enum LayerUnitType
- {
- ZZ = 1,
- BZ,
- NC,
- QXZ,
- JK,
- QT
- }
- [System.Serializable]
- public class JKYJData {
- public int normal;
- public int total;
- public int fault;
- public List<JKYJChildData> items;
- }
- [System.Serializable]
- public class JKYJChildData
- {
- public string name;
- public string model;
- public string ipAddress;
- public string deviceId;
- public string channelId;
- public bool onlineStatus;
- }
- public class GCGKData
- {
- public string name;
- public string type;
- public int count;
- }
- [System.Serializable]
- public class LayerUnitData
- {
- public string special;
- public LayerUnitType type;
- public float longitude;
- public float latitude;
- public string name;
- public string namePri;
- public string text1;
- public string text2;
- public string GetTypeName()
- {
- string result = "";
- switch (type)
- {
- case LayerUnitType.ZZ:
- result = "闸站";
- break;
- case LayerUnitType.BZ:
- result = "泵站";
- break;
- case LayerUnitType.NC:
- result = "农场";
- break;
- case LayerUnitType.QXZ:
- result = "气象站";
- break;
- case LayerUnitType.JK:
- result = "监控";
- break;
- case LayerUnitType.QT:
- result = "其他";
- break;
- }
- return result;
- }
- }
- [System.Serializable]
- public class HotPointData
- {
- public LayerUnitType type;
- public float longitude;
- public float latitude;
- public string name;
- public string namePri;
- }
- [System.Serializable]
- public class SWStationRecordData
- {
- public string name;
- public string time;
- public float value;
- public int dir;
- public string stcd = "0";
- }
- public class YZTLayer : YZTRootLayer
- {
- public VerticalLayoutGroup content;
- public Sprite[] layerSprite;
- public Sprite[] hotPointSprite;
- public LayerBtn layerBtnPrefab;
- public SecLayerBtn secLayerBtnPrefab;
- public YZTLayerData[] layerDatas;
- public RectTransform leftContent;
- public RectTransform middleContent;
- public RectTransform rightContent;
- List<LayerBtn> layerBtns = new List<LayerBtn>();
- public RuntimePoint pointPrefab;
- public GameObject runtimePointObj;
- public RectTransform pointParent;
- List<RuntimePoint> runtimePointLib = new List<RuntimePoint>();
- public GameObject yZTMini;
- public GameObject yZT;
- public RectTransform infoRight;
- public Button returnBtn;
- private float clickInterval;
- private Vector3 startClickPosition;
- public Button[] leftButtons;
- public Button layerButton;
- public int currentActiveLeft = 0;
- public RectTransform layerInfo;
- public Button layerInfoExitBtn;
- public Button[] baseLayerInfoBtns;
- public Button[] layerInfoBtns;
- public List<int> cancelLayer = new List<int>();
- public Sprite[] sprites;
- public Text rainText;
- public Text[] rainTextNum;
- public GameObject thingPrefab;
- public RectTransform thingParent;
- public List<SWStationRecordData> rescordSWStationData = new List<SWStationRecordData>();
- public List<GameObject> thing3s = new List<GameObject>();
- public Button clearBtn;
- public RectTransform regionParent;
- public RectTransform[] riverLayerInfo;
- public RectTransform[] lakeLayerInfo;
- public GameObject regionObjParent;
- public GameObject regionObjParent2;
- public GameObject[] regionLayerObj;
- public GameObject[] riverLayerObj;
- public GameObject[] lakeLayerObj;
- public List<GameObject> region2LayerObj = new List<GameObject>();
- // Start is called before the first frame update
- public WaterTrendPanel _waterTrendPanel;
- public Item0 item0Prefab;
- public GameObject item0Parent;
- public Text normalCount;
- public Text badCount;
- public Text stopCount;
- public Text allCount;
- public Thing0 thing0Prefab;
- public RectTransform thing0Content;
- public Text totalJKNum;
- public Text normalJKNum;
- public Text errorJKNum;
- public Text currentSWText;
- public Text avgSWText;
- public Text sfSWText;
- public Text jjSWText;
- public Text bzSWText;
- async void Awake()
- {
- viewMode = ViewMode.miniMap;
- _waterTrendPanel = this.transform.Find("WaterTrendPanel").GetComponent<WaterTrendPanel>();
- _waterTrendPanel.Init();
- await InitData();
- Init();
- InitLeftBtn();
- InitLayerInfo();
- InitLayerBtns();
- InitReturnBtn();
- InitGCGKData();
- InitJKYJData();
- InitSWYJData();
- InitRainInfo();
- InitSWHeightInfo();
- await InitPointData();
- InitPoint();
- }
- void InitGCGKData() {
- normalCount.text = GlobalData.gcgkContents[0].count.ToString() + "个";
- badCount.text = GlobalData.gcgkContents[1].count.ToString() + "个";
- stopCount.text = GlobalData.gcgkContents[2].count.ToString() + "个";
- allCount.text = (GlobalData.gcgkContents[0].count + GlobalData.gcgkContents[1].count + GlobalData.gcgkContents[2].count).ToString() + "个";
- }
- async void InitJKYJData()
- {
- await new WaitUntil(() =>
- {
- return GlobalData.byJKYJContents.total > 0 && GlobalData.tkJKYJContents.total > 0;
- });
- for (int i = 0; i < GlobalData.byJKYJContents.items.Count; i++) {
- Thing0 thing0 = Instantiate(thing0Prefab);
- thing0.transform.SetParent(thing0Content);
- thing0.transform.localPosition = Vector3.zero;
- thing0.transform.localScale = Vector3.one;
- thing0.SetData(i.ToString(), GlobalData.byJKYJContents.items[i].name, "补元", "开启", GlobalData.byJKYJContents.items[i].onlineStatus?"正常":"故障");
- }
- for (int i = 0; i < GlobalData.tkJKYJContents.items.Count; i++)
- {
- Thing0 thing0 = Instantiate(thing0Prefab);
- thing0.transform.SetParent(thing0Content);
- thing0.transform.localPosition = Vector3.zero;
- thing0.transform.localScale = Vector3.one;
- thing0.SetData((i + GlobalData.byJKYJContents.total).ToString(), GlobalData.tkJKYJContents.items[i].name, "套口", "开启", GlobalData.tkJKYJContents.items[i].onlineStatus ? "正常" : "故障");
- }
- totalJKNum.text = (GlobalData.byJKYJContents.total + GlobalData.tkJKYJContents.total).ToString();
- normalJKNum.text = (GlobalData.byJKYJContents.normal + GlobalData.tkJKYJContents.normal).ToString();
- errorJKNum.text = (GlobalData.byJKYJContents.fault + GlobalData.tkJKYJContents.fault).ToString();
- }
- async void InitSWYJData()
- {
- await new WaitUntil(() =>
- {
- return GlobalData.TaoKouShuiWeiDataList.Count > 1;
- });
- float value1 = GlobalData.TaoKouShuiWeiDataList[0].value;
- float value2 = GlobalData.TaoKouShuiWeiDataList[1].value;
- if (value1 > 1000)
- {
- value1 = value1 / 100.0f;
- }
- if (value2 > 1000)
- {
- value2 = value2 / 100.0f;
- }
- avgSWText.text = $"{((value1 + value2) / 2).ToString("0.00")}";
- sfSWText.text = $"{GlobalData.threeLevelShuiWeiDatas[1].floodProtectionLevel}";
- jjSWText.text = $"{GlobalData.threeLevelShuiWeiDatas[1].warningLevel}";
- bzSWText.text = $"{GlobalData.threeLevelShuiWeiDatas[1].guaranteeLevel}";
- currentSWText.text = value1.ToString("0.00");
- }
- void InitLeftBtn()
- {
- for (int i = 0; i < leftButtons.Length; i++)
- {
- int temp = i;
- leftButtons[i].onClick.AddListener(() =>
- {
- LeftBtnClick(temp);
- });
- }
- LeftBtnClick(0);
- clearBtn.onClick.AddListener(() =>
- {
- if (clearBtn.GetComponent<Image>().sprite == sprites[0])
- {
- for (int i = 0; i < leftButtons.Length; i++)
- leftButtons[i].gameObject.SetActive(false);
- clearBtn.GetComponent<Image>().sprite = sprites[1];
- DOTween.To(() => leftContent.GetComponent<RectTransform>().anchoredPosition, x => leftContent.GetComponent<RectTransform>().anchoredPosition = x, new Vector2(-219.74f, 0), 0.3f);
- DOTween.To(() => leftContent.GetComponent<CanvasGroup>().alpha, x => leftContent.GetComponent<CanvasGroup>().alpha = x, 0, 0.3f);
- pointParent.gameObject.SetActive(true);
- DOTween.To(() => middleContent.GetComponent<RectTransform>().anchoredPosition, x => middleContent.GetComponent<RectTransform>().anchoredPosition = x, new Vector2(400f, 540), 0.3f);
- DOTween.To(() => rightContent.GetComponent<RectTransform>().anchoredPosition, x => rightContent.GetComponent<RectTransform>().anchoredPosition = x, new Vector2(220.6f, 419.8932f), 0.3f);
- DOTween.To(() => rightContent.GetComponent<CanvasGroup>().alpha, x => rightContent.GetComponent<CanvasGroup>().alpha = x, 0, 0.3f);
- clearBtn.GetComponent<RectTransform>().DOLocalMoveX(-827f, 0.3f);
- }
- else
- {
- for (int i = 0; i < leftButtons.Length; i++)
- leftButtons[i].gameObject.SetActive(true);
- clearBtn.GetComponent<Image>().sprite = sprites[0];
- DOTween.To(() => leftContent.GetComponent<RectTransform>().anchoredPosition, x => leftContent.GetComponent<RectTransform>().anchoredPosition = x, new Vector2(219.74f, 0), 0.3f);
- DOTween.To(() => leftContent.GetComponent<CanvasGroup>().alpha, x => leftContent.GetComponent<CanvasGroup>().alpha = x, 1, 0.3f);
- pointParent.gameObject.SetActive(true);
- DOTween.To(() => middleContent.GetComponent<RectTransform>().anchoredPosition, x => middleContent.GetComponent<RectTransform>().anchoredPosition = x, new Vector2(0f, 540), 0.3f);
- DOTween.To(() => rightContent.GetComponent<RectTransform>().anchoredPosition, x => rightContent.GetComponent<RectTransform>().anchoredPosition = x, new Vector2(-220.6f, 419.8932f), 0.3f);
- DOTween.To(() => rightContent.GetComponent<CanvasGroup>().alpha, x => rightContent.GetComponent<CanvasGroup>().alpha = x, 1, 0.3f);
- clearBtn.GetComponent<RectTransform>().DOLocalMoveX(-457f, 0.3f);
- }
- });
- }
- async void InitSWHeightInfo()
- {
- await new WaitUntil(() =>
- {
- return GlobalData.swDatas.Count > 0;
- });
- if (rescordSWStationData.Count < 1)
- {
- for (int i = 0; i < GlobalData.swDatas.Count; i++)
- {
- SWStationRecordData sWStationRecordData = new SWStationRecordData();
- sWStationRecordData.dir = 0;
- sWStationRecordData.name = GlobalData.swDatas[i].STNM;
- sWStationRecordData.value = (GlobalData.swDatas[i].upz > GlobalData.swDatas[i].dwz) ? GlobalData.swDatas[i].upz : GlobalData.swDatas[i].dwz;
- sWStationRecordData.time = DateTime.Now.ToString("MM/dd HH:mm");
- sWStationRecordData.stcd = GlobalData.swDatas[i].STCD;
- rescordSWStationData.Add(sWStationRecordData);
- }
- for (int i = 0; i < rescordSWStationData.Count; i++)
- {
- GameObject obj = Instantiate(thingPrefab);
- obj.GetComponent<RectTransform>().SetParent(thingParent);
- obj.transform.localScale = Vector3.one;
- obj.transform.GetChild(0).GetComponent<Text>().text = (i + 1).ToString();
- string rescordSW_name = rescordSWStationData[i].name.ToString(); ;
- obj.transform.GetChild(1).GetComponent<Text>().text = rescordSW_name;
- obj.transform.GetChild(2).GetComponent<Text>().text = rescordSWStationData[i].time.ToString();
- obj.transform.GetChild(3).GetComponent<Text>().text = rescordSWStationData[i].value.ToString();
- string rescordSW_stcd = rescordSWStationData[i].stcd;
- obj.transform.GetComponent<Button>().onClick.AddListener(() =>
- {
- _waterTrendPanel.Show(rescordSW_stcd, rescordSW_name);
- });
- if (rescordSWStationData[i].dir == 0)
- {
- obj.transform.GetChild(4).localEulerAngles = new Vector3(0, 0, 0);
- }
- else if (rescordSWStationData[i].dir == 1)
- {
- obj.transform.GetChild(4).localEulerAngles = new Vector3(0, 0, 90);
- }
- else
- {
- obj.transform.GetChild(4).localEulerAngles = new Vector3(0, 0, -90);
- }
- thing3s.Add(obj);
- }
- }
- else
- {
- for (int i = 0; i < GlobalData.swDatas.Count; i++)
- {
- rescordSWStationData[i].name = GlobalData.swDatas[i].STNM;
- float lastValue = rescordSWStationData[i].value;
- rescordSWStationData[i].value = (GlobalData.swDatas[i].upz > GlobalData.swDatas[i].dwz) ? GlobalData.swDatas[i].upz : GlobalData.swDatas[i].dwz;
- rescordSWStationData[i].time = DateTime.Now.ToString("MM/dd HH:mm");
- if (rescordSWStationData[i].value > lastValue)
- {
- rescordSWStationData[i].dir = 1;
- }
- else if (rescordSWStationData[i].value > lastValue)
- {
- rescordSWStationData[i].dir = 0;
- }
- else
- {
- rescordSWStationData[i].dir = -1;
- }
- }
- for (int i = 0; i < rescordSWStationData.Count; i++)
- {
- thing3s[i].transform.GetChild(0).GetComponent<Text>().text = (i + 1).ToString();
- thing3s[i].transform.GetChild(1).GetComponent<Text>().text = rescordSWStationData[i].name.ToString();
- thing3s[i].transform.GetChild(2).GetComponent<Text>().text = rescordSWStationData[i].time.ToString();
- thing3s[i].transform.GetChild(3).GetComponent<Text>().text = rescordSWStationData[i].value.ToString();
- if (rescordSWStationData[i].dir == 0)
- {
- thing3s[i].transform.GetChild(4).localEulerAngles = new Vector3(0, 0, 0);
- }
- else if (rescordSWStationData[i].dir == 1)
- {
- thing3s[i].transform.GetChild(4).localEulerAngles = new Vector3(0, 0, 90);
- }
- else
- {
- thing3s[i].transform.GetChild(4).localEulerAngles = new Vector3(0, 0, -90);
- }
- }
- }
- }
- async void InitRainInfo()
- {
- await new WaitUntil(() =>
- {
- return GlobalData.qXZDatas.Count > 0;
- });
- int qxzCount = GlobalData.qXZDatas.Count;
- string maxName = "";
- float maxValue = -99f;
- int value010 = 0;
- int value1025 = 0;
- int value2550 = 0;
- int value50100 = 0;
- int value100200 = 0;
- int value200 = 0;
- for (int i = 0; i < qxzCount; i++)
- {
- float value = GlobalData.qXZDatas[i].dropSum6;
- if (value > maxValue)
- {
- maxValue = value;
- maxName = GlobalData.qXZDatas[i].STNM;
- }
- if (value >= 0 && value < 10)
- {
- value010++;
- }
- else if (value >= 10 && value < 25)
- {
- value1025++;
- }
- else if (value >= 25 && value < 50)
- {
- value2550++;
- }
- else if (value >= 50 && value < 100)
- {
- value50100++;
- }
- else if (value >= 100 && value < 200)
- {
- value100200++;
- }
- else
- {
- value200++;
- }
- }
- rainText.text = $"数据时间:17日12时至18日12时(过去24小时)\r\n蓄洪区共有{qxzCount}个雨量站,其中几个雨量站监测有降雨最大降雨测站为{maxName}站点,降雨量{maxValue}mm.";
- rainTextNum[0].text = value010.ToString();
- rainTextNum[1].text = value1025.ToString();
- rainTextNum[2].text = value2550.ToString();
- rainTextNum[3].text = value50100.ToString();
- rainTextNum[4].text = value100200.ToString();
- rainTextNum[5].text = value200.ToString();
- }
- void InitLayerInfo()
- {
- //layerInfoBtns = layerInfo.GetComponentsInChildren<Button>();
- for (int i = 0; i < layerInfoBtns.Length; i++)
- {
- int temp = i;
- layerInfoBtns[i].onClick.AddListener(() =>
- {
- RunTimeLayerClick(temp);
- });
- }
- layerButton.onClick.AddListener(() =>
- {
- layerInfo.gameObject.SetActive(true);
- });
- layerInfoExitBtn.onClick.AddListener(() =>
- {
- layerInfo.gameObject.SetActive(false);
- });
- baseLayerInfoBtns[0].onClick.AddListener(() =>
- {
- bool active = baseLayerInfoBtns[0].GetComponent<CanvasGroup>().alpha > 0.5f;
- BaseLayer0BtnOnClick(!active);
- });
- baseLayerInfoBtns[0].GetComponent<CanvasGroup>().alpha = 0.5f;
- baseLayerInfoBtns[1].onClick.AddListener(() =>
- {
- bool active = baseLayerInfoBtns[1].GetComponent<CanvasGroup>().alpha > 0.5f;
- baseLayerInfoBtns[1].GetComponent<CanvasGroup>().alpha = active ? 0.5f : 1.0f;
- bool newActive = !active;
- for (int i = 0; i < riverLayerObj.Length; i++)
- {
- riverLayerObj[i].gameObject.SetActive(newActive);
- riverLayerInfo[i].gameObject.SetActive(newActive);
- }
- });
- baseLayerInfoBtns[1].GetComponent<CanvasGroup>().alpha = 0.5f;
- baseLayerInfoBtns[2].onClick.AddListener(() =>
- {
- bool active = baseLayerInfoBtns[2].GetComponent<CanvasGroup>().alpha > 0.5f;
- BaseLayer2BtnOnClick(!active);
- });
- baseLayerInfoBtns[2].GetComponent<CanvasGroup>().alpha = 0.5f;
- for (int i = 0; i < regionObjParent2.transform.childCount; i++)
- {
- region2LayerObj.Add(regionObjParent2.transform.GetChild(i).gameObject);
- }
- baseLayerInfoBtns[3].onClick.AddListener(() =>
- {
- bool active = baseLayerInfoBtns[3].GetComponent<CanvasGroup>().alpha > 0.5f;
- BaseLayer3BtnOnClick(!active);
- });
- baseLayerInfoBtns[3].GetComponent<CanvasGroup>().alpha = 0.5f;
- }
- void BaseLayer0BtnOnClick(bool newActive)
- {
- baseLayerInfoBtns[0].GetComponent<CanvasGroup>().alpha = newActive ? 1f : 0.5f;
- if (newActive)
- {
- BaseLayer2BtnOnClick(false);
- BaseLayer3BtnOnClick(false);
- }
- for (int i = 0; i < regionLayerObj.Length; i++)
- {
- regionLayerObj[i].gameObject.SetActive(newActive);
- }
- }
- void BaseLayer2BtnOnClick(bool newActive)
- {
- if (newActive)
- {
- BaseLayer0BtnOnClick(false);
- BaseLayer3BtnOnClick(false);
- }
- baseLayerInfoBtns[2].GetComponent<CanvasGroup>().alpha = newActive ? 1f : 0.5f;
- for (int i = 0; i < lakeLayerObj.Length; i++)
- {
- lakeLayerObj[i].gameObject.SetActive(newActive);
- lakeLayerInfo[i].gameObject.SetActive(newActive);
- }
- }
- void BaseLayer3BtnOnClick(bool newActive)
- {
- if (newActive)
- {
- BaseLayer0BtnOnClick(false);
- BaseLayer2BtnOnClick(false);
- }
- baseLayerInfoBtns[3].GetComponent<CanvasGroup>().alpha = newActive ? 1f : 0.5f;
- for (int i = 0; i < region2LayerObj.Count; i++)
- {
- region2LayerObj[i].gameObject.SetActive(newActive);
- }
- }
- void RunTimeLayerClick(int temp)
- {
- bool active = layerInfoBtns[temp].GetComponent<CanvasGroup>().alpha > 0.5f;
- layerInfoBtns[temp].GetComponent<CanvasGroup>().alpha = active ? 0.5f : 1.0f;
- bool newActive = !active;
- ChangeRuntimeLayer(temp, newActive);
- }
- void LeftBtnClick(int index, bool record = true)
- {
- if (record)
- currentActiveLeft = index;
- for (int i = 0; i < leftButtons.Length; i++)
- {
- leftButtons[i].GetComponent<Image>().sprite = sprites[1];
- }
- leftButtons[index].GetComponent<Image>().sprite = sprites[0];
- for (int i = 0; i < leftContent.childCount; i++)
- {
- leftContent.transform.GetChild(i).gameObject.SetActive(false);
- }
- leftContent.transform.GetChild(index).gameObject.SetActive(true);
- if (index == 1)
- {
- InitSWHeightInfo();
- }
- }
- void InitLayerBtns()
- {
- layerBtns = new List<LayerBtn>();
- for (int i = 0; i < layerDatas.Length; i++)
- {
- LayerBtn layerBtn = Instantiate(layerBtnPrefab);
- layerBtn.SetUseful(false);
- int index = i;
- int num = 0;
- if (i == 0)
- {
- List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
- for (int j = 0; j < tempDatas.Count; j++)
- {
- if (tempDatas[j].special == "1")
- {
- int tempJ = j;
- SecLayerBtn secLayerBtn = Instantiate(secLayerBtnPrefab);
- secLayerBtn.SetLayerBtnData(tempDatas[j].name);
- secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
- secLayerBtn.btn.onClick.AddListener(() =>
- {
- CameraManager.SwitchCamera(0);
- viewMode = ViewMode.normal;
- StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].namePri);
- yZT.gameObject.SetActive(true);
- ChangeRightContent(tempJ);
- pointParent.gameObject.SetActive(false);
- clearBtn.gameObject.SetActive(false);
- middleContent.gameObject.SetActive(false);
- rightContent.gameObject.SetActive(false);
- LeftBtnClick(1, false);
- });
- num++;
- }
- }
- layerBtn.secContent.gameObject.SetActive(true);
- }
- else
- {
- List<LayerUnitData> tempDatas = new List<LayerUnitData>(GlobalData.layerUnitDatas);
- for (int j = 0; j < tempDatas.Count; j++)
- {
- if ((int)tempDatas[j].type == layerDatas[i].layerID)
- {
- int tempJ = j;
- SecLayerBtn secLayerBtn = Instantiate(secLayerBtnPrefab);
- secLayerBtn.SetLayerBtnData(tempDatas[j].name);
- secLayerBtn.GetComponent<RectTransform>().SetParent(layerBtn.secContent.GetComponent<RectTransform>());
- secLayerBtn.btn.onClick.AddListener(() =>
- {
- CameraManager.SwitchCamera(0);
- viewMode = ViewMode.normal;
- StaticLod.instance.OnFoucusStatic(tempDatas[tempJ].namePri);
- yZT.gameObject.SetActive(true);
- ChangeRightContent(tempJ);
- pointParent.gameObject.SetActive(false);
- clearBtn.gameObject.SetActive(false);
- middleContent.gameObject.SetActive(false);
- rightContent.gameObject.SetActive(false);
- LeftBtnClick(1, false);
- });
- num++;
- }
- }
- }
- layerBtn.btn.GetComponent<Button>().onClick.AddListener(() =>
- {
- for (int j = 0; j < layerBtns.Count; j++)
- {
- layerBtns[j].SetUseful(false);
- layerBtns[j].secContent.gameObject.SetActive(false);
- }
- layerBtns[index].SetUseful(true);
- layerBtns[index].secContent.gameObject.SetActive(true);
- //ChangeRuntimeLayer(index);
- });
- layerBtn.SetLayerBtnData(layerSprite[layerDatas[i].layerID], layerDatas[i].layerName, num.ToString());
- layerBtn.GetComponent<RectTransform>().SetParent(content.GetComponent<RectTransform>());
- layerBtn.transform.localScale = Vector3.one;
- layerBtns.Add(layerBtn);
- }
- content.GetComponent<VerticalLayoutGroup>().SetLayoutVertical();
- layerBtns[0].SetUseful(true);
- }
- void ChangeRightContent(int index)
- {
- for (int i = 0; i < infoRight.childCount; i++)
- {
- infoRight.GetChild(i).gameObject.SetActive(false);
- }
- infoRight.GetChild(index).gameObject.SetActive(true);
- GameObject title = infoRight.GetChild(index).GetChild(0).GetChild(1).gameObject;
- GameObject text1 = infoRight.GetChild(index).GetChild(0).GetChild(2).gameObject;
- if (title != null)
- {
- title.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].name;
- }
- if (text1 != null)
- {
- text1.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].text1;
- }
- if (infoRight.GetChild(index).GetChild(0).childCount > 3)
- {
- GameObject text2 = infoRight.GetChild(index).GetChild(0).GetChild(3).gameObject;
- if (text2 != null)
- {
- text2.GetComponent<Text>().text = GlobalData.layerUnitDatas[index].text2;
- }
- }
- }
- void InitPoint()
- {
- GameObject shaPan = GameObject.FindGameObjectWithTag("ShaPan");
- for (int i = 0; i < GlobalData.hotPointDatas.Count; i++)
- {
- HotPointData temp = GlobalData.hotPointDatas[i];
- Vector3 tempLocalPosition = CoordinateConverter.GeoToUGUISmall(temp.longitude, temp.latitude);
- //bool have = false;
- //for (int j = 0; j < runtimePointLib.Count; j++)
- //{
- // if (Vector3.Distance(tempLocalPosition, runtimePointLib[j].bingObj.transform.localPosition) < 0.1)
- // {
- // if (runtimePointLib[j].layerIDs.Contains((int)temp.type))
- // {
- // have = true;
- // break;
- // }
- // else {
- // have = true;
- // runtimePointLib[j].Refresh(hotPointSprite[8]);
- // runtimePointLib[j].layerIDs.Add((int)temp.type);
- // break;
- // }
- // }
- //}
- //if (have) {
- // continue;
- //}
- RuntimePoint newPoint = Instantiate(pointPrefab, Vector3.zero, Quaternion.identity);
-
- int tempI = i;
- newPoint.GetComponent<RectTransform>().SetParent(pointParent);
- newPoint.InitPoint(hotPointSprite[(int)(temp.type)], temp.namePri, temp.name);
- newPoint.layerIDs.Add((int)(temp.type));
- newPoint.bingObj = Instantiate(runtimePointObj).gameObject;
- newPoint.bingObj.transform.SetParent(shaPan.transform.GetChild(8));
- newPoint.bingObj.transform.localEulerAngles = Vector3.zero;
- newPoint.bingObj.transform.localScale = Vector3.one;
- newPoint.bingObj.transform.localPosition = tempLocalPosition;
- newPoint.bingObj.name = temp.name;
- if ((int)temp.type == 6 || (int)temp.type == 7)
- {
- int index = FindIndexByLayerUnitName(temp.name);
-
- Item0 item0 = Instantiate(item0Prefab, Vector3.zero, Quaternion.identity);
- item0.GetComponent<RectTransform>().SetParent(item0Parent.transform);
- item0.InitPoint(hotPointSprite[(int)(temp.type)], temp.namePri, temp.name, GlobalData.layerUnitDatas[index].special);
- item0.onPointClick = () =>
- {
- OnNewPointClick(temp, item0);
- };
- }
- Item0 item1 = Instantiate(item0Prefab, Vector3.zero, Quaternion.identity);
- item1.GetComponent<RectTransform>().SetParent(item0Parent.transform);
- item1.InitPoint(hotPointSprite[7], "GeTi", "隔提", "1");
- //item1.onPointClick = () =>
- //{
- // OnNewPointClick(temp, item1);
- //};
- newPoint.onPointClick = () =>
- {
- OnNewPointClick(temp, newPoint);
- };
- runtimePointLib.Add(newPoint);
- }
- RunTimeLayerClick(0);
- RunTimeLayerClick(1);
- RunTimeLayerClick(2);
- RunTimeLayerClick(3);
- RunTimeLayerClick(4);
- RunTimeLayerClick(5);
- RunTimeLayerClick(6);
- BaseLayer3BtnOnClick(true);
- }
- int FindIndexByLayerUnitName(string name)
- {
- for (int i = 0; i < GlobalData.layerUnitDatas.Count; i++)
- {
- if (GlobalData.layerUnitDatas[i].name == name.Trim())
- {
- return i;
- }
- }
- return -1;
- }
- int FindIndexByHotPointName(string name)
- {
- Debug.Log(name);
- for (int i = 0; i < GlobalData.swDatas.Count; i++)
- {
- Debug.Log(GlobalData.swDatas[i].STNM);
- if (GlobalData.swDatas[i].STNM.Trim() == name.Trim())
- {
- return i;
- }
- }
- return -1;
- }
- void OnNewPointClick(HotPointData temp, RuntimePoint newPoint)
- {
- Debug.Log(temp.type);
- if ((int)temp.type == 4)
- {
- int index = FindIndexByHotPointName(temp.name);
- Debug.Log(index);
- _waterTrendPanel.Show(GlobalData.swDatas[index].STCD, GlobalData.swDatas[index].STNM);
- }
- else if ((int)temp.type >= 6 || newPoint.layerIDs.Count > 4)
- {
- CameraManager.SwitchCamera(0);
- viewMode = ViewMode.normal;
- StaticLod.instance.OnFoucusStatic(newPoint.staticImp);
- yZT.gameObject.SetActive(true);
- int index = FindIndexByLayerUnitName(temp.name);
- ChangeRightContent(index);
- pointParent.gameObject.SetActive(false);
- clearBtn.gameObject.SetActive(false);
- middleContent.gameObject.SetActive(false);
- rightContent.gameObject.SetActive(false);
- LeftBtnClick(1, false);
- }
- }
- void OnNewPointClick(HotPointData temp, Item0 item0)
- {
- CameraManager.SwitchCamera(0);
- viewMode = ViewMode.normal;
- StaticLod.instance.OnFoucusStatic(item0.staticImp);
- yZT.gameObject.SetActive(true);
- int index = FindIndexByLayerUnitName(temp.name);
- ChangeRightContent(index);
- pointParent.gameObject.SetActive(false);
- clearBtn.gameObject.SetActive(false);
- middleContent.gameObject.SetActive(false);
- rightContent.gameObject.SetActive(false);
- LeftBtnClick(1, false);
- }
- async Task InitData()
- {
- await new WaitUntil(() =>
- {
- return GlobalData.layerUnitDatas.Count > 0;
- });
- }
- async Task InitPointData()
- {
- await new WaitUntil(() =>
- {
- return GlobalData.hotPointDatas.Count > 0;
- });
- }
- void Init()
- {
- yZT.gameObject.SetActive(false);
- clearBtn.gameObject.SetActive(true);
- pointParent.gameObject.SetActive(true);
- middleContent.gameObject.SetActive(true);
- rightContent.gameObject.SetActive(true);
- LeftBtnClick(currentActiveLeft);
- }
- void InitReturnBtn()
- {
- returnBtn.onClick.AddListener(() =>
- {
- CameraManager.SwitchCamera(1);
- viewMode = ViewMode.miniMap;
- Init();
- });
- }
- void ChangeRuntimeLayer(int layer, bool show)
- {
- if (show)
- {
- if (cancelLayer.Contains(layer))
- {
- cancelLayer.Remove(layer);
- }
- }
- else
- {
- if (!cancelLayer.Contains(layer))
- {
- cancelLayer.Add(layer);
- }
- }
- for (int i = 0; i < runtimePointLib.Count; i++)
- {
- if (runtimePointLib[i].layerIDs.Contains(layer))
- {
- if (runtimePointLib[i].layerIDs.Count < 2)
- {
- runtimePointLib[i].gameObject.SetActive(show);
- }
- else
- {
- List<int> tempLayers = new List<int>(runtimePointLib[i].layerIDs);
- for (int j = 0; j < cancelLayer.Count; j++)
- {
- if (tempLayers.Contains(cancelLayer[j]))
- {
- tempLayers.Remove(cancelLayer[j]);
- }
- }
- if (tempLayers.Count < 1)
- {
- runtimePointLib[i].gameObject.SetActive(false);
- }
- else
- {
- runtimePointLib[i].gameObject.SetActive(true);
- }
- }
- }
- }
- }
- void ShootRay()
- {
- Ray ray = CameraManager.instance.mainCamera.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit, 20000, 1 << 8 | 1 << 9))
- {
- CameraBird bird = CameraManager.instance.mainCamera.GetComponent<CameraBird>();
- if (hit.collider.gameObject.layer == LayerMask.NameToLayer("EarthTile"))
- {
- if (bird.transform.position.y > 1000)
- {
- bird.SetCameraToCenterFade(hit.point, 1100);
- }
- }
- else if (hit.collider.gameObject.layer == LayerMask.NameToLayer("StaticImportant"))
- {
- StaticImportant si = hit.collider.gameObject.GetComponent<StaticImportant>();
- int index = StaticLod.instance.OnFoucusStatic(si);
- yZT.gameObject.SetActive(true);
- ChangeRightContent(index);
- pointParent.gameObject.SetActive(false);
- clearBtn.gameObject.SetActive(false);
- middleContent.gameObject.SetActive(false);
- rightContent.gameObject.SetActive(false);
- LeftBtnClick(1, false);
- }
- }
- else
- {
- Debug.Log("No hit");
- }
- }
- private void OnEnable()
- {
- if (regionObjParent != null)
- regionObjParent.transform.gameObject.SetActive(true);
- if (regionObjParent2 != null)
- regionObjParent2.transform.gameObject.SetActive(true);
- }
- private void OnDisable()
- {
- if (regionObjParent != null)
- regionParent.transform.gameObject.SetActive(false);
- if (regionObjParent2 != null)
- regionObjParent2.transform.gameObject.SetActive(false);
- }
- private void Update()
- {
- if (Input.GetMouseButtonDown(0)) // 检测鼠标左键点击
- {
- clickInterval = 0.0f;
- startClickPosition = Input.mousePosition;
- }
- clickInterval += Time.deltaTime;
- if (Input.GetMouseButtonUp(0))
- {
- if (clickInterval < 0.2f && Vector3.Distance(startClickPosition, Input.mousePosition) < 10f)
- {
- if (!CameraManager.instance.secondCamera.enabled)
- {
- ShootRay();
- }
- }
- }
- }
- private void LateUpdate()
- {
- if (CameraManager.instance.secondCamera.enabled)
- {
- regionParent.transform.gameObject.SetActive(true);
- for (int i = 0; i < riverLayerInfo.Length; i++)
- {
- if (riverLayerInfo[i].gameObject.activeSelf)
- {
- riverLayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(riverLayerObj[i].transform.position) / Screen.width * 1920.0f;
- }
- }
- for (int i = 0; i < lakeLayerInfo.Length; i++)
- {
- if (lakeLayerInfo[i].gameObject.activeSelf)
- {
- lakeLayerInfo[i].anchoredPosition = CameraManager.instance.secondCamera.WorldToScreenPoint(lakeLayerObj[i].transform.position) / Screen.width * 1920.0f;
- }
- }
-
- }
- else
- {
- regionParent.transform.gameObject.SetActive(false);
- }
- }
- }
|