12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082 |
- 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();
- }
- async void InitGCGKData() {
- await new WaitUntil(() =>
- {
- return GlobalData.gcgkContents.Count > 2;
- });
- 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()
- {
- // Debug.Log("111");
- await new WaitUntil(() =>
- {
- return GlobalData.byJKYJContents.total > 0 && GlobalData.tkJKYJContents.total > 0;
- });
- //Debug.Log("222");
- 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?"正常":"故障");
- }
- //Debug.Log("333");
- 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 ? "正常" : "故障");
- }
- // Debug.Log("444");
- 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()
- {
- //Debug.Log("555");
- await new WaitUntil(() =>
- {
- return GlobalData.TaoKouShuiWeiDataList.Count > 1;
- });
- //Debug.Log("666");
- 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;
- }
- //Debug.Log("777");
- 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);
- }
- }
- }
|