using Best.HTTP.Shared.Compression.Zlib; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System; using System.Collections; using System.Collections.Generic; using System.Drawing; using System.Text.RegularExpressions; using System.Threading.Tasks; using Unity.VisualScripting; using UnityAsync; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; using Color = UnityEngine.Color; 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 MovePath { public MovePath(double l1, double l2) { longitude = l1; latitude = l2; } public double longitude; public double latitude; } [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; public List paths = new List(); } [System.Serializable] public class ZYYAData { public int totalRoadCount; public float totalmanNum; public int totalVillageCount; public float totalMaterialPrize; } public class RKZYLayer : YZTRootLayer { public static float lineOrderZ = 0.01f; 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 Text[] zYGKText; public ZYYAData[] zYYADatas; public int zYYAIndex = 0; public Text[] zYYAText; public Material afterMat; public LinePathUnit linePathUnitPrefab; public LinePath linePathPrefab; public RectTransform startPos; public RectTransform endPos; public RectTransform pathSign; public int page = 0; public List allFilterPlans = new List(); [Header("计算面板和三个新加的按钮")] public GameObject calculatePanel; public Button closeCalculateButton; public Text lineNameText; public Text lineStarToEndText; public InputField peopleCountText; public InputField tunTuText; public InputField zhuangZaiText; public InputField moveTimeText; public Button allLineButton; public Button calculateShowButton; public Button showMoveButton; public GameObject calcMask; public Button calcTimeBtn; public Button resetTimeBtn; private bool calcOpen = true; public InputField searchPath; public Thing1 currentPath; // Start is called before the first frame update async void Start() { GameObject shaPan = GameObject.FindGameObjectWithTag("ShaPan"); beforeC.gameObject.SetActive(true); beforeC = shaPan.transform.GetChild(12); afterC = shaPan.transform.GetChild(13); 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); if(page == 0) beforeC.gameObject.SetActive(true); else afterC.gameObject.SetActive(true); } 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 = 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 beforeLinePaths = new List(); List afterLinePaths = new List(); GameObject shaPan = GameObject.FindGameObjectWithTag("ShaPan"); Transform runtimPointParent = shaPan.transform.GetChild(12); for (int i = 0; i < GlobalData.allServerMovePlans.Count; i++) { bool after = GlobalData.allServerMovePlans[i].isAfter; bool isOut = GlobalData.allServerMovePlans[i].isOut; if (!after) { LinePath lineParent = Instantiate(linePathPrefab); lineParent.transform.SetParent(beforeC); float clolorLerpUnit = 1.0f / (GlobalData.allServerMovePlans[i].paths.Count - 1); for (int j = 0; j < GlobalData.allServerMovePlans[i].paths.Count - 1; j++) { LinePathUnit linePath = Instantiate(linePathUnitPrefab); linePath.transform.SetParent(lineParent.transform); Vector3 localPos = CoordinateConverter.GeoToUGUISmall(GlobalData.allServerMovePlans[i].paths[j].longitude, GlobalData.allServerMovePlans[i].paths[j].latitude); Vector3 worldPos = runtimPointParent.TransformPoint(localPos); worldPos.z = -583; Vector3 localPos1 = CoordinateConverter.GeoToUGUISmall(GlobalData.allServerMovePlans[i].paths[j + 1].longitude, GlobalData.allServerMovePlans[i].paths[j + 1].latitude); Vector3 worldPos1 = runtimPointParent.TransformPoint(localPos1); worldPos1.z = -583; linePath.SetPath(worldPos, worldPos1); linePath.SetColor(Color.Lerp(Color.yellow, Color.red, j * clolorLerpUnit), Color.Lerp(Color.yellow, Color.red, (j + 1) * clolorLerpUnit)); if (j == 0) { RectTransform startSign = Instantiate(startPos); startSign.SetParent(pathSign); startSign.transform.localScale = Vector3.one; startSign.GetComponent().bindObj = linePath.gameObject; startSign.GetComponent().bindPos = worldPos; } if (j == GlobalData.allServerMovePlans[i].paths.Count - 2) { RectTransform endSign = Instantiate(endPos); endSign.SetParent(pathSign); endSign.transform.localScale = Vector3.one; endSign.GetComponent().bindObj = linePath.gameObject; endSign.GetComponent().bindPos = worldPos1; } } lineParent.startPos = GlobalData.allServerMovePlans[i].from; lineParent.endPos = GlobalData.allServerMovePlans[i].to; lineParent.lineDir = isOut ? LineDir.Out : LineDir.In; lineParent.linePathContent = GlobalData.allServerMovePlans[i].desc; lineParent.manNum = GlobalData.allServerMovePlans[i].manNum; lineParent.homeNum = GlobalData.allServerMovePlans[i].homeNum; lineParent.completeNum = GlobalData.allServerMovePlans[i].completeNum; lineParent.dateTime = GlobalData.allServerMovePlans[i].dateTime; lineParent.xishu = UnityEngine.Random.Range(10f, 30.0f); if (lineParent.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; } lineParent.transform.localPosition = new Vector3(lineParent.transform.localPosition.x, lineParent.transform.localPosition.y, lineOrderZ); lineOrderZ += 0.01f; beforeLinePaths.Add(lineParent); } else { LinePath lineParent = Instantiate(linePathPrefab); lineParent.transform.SetParent(afterC); float clolorLerpUnit = 1.0f / (GlobalData.allServerMovePlans[i].paths.Count - 1); for (int j = 0; j < GlobalData.allServerMovePlans[i].paths.Count - 1; j++) { LinePathUnit linePath = Instantiate(linePathUnitPrefab); linePath.transform.SetParent(lineParent.transform); Vector3 localPos = CoordinateConverter.GeoToUGUISmall(GlobalData.allServerMovePlans[i].paths[j].longitude, GlobalData.allServerMovePlans[i].paths[j].latitude); Vector3 worldPos = runtimPointParent.TransformPoint(localPos); worldPos.z = -583; Vector3 localPos1 = CoordinateConverter.GeoToUGUISmall(GlobalData.allServerMovePlans[i].paths[j + 1].longitude, GlobalData.allServerMovePlans[i].paths[j + 1].latitude); Vector3 worldPos1 = runtimPointParent.TransformPoint(localPos1); worldPos1.z = -583; linePath.SetPath(worldPos, worldPos1); linePath.SetColor(Color.Lerp(Color.yellow, Color.red, j * clolorLerpUnit), Color.Lerp(Color.yellow, Color.red, (j + 1) * clolorLerpUnit)); if (j == 0) { RectTransform startSign = Instantiate(startPos); startSign.SetParent(pathSign); startSign.transform.localScale = Vector3.one; startSign.GetComponent().bindObj = linePath.gameObject; startSign.GetComponent().bindPos = worldPos; } if (j == GlobalData.allServerMovePlans[i].paths.Count - 2) { RectTransform endSign = Instantiate(endPos); endSign.SetParent(pathSign); endSign.transform.localScale = Vector3.one; endSign.GetComponent().bindObj = linePath.gameObject; endSign.GetComponent().bindPos = worldPos1; } } lineParent.startPos = GlobalData.allServerMovePlans[i].from; lineParent.endPos = GlobalData.allServerMovePlans[i].to; lineParent.lineDir = isOut ? LineDir.Out : LineDir.In; lineParent.linePathContent = GlobalData.allServerMovePlans[i].desc; lineParent.manNum = GlobalData.allServerMovePlans[i].manNum; lineParent.homeNum = GlobalData.allServerMovePlans[i].homeNum; lineParent.completeNum = GlobalData.allServerMovePlans[i].completeNum; lineParent.dateTime = GlobalData.allServerMovePlans[i].dateTime; lineParent.xishu = UnityEngine.Random.Range(10f, 30.0f); if (lineParent.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; } lineParent.transform.localPosition = new Vector3(lineParent.transform.localPosition.x, lineParent.transform.localPosition.y, lineOrderZ); lineOrderZ += 0.01f; afterLinePaths.Add(lineParent); } 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