123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559 |
- using Best.HTTP.Shared.Compression.Zlib;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using Unity.VisualScripting;
- using UnityAsync;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- using WaitUntil = UnityAsync.WaitUntil;
- [System.Serializable]
- public class MovePlan
- {
- public string startPos;
- public string endPos;
- public int humanNum;
- public string time;
- }
- [System.Serializable]
- public class MoveAtten
- {
- public string title;
- public string pos;
- public string time;
- }
- [System.Serializable]
- public class ServerMovePlan {
- public bool isAfter;
- public bool isOut;
- public string desc;
- public string from;
- public float fromLong;
- public float fromLttd;
- public string to;
- public float toLong;
- public float toLttd;
- public int manNum;
- public int homeNum;
- public int completeNum;
- public string dateTime;
- public int villageCount;
- public int materialPrize;
- }
- [System.Serializable]
- public class ZYYAData
- {
- public int totalRoadCount;
- public float totalmanNum;
- public int totalVillageCount;
- public float totalMaterialPrize;
- }
- public class RKZYLayer : YZTRootLayer
- {
- public Text timeText;
- public LineInfo lineInfo;
- //public List<MovePlan> movePlans;
- public List<Thing1> movePlans;
- public List<MoveAtten> moveAttens;
- public static LineInfo lineInfoStatic;
- public Button beforeBtn;
- public Button afterBtn;
- public Button[] allInOut;
- public Transform beforeC;
- public Transform afterC;
- public List<LinePath> linePaths = new List<LinePath>();
- public Sprite[] sprites;
- public int inOutIndex;
- public int beforeAfterIndex;
- public RectTransform title1;
- public RectTransform plan1;
- public RectTransform movePlanBeforeContent;
- public RectTransform movePlanAfterContent;
- public RectTransform title2;
- public RectTransform plan2;
- public RectTransform attenContent;
-
- public Text[] zYGKText;
- public ZYYAData[] zYYADatas;
- public int zYYAIndex = 0;
- public Text[] zYYAText;
- public Material afterMat;
- public LinePath linePathPrefab;
- // Start is called before the first frame update
- async void Start()
- {
- GameObject shaPan = GameObject.FindGameObjectWithTag("ShaPan");
- beforeC.gameObject.SetActive(true);
- beforeC = shaPan.transform.GetChild(10);
- afterC = shaPan.transform.GetChild(11);
- lineInfoStatic = lineInfo;
- await InitMovePlan();
- //TODO 这一块的path应该从movePlan里面生成而不是默认
- InitAllPath();
- InitButton();
- InitAtten();
- await InitBaseData();
- }
- public override void OnUILeave()
- {
- base.OnUILeave();
- beforeC.gameObject.SetActive(false);
- afterC.gameObject.SetActive(false);
- }
- private void OnEnable()
- {
- CameraManager.SwitchCamera(1);
- }
- void InitAtten() {
- RectTransform title = Instantiate(title2);
- title.SetParent(attenContent);
- title.localScale = Vector3.one;
- for (int i = 0; i < moveAttens.Count; i++)
- {
- RectTransform plan = Instantiate(plan2);
- plan.SetParent(attenContent);
- plan.localScale = Vector3.one;
- plan.GetChild(0).GetComponent<Text>().text = i.ToString();
- plan.GetChild(1).GetComponent<Text>().text = moveAttens[i].title;
- plan.GetChild(2).GetComponent<Text>().text = moveAttens[i].pos;
- plan.GetChild(3).GetComponent<Text>().text = moveAttens[i].time;
- }
- }
- async Task InitBaseData() {
- bool successInternet = true;
- UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetGeBaseData);
- await requestData.SendWebRequest();
- try
- {
- if (requestData.result != UnityWebRequest.Result.Success)
- {
- Debug.LogWarning("RKZYLayer基础数据联网不成功,原因:返request不成功");
- successInternet = false;
- }
- else
- {
- JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
- JToken codeToken = jsonObject["code"];
- if (codeToken.ToString() == "200")
- {
- JToken areaToken = jsonObject["data"]["area"];
- JToken capacityToken = jsonObject["data"]["capacity"];
- JToken populationToken = jsonObject["data"]["population"];
- zYGKText[0].text = populationToken.ToString() + "人";
- zYGKText[1].text = GlobalData.allServerMovePlans.Count.ToString() + "条";
- zYGKText[2].text = areaToken.ToString() + "km²";
- zYGKText[3].text = (float.Parse((capacityToken.ToString())) * 100).ToString() + "%";
- }
- else
- {
- successInternet = false;
- Debug.LogWarning("RKZYLayer基础数据联网不成功,原因:返序列化失败");
- }
- }
- }
- catch (Exception e)
- {
- successInternet = false;
- Debug.LogWarning("RKZYLayer基础数据联网不成功,原因:" + e.ToString());
- }
- }
- async Task InitMovePlan() {
-
- zYYADatas = new ZYYAData[6] { new ZYYAData(), new ZYYAData() , new ZYYAData() , new ZYYAData() , new ZYYAData() , new ZYYAData() };
- await new WaitUntil(() =>
- {
- return GlobalData.allServerMovePlans.Count > 0;
- });
- int beforeIndex = 0;
- int afterIndex = 0;
- List<LinePath> beforeLinePaths = new List<LinePath>();
- List<LinePath> afterLinePaths = new List<LinePath>();
- GameObject shaPan = GameObject.FindGameObjectWithTag("ShaPan");
- Transform runtimPointParent = shaPan.transform.GetChild(10);
- for (int i = 0; i < GlobalData.allServerMovePlans.Count; i++) {
- bool after = GlobalData.allServerMovePlans[i].isAfter;
- bool isOut = GlobalData.allServerMovePlans[i].isOut;
- if (!after)
- {
- LinePath linePath = Instantiate(linePathPrefab);
- linePath.transform.SetParent(beforeC);
- linePath.startPos = GlobalData.allServerMovePlans[i].from;
- Vector3 localPos = CoordinateConverter.GeoToUGUISmall(GlobalData.allServerMovePlans[i].fromLong, GlobalData.allServerMovePlans[i].fromLttd);
- Vector3 worldPos = runtimPointParent.TransformPoint(localPos);
- worldPos.z = -583;
- linePath.endPos = GlobalData.allServerMovePlans[i].to;
- Vector3 localPos1 = CoordinateConverter.GeoToUGUISmall(GlobalData.allServerMovePlans[i].toLong, GlobalData.allServerMovePlans[i].toLttd);
- Vector3 worldPos1 = runtimPointParent.TransformPoint(localPos1);
- worldPos1.z = -583;
- linePath.SetPath(worldPos, worldPos1);
- linePath.lineDir = isOut ? LineDir.Out : LineDir.In;
- linePath.linePathContent = GlobalData.allServerMovePlans[i].desc;
- linePath.manNum = GlobalData.allServerMovePlans[i].manNum;
- linePath.homeNum = GlobalData.allServerMovePlans[i].homeNum;
- linePath.completeNum = GlobalData.allServerMovePlans[i].completeNum;
- linePath.dateTime = GlobalData.allServerMovePlans[i].dateTime;
- if (linePath.lineDir == LineDir.Out)
- {
- zYYADatas[1].totalmanNum += GlobalData.allServerMovePlans[i].manNum;
- zYYADatas[1].totalVillageCount += GlobalData.allServerMovePlans[i].villageCount;
- zYYADatas[1].totalMaterialPrize += GlobalData.allServerMovePlans[i].materialPrize;
- zYYADatas[1].totalRoadCount += 1;
- }
- else
- {
- zYYADatas[2].totalmanNum += GlobalData.allServerMovePlans[i].manNum;
- zYYADatas[2].totalVillageCount += GlobalData.allServerMovePlans[i].villageCount;
- zYYADatas[2].totalMaterialPrize += GlobalData.allServerMovePlans[i].materialPrize;
- zYYADatas[2].totalRoadCount += 1;
- }
- beforeLinePaths.Add(linePath);
- }
- else
- {
- LinePath linePath = Instantiate(linePathPrefab);
- linePath.transform.SetParent(afterC);
- linePath.startPos = GlobalData.allServerMovePlans[i].from;
- Vector3 localPos = CoordinateConverter.GeoToUGUISmall(GlobalData.allServerMovePlans[i].fromLong, GlobalData.allServerMovePlans[i].fromLttd);
- Vector3 worldPos = runtimPointParent.TransformPoint(localPos);
- worldPos.z = -583;
- linePath.endPos = GlobalData.allServerMovePlans[i].to;
- Vector3 localPos1 = CoordinateConverter.GeoToUGUISmall(GlobalData.allServerMovePlans[i].toLong, GlobalData.allServerMovePlans[i].toLttd);
- Vector3 worldPos1 = runtimPointParent.TransformPoint(localPos1);
- worldPos1.z = -583;
- linePath.SetPath(worldPos, worldPos1);
- linePath.lineDir = isOut ? LineDir.Out : LineDir.In;
- linePath.linePathContent = GlobalData.allServerMovePlans[i].desc;
- linePath.manNum = GlobalData.allServerMovePlans[i].manNum;
- linePath.homeNum = GlobalData.allServerMovePlans[i].homeNum;
- linePath.completeNum = GlobalData.allServerMovePlans[i].completeNum;
- linePath.dateTime = GlobalData.allServerMovePlans[i].dateTime;
- if (linePath.lineDir == LineDir.Out)
- {
- zYYADatas[4].totalmanNum += GlobalData.allServerMovePlans[i].manNum;
- zYYADatas[4].totalVillageCount += GlobalData.allServerMovePlans[i].villageCount;
- zYYADatas[4].totalMaterialPrize += GlobalData.allServerMovePlans[i].materialPrize;
- zYYADatas[4].totalRoadCount += 1;
- }
- else
- {
- zYYADatas[5].totalmanNum += GlobalData.allServerMovePlans[i].manNum;
- zYYADatas[5].totalVillageCount += GlobalData.allServerMovePlans[i].villageCount;
- zYYADatas[5].totalMaterialPrize += GlobalData.allServerMovePlans[i].materialPrize;
- zYYADatas[5].totalRoadCount += 1;
- }
- afterLinePaths.Add(linePath);
- }
- zYYADatas[0].totalmanNum = zYYADatas[1].totalmanNum + zYYADatas[2].totalmanNum;
- zYYADatas[0].totalVillageCount = zYYADatas[1].totalVillageCount + zYYADatas[2].totalVillageCount;
- zYYADatas[0].totalMaterialPrize = zYYADatas[1].totalMaterialPrize + zYYADatas[2].totalMaterialPrize;
- zYYADatas[0].totalRoadCount = zYYADatas[1].totalRoadCount + zYYADatas[2].totalRoadCount;
- zYYADatas[3].totalmanNum = zYYADatas[4].totalmanNum + zYYADatas[5].totalmanNum;
- zYYADatas[3].totalVillageCount = zYYADatas[4].totalVillageCount + zYYADatas[5].totalVillageCount;
- zYYADatas[3].totalMaterialPrize = zYYADatas[4].totalMaterialPrize + zYYADatas[5].totalMaterialPrize;
- zYYADatas[3].totalRoadCount = zYYADatas[4].totalRoadCount + zYYADatas[5].totalRoadCount;
- RefreshZYYAData();
- }
-
- movePlans = new List<Thing1>();
- RectTransform title = Instantiate(title1);
- title.localScale = Vector3.one;
- title.SetParent(movePlanBeforeContent);
- RectTransform title2 = Instantiate(title1);
- title2.localScale = Vector3.one;
- title2.SetParent(movePlanAfterContent);
- List<ServerMovePlan> serverMovePlans = new List<ServerMovePlan>();
- for (int i = 0; i < beforeLinePaths.Count; i++)
- {
- int tempI = i;
- RectTransform plan = Instantiate(plan1);
- plan.SetParent(movePlanBeforeContent);
- Thing1 thing1 = plan.GetComponent<Thing1>();
- thing1.zyTime = ZYTime.Before;
- thing1.lineDir = beforeLinePaths[i].lineDir;
- thing1.bindLinePath = beforeLinePaths[i];
- thing1.GetComponent<Button>().onClick.AddListener(() =>
- {
- for (int i = 0; i < linePaths.Count; i++)
- {
- linePaths[i].gameObject.SetActive(false);
- }
- thing1.bindLinePath.gameObject.SetActive(true);
- });
- plan.localScale = Vector3.one;
- plan.GetChild(0).GetComponent<Text>().text = i.ToString();
- plan.GetChild(1).GetComponent<Text>().text = beforeLinePaths[i].startPos;
- plan.GetChild(2).GetComponent<Text>().text = beforeLinePaths[i].endPos;
- plan.GetChild(3).GetComponent<Text>().text = beforeLinePaths[i].manNum.ToString();
- plan.GetChild(4).GetComponent<Text>().text = beforeLinePaths[i].dateTime.ToString();
- movePlans.Add(thing1);
- }
- for (int i = 0; i < afterLinePaths.Count; i++)
- {
- RectTransform plan = Instantiate(plan1);
- plan.SetParent(movePlanAfterContent);
- Thing1 thing1 = plan.GetComponent<Thing1>();
- thing1.zyTime = ZYTime.After;
- thing1.lineDir = afterLinePaths[i].lineDir;
- thing1.bindLinePath = afterLinePaths[i];
- thing1.GetComponent<Button>().onClick.AddListener(() =>
- {
- for (int i = 0; i < linePaths.Count; i++)
- {
- linePaths[i].gameObject.SetActive(false);
- }
- thing1.bindLinePath.gameObject.SetActive(true);
- });
- plan.localScale = Vector3.one;
- plan.GetChild(0).GetComponent<Text>().text = i.ToString();
- plan.GetChild(1).GetComponent<Text>().text = afterLinePaths[i].startPos;
- plan.GetChild(2).GetComponent<Text>().text = afterLinePaths[i].endPos;
- plan.GetChild(3).GetComponent<Text>().text = afterLinePaths[i].manNum.ToString();
- plan.GetChild(4).GetComponent<Text>().text = afterLinePaths[i].dateTime.ToString();
- movePlans.Add(thing1);
- }
- movePlanAfterContent.gameObject.SetActive(false);
-
- }
- void ChangeLinePathChannel(int index) {
- switch (index)
- {
- case 0:
- for (int i = 0; i < linePaths.Count; i++)
- {
- linePaths[i].gameObject.SetActive(true);
- }
- break;
- case 1:
- for (int i = 0; i < linePaths.Count; i++)
- {
- if (linePaths[i].lineDir == LineDir.Out)
- linePaths[i].gameObject.SetActive(true);
- else
- linePaths[i].gameObject.SetActive(false);
- }
- break;
- case 2:
- for (int i = 0; i < linePaths.Count; i++)
- {
- if (linePaths[i].lineDir == LineDir.In)
- linePaths[i].gameObject.SetActive(true);
- else
- linePaths[i].gameObject.SetActive(false);
- }
- break;
- }
- }
- void RefreshZYYAData() {
- zYYAIndex = beforeAfterIndex * 3 + inOutIndex;
- zYYAText[0].text = zYYADatas[zYYAIndex].totalVillageCount.ToString();
- zYYAText[1].text = (zYYADatas[zYYAIndex].totalmanNum / 10000.0f).ToString("0.00");
- zYYAText[2].text = (zYYADatas[zYYAIndex].totalMaterialPrize / 100000000.0f).ToString("0.00");
- zYYAText[3].text = zYYADatas[zYYAIndex].totalRoadCount.ToString();
- }
- void InitButton() {
- beforeBtn.onClick.AddListener(() => {
- beforeAfterIndex = 0;
- beforeBtn.GetComponent<Image>().sprite = sprites[0];
- afterBtn.GetComponent<Image>().sprite = sprites[1];
- beforeC.gameObject.SetActive(true);
- afterC.gameObject.SetActive(false);
- movePlanBeforeContent.gameObject.SetActive(true);
- movePlanAfterContent.gameObject.SetActive(false);
- ChangeLinePathChannel(inOutIndex);
- RefreshZYYAData();
- });
- afterBtn.onClick.AddListener(() => {
- beforeAfterIndex = 1;
- beforeBtn.GetComponent<Image>().sprite = sprites[1];
- afterBtn.GetComponent<Image>().sprite = sprites[0];
- beforeC.gameObject.SetActive(false);
- afterC.gameObject.SetActive(true);
- movePlanBeforeContent.gameObject.SetActive(false);
- movePlanAfterContent.gameObject.SetActive(true);
- ChangeLinePathChannel(inOutIndex);
- RefreshZYYAData();
- });
- allInOut[0].onClick.AddListener(() =>
- {
- inOutIndex = 0;
- ChangeLinePathChannel(0);
- for (int i = 0; i < movePlans.Count; i++)
- {
- movePlans[i].gameObject.SetActive(true);
- }
- allInOut[0].gameObject.GetComponent<Image>().sprite = sprites[0];
- allInOut[1].gameObject.GetComponent<Image>().sprite = sprites[1];
- allInOut[2].gameObject.GetComponent<Image>().sprite = sprites[1];
- RefreshZYYAData();
- });
- allInOut[1].onClick.AddListener(() =>
- {
- inOutIndex = 1;
- ChangeLinePathChannel(1);
- for (int i = 0; i < movePlans.Count; i++)
- {
- if (movePlans[i].lineDir == LineDir.Out)
- movePlans[i].gameObject.SetActive(true);
- else
- movePlans[i].gameObject.SetActive(false);
- }
- allInOut[0].gameObject.GetComponent<Image>().sprite = sprites[1];
- allInOut[1].gameObject.GetComponent<Image>().sprite = sprites[0];
- allInOut[2].gameObject.GetComponent<Image>().sprite = sprites[1];
- RefreshZYYAData();
- });
- allInOut[2].onClick.AddListener(() =>
- {
- inOutIndex = 2;
- ChangeLinePathChannel(2);
- for (int i = 0; i < movePlans.Count; i++)
- {
- if (movePlans[i].lineDir == LineDir.In)
- movePlans[i].gameObject.SetActive(true);
- else
- movePlans[i].gameObject.SetActive(false);
- }
- allInOut[0].gameObject.GetComponent<Image>().sprite = sprites[1];
- allInOut[1].gameObject.GetComponent<Image>().sprite = sprites[1];
- allInOut[2].gameObject.GetComponent<Image>().sprite = sprites[0];
- RefreshZYYAData();
- });
- }
- void InitAllPath() {
- for (int i = 0; i < beforeC.childCount; i++)
- {
- if (beforeC.GetChild(i).GetComponent<LinePath>())
- {
- linePaths.Add(beforeC.GetChild(i).GetComponent<LinePath>());
- }
- }
- for (int i = 0; i < afterC.childCount; i++)
- {
- if (afterC.GetChild(i).GetComponent<LinePath>())
- {
- linePaths.Add(afterC.GetChild(i).GetComponent<LinePath>());
- }
- }
- }
- // Update is called once per frame
- void Update()
- {
- // 获取当前时间
- DateTime now = DateTime.Now;
- // 格式化时间字符串
- string timeString = now.ToString("yyyy/MM/dd HH:mm");
- // 将格式化的时间字符串设置到UI Text组件上
- timeText.text = timeString;
- }
- LinePath lastPath;
- private void FixedUpdate()
- {
- if (lineInfo.linePaths.Count > 0)
- {
- lineInfo.gameObject.SetActive(true);
- }
- else
- {
- lineInfo.gameObject.SetActive(false);
- }
- Ray ray = CameraManager.instance.secondCamera.ScreenPointToRay(Input.mousePosition);
- RaycastHit hit;
- if (Physics.Raycast(ray, out hit, 10000))
- {
- Debug.Log(hit.collider.gameObject.name);
- // 检查射线是否击中 LineRenderer 所在的物体
- if (hit.collider.transform.parent.GetComponent<LinePath>() != null)
- {
- if (lastPath != null && hit.collider.transform.parent.GetComponent<LinePath>() != lastPath) {
- lastPath.UnShow();
- }
- hit.collider.transform.parent.GetComponent<LinePath>().OnShow();
- lastPath = hit.collider.transform.parent.GetComponent<LinePath>();
- }
- else
- {
- if (lastPath)
- {
- lastPath.UnShow();
- lastPath = null;
- }
- }
- }
- else {
- if (lastPath)
- {
- lastPath.UnShow();
- lastPath = null;
- }
- }
- }
-
- }
|