123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958 |
- 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;
- [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 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;
- async void Awake()
- {
- viewMode = ViewMode.miniMap;
- _waterTrendPanel = this.transform.Find("WaterTrendPanel").GetComponent<WaterTrendPanel>();
- _waterTrendPanel.Init();
- await InitData();
- Init();
- InitLeftBtn();
- InitLayerInfo();
- InitLayerBtns();
- InitReturnBtn();
- InitRainInfo();
- InitSWHeightInfo();
- await InitPointData();
- InitPoint();
- }
- 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);
- };
- }
- newPoint.onPointClick = () =>
- {
- OnNewPointClick(temp, newPoint);
- };
- runtimePointLib.Add(newPoint);
- }
- RunTimeLayerClick(0);
- RunTimeLayerClick(1);
- RunTimeLayerClick(2);
- RunTimeLayerClick(3);
- RunTimeLayerClick(4);
- RunTimeLayerClick(5);
- }
- 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);
- }
- }
- }
|