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; [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 movePlans; public List movePlans; public List moveAttens; public static LineInfo lineInfoStatic; public Button beforeBtn; public Button afterBtn; public Button[] allInOut; public Transform beforeC; public Transform afterC; public List linePaths = new List(); 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 List allServerMovePlans = new List(); 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 = i.ToString(); plan.GetChild(1).GetComponent().text = moveAttens[i].title; plan.GetChild(2).GetComponent().text = moveAttens[i].pos; plan.GetChild(3).GetComponent().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 = 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() { bool successInternet = true; UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetGetMovePlans); await requestData.SendWebRequest(); zYYADatas = new ZYYAData[6] { new ZYYAData(), new ZYYAData() , new ZYYAData() , new ZYYAData() , new ZYYAData() , new ZYYAData() }; try { if (true) { Debug.LogWarning("RKZYLayer联网不成功,读本地缓存数据,原因:返request不成功"); successInternet = false; } else { JObject jsonObject = JObject.Parse(requestData.downloadHandler.text); // 提取data字段的值 JToken dataToken = jsonObject["data"]; JToken codeToken = jsonObject["code"]; if (codeToken.ToString() == "200") { allServerMovePlans = JsonConvert.DeserializeObject>(dataToken.ToString()); } else { successInternet = false; Debug.LogWarning("XHGKLayer联网不成功,读本地缓存数据,原因:返序列化失败"); } } } catch (Exception e) { successInternet = false; Debug.LogWarning("RKZYLayer联网不成功,读本地缓存数据,原因:" + e.ToString()); } if (!successInternet) { WWW www = new WWW(Application.streamingAssetsPath + "/moveplan.json"); await new UnityAsync.WaitUntil(() => { return www.isDone; }); allServerMovePlans = JsonConvert.DeserializeObject>(www.text); www.Dispose(); } int beforeIndex = 0; int afterIndex = 0; List beforeLinePaths = new List(); List afterLinePaths = new List(); GameObject shaPan = GameObject.FindGameObjectWithTag("ShaPan"); Transform runtimPointParent = shaPan.transform.GetChild(10); for (int i = 0; i < allServerMovePlans.Count; i++) { bool after = allServerMovePlans[i].isAfter; bool isOut = allServerMovePlans[i].isOut; if (!after) { LinePath linePath = Instantiate(linePathPrefab); linePath.transform.SetParent(beforeC); linePath.startPos = allServerMovePlans[i].from; Vector3 localPos = CoordinateConverter.GeoToUGUISmall(allServerMovePlans[i].fromLong, allServerMovePlans[i].fromLttd); Vector3 worldPos = runtimPointParent.TransformPoint(localPos); worldPos.z = -583; linePath.endPos = allServerMovePlans[i].to; Vector3 localPos1 = CoordinateConverter.GeoToUGUISmall(allServerMovePlans[i].toLong, allServerMovePlans[i].toLttd); Vector3 worldPos1 = runtimPointParent.TransformPoint(localPos1); worldPos1.z = -583; linePath.SetPath(worldPos, worldPos1); linePath.lineDir = isOut ? LineDir.Out : LineDir.In; linePath.linePathContent = allServerMovePlans[i].desc; linePath.manNum = allServerMovePlans[i].manNum; linePath.homeNum = allServerMovePlans[i].homeNum; linePath.completeNum = allServerMovePlans[i].completeNum; linePath.dateTime = allServerMovePlans[i].dateTime; if (linePath.lineDir == LineDir.Out) { zYYADatas[1].totalmanNum += allServerMovePlans[i].manNum; zYYADatas[1].totalVillageCount += allServerMovePlans[i].villageCount; zYYADatas[1].totalMaterialPrize += allServerMovePlans[i].materialPrize; zYYADatas[1].totalRoadCount += 1; } else { zYYADatas[2].totalmanNum += allServerMovePlans[i].manNum; zYYADatas[2].totalVillageCount += allServerMovePlans[i].villageCount; zYYADatas[2].totalMaterialPrize += allServerMovePlans[i].materialPrize; zYYADatas[2].totalRoadCount += 1; } beforeLinePaths.Add(linePath); } else { LinePath linePath = Instantiate(linePathPrefab); linePath.transform.SetParent(afterC); linePath.startPos = allServerMovePlans[i].from; Vector3 localPos = CoordinateConverter.GeoToUGUISmall(allServerMovePlans[i].fromLong, allServerMovePlans[i].fromLttd); Vector3 worldPos = runtimPointParent.TransformPoint(localPos); worldPos.z = -583; linePath.endPos = allServerMovePlans[i].to; Vector3 localPos1 = CoordinateConverter.GeoToUGUISmall(allServerMovePlans[i].toLong, allServerMovePlans[i].toLttd); Vector3 worldPos1 = runtimPointParent.TransformPoint(localPos1); worldPos1.z = -583; linePath.SetPath(worldPos, worldPos1); linePath.lineDir = isOut ? LineDir.Out : LineDir.In; linePath.linePathContent = allServerMovePlans[i].desc; linePath.manNum = allServerMovePlans[i].manNum; linePath.homeNum = allServerMovePlans[i].homeNum; linePath.completeNum = allServerMovePlans[i].completeNum; linePath.dateTime = allServerMovePlans[i].dateTime; if (linePath.lineDir == LineDir.Out) { zYYADatas[4].totalmanNum += allServerMovePlans[i].manNum; zYYADatas[4].totalVillageCount += allServerMovePlans[i].villageCount; zYYADatas[4].totalMaterialPrize += allServerMovePlans[i].materialPrize; zYYADatas[4].totalRoadCount += 1; } else { zYYADatas[5].totalmanNum += allServerMovePlans[i].manNum; zYYADatas[5].totalVillageCount += allServerMovePlans[i].villageCount; zYYADatas[5].totalMaterialPrize += 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(); RectTransform title = Instantiate(title1); title.localScale = Vector3.one; title.SetParent(movePlanBeforeContent); RectTransform title2 = Instantiate(title1); title2.localScale = Vector3.one; title2.SetParent(movePlanAfterContent); List serverMovePlans = new List(); for (int i = 0; i < beforeLinePaths.Count; i++) { int tempI = i; RectTransform plan = Instantiate(plan1); plan.SetParent(movePlanBeforeContent); Thing1 thing1 = plan.GetComponent(); thing1.zyTime = ZYTime.Before; thing1.lineDir = beforeLinePaths[i].lineDir; thing1.bindLinePath = beforeLinePaths[i]; thing1.GetComponent