RKZYLayer.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. using Best.HTTP.Shared.Compression.Zlib;
  2. using Newtonsoft.Json;
  3. using Newtonsoft.Json.Linq;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using System.Drawing;
  8. using System.Text.RegularExpressions;
  9. using System.Threading.Tasks;
  10. using Unity.VisualScripting;
  11. using UnityAsync;
  12. using UnityEngine;
  13. using UnityEngine.Networking;
  14. using UnityEngine.UI;
  15. using Color = UnityEngine.Color;
  16. using WaitUntil = UnityAsync.WaitUntil;
  17. [System.Serializable]
  18. public class MovePlan
  19. {
  20. public string startPos;
  21. public string endPos;
  22. public int humanNum;
  23. public string time;
  24. }
  25. [System.Serializable]
  26. public class MoveAtten
  27. {
  28. public string title;
  29. public string pos;
  30. public string time;
  31. }
  32. [System.Serializable]
  33. public class MovePath
  34. {
  35. public MovePath(double l1, double l2)
  36. {
  37. longitude = l1;
  38. latitude = l2;
  39. }
  40. public double longitude;
  41. public double latitude;
  42. }
  43. [System.Serializable]
  44. public class ServerMovePlan {
  45. public bool isAfter;
  46. public bool isOut;
  47. public string desc;
  48. public string from;
  49. public float fromLong;
  50. public float fromLttd;
  51. public string to;
  52. public float toLong;
  53. public float toLttd;
  54. public int manNum;
  55. public int homeNum;
  56. public int completeNum;
  57. public string dateTime;
  58. public int villageCount;
  59. public int carNum;
  60. public List<MovePath> paths = new List<MovePath>();
  61. }
  62. [System.Serializable]
  63. public class ZYYAData
  64. {
  65. public int totalRoadCount;
  66. public float totalmanNum;
  67. public int totalVillageCount;
  68. public float totalCarNum;
  69. }
  70. public class RKZYLayer : YZTRootLayer
  71. {
  72. public static float lineOrderZ = 0.01f;
  73. public Text timeText;
  74. public LineInfo lineInfo;
  75. //public List<MovePlan> movePlans;
  76. public List<Thing1> movePlans;
  77. public List<MoveAtten> moveAttens;
  78. public static LineInfo lineInfoStatic;
  79. public Button beforeBtn;
  80. public Button afterBtn;
  81. public Button[] allInOut;
  82. public Transform beforeC;
  83. public Transform afterC;
  84. public List<LinePath> linePaths = new List<LinePath>();
  85. public Sprite[] sprites;
  86. public int inOutIndex;
  87. public int beforeAfterIndex;
  88. public RectTransform title1;
  89. public RectTransform plan1;
  90. public RectTransform movePlanBeforeContent;
  91. public RectTransform movePlanAfterContent;
  92. public RectTransform title2;
  93. public RectTransform plan2;
  94. public RectTransform attenContent;
  95. public Text[] zYGKText;
  96. public ZYYAData[] zYYADatas;
  97. public int zYYAIndex = 0;
  98. public Text[] zYYAText;
  99. public Material afterMat;
  100. public LinePathUnit linePathUnitPrefab;
  101. public LinePath linePathPrefab;
  102. public RectTransform startPos;
  103. public RectTransform endPos;
  104. public RectTransform pathSign;
  105. public int page = 0;
  106. public List<Thing1> allFilterPlans = new List<Thing1>();
  107. [Header("计算面板和三个新加的按钮")]
  108. public GameObject calculatePanel;
  109. public Button closeCalculateButton;
  110. public Text lineNameText;
  111. public Text lineStarToEndText;
  112. public InputField peopleCountText;
  113. public InputField tunTuText;
  114. public InputField zhuangZaiText;
  115. public InputField moveTimeText;
  116. public Button allLineButton;
  117. public Button calculateShowButton;
  118. public Button showMoveButton;
  119. public GameObject calcMask;
  120. public Button calcTimeBtn;
  121. public Button resetTimeBtn;
  122. private bool calcOpen = true;
  123. public InputField searchPath;
  124. public Thing1 currentPath;
  125. // Start is called before the first frame update
  126. async void Start()
  127. {
  128. GameObject shaPan = GameObject.FindGameObjectWithTag("ShaPan");
  129. beforeC.gameObject.SetActive(true);
  130. beforeC = shaPan.transform.GetChild(12);
  131. afterC = shaPan.transform.GetChild(13);
  132. lineInfoStatic = lineInfo;
  133. await InitMovePlan();
  134. //TODO 这一块的path应该从movePlan里面生成而不是默认
  135. InitAllPath();
  136. InitButton();
  137. InitAtten();
  138. await InitBaseData();
  139. }
  140. public override void OnUILeave()
  141. {
  142. base.OnUILeave();
  143. beforeC.gameObject.SetActive(false);
  144. afterC.gameObject.SetActive(false);
  145. }
  146. private void OnEnable()
  147. {
  148. CameraManager.SwitchCamera(1);
  149. if(page == 0)
  150. beforeC.gameObject.SetActive(true);
  151. else
  152. afterC.gameObject.SetActive(true);
  153. }
  154. void InitAtten() {
  155. RectTransform title = Instantiate(title2);
  156. title.SetParent(attenContent);
  157. title.localScale = Vector3.one;
  158. for (int i = 0; i < moveAttens.Count; i++)
  159. {
  160. RectTransform plan = Instantiate(plan2);
  161. plan.SetParent(attenContent);
  162. plan.localScale = Vector3.one;
  163. plan.GetChild(0).GetComponent<Text>().text = i.ToString();
  164. plan.GetChild(1).GetComponent<Text>().text = moveAttens[i].title;
  165. plan.GetChild(2).GetComponent<Text>().text = moveAttens[i].pos;
  166. plan.GetChild(3).GetComponent<Text>().text = moveAttens[i].time;
  167. }
  168. }
  169. async Task InitBaseData() {
  170. bool successInternet = true;
  171. UnityWebRequest requestData = UnityWebRequest.Get(ServerAddress.APIGetGeBaseData);
  172. await requestData.SendWebRequest();
  173. try
  174. {
  175. if (requestData.result != UnityWebRequest.Result.Success)
  176. {
  177. Debug.LogWarning("RKZYLayer基础数据联网不成功,原因:返request不成功");
  178. successInternet = false;
  179. }
  180. else
  181. {
  182. JObject jsonObject = JObject.Parse(requestData.downloadHandler.text);
  183. JToken codeToken = jsonObject["code"];
  184. if (codeToken.ToString() == "200")
  185. {
  186. JToken areaToken = jsonObject["data"]["area"];
  187. JToken capacityToken = jsonObject["data"]["capacity"];
  188. JToken populationToken = jsonObject["data"]["population"];
  189. zYGKText[0].text = populationToken.ToString() + "人";
  190. zYGKText[1].text = GlobalData.allServerMovePlans.Count.ToString() + "条";
  191. zYGKText[2].text = areaToken.ToString() + "km²";
  192. zYGKText[3].text = (float.Parse((capacityToken.ToString())) * 100).ToString() + "%";
  193. }
  194. else
  195. {
  196. successInternet = false;
  197. Debug.LogWarning("RKZYLayer基础数据联网不成功,原因:返序列化失败");
  198. }
  199. }
  200. }
  201. catch (Exception e)
  202. {
  203. successInternet = false;
  204. Debug.LogWarning("RKZYLayer基础数据联网不成功,原因:" + e.ToString());
  205. }
  206. }
  207. async Task InitMovePlan() {
  208. zYYADatas = new ZYYAData[6] { new ZYYAData(), new ZYYAData() , new ZYYAData() , new ZYYAData() , new ZYYAData() , new ZYYAData() };
  209. await new WaitUntil(() =>
  210. {
  211. return GlobalData.allServerMovePlans.Count > 0;
  212. });
  213. int beforeIndex = 0;
  214. int afterIndex = 0;
  215. List<LinePath> beforeLinePaths = new List<LinePath>();
  216. List<LinePath> afterLinePaths = new List<LinePath>();
  217. GameObject shaPan = GameObject.FindGameObjectWithTag("ShaPan");
  218. Transform runtimPointParent = shaPan.transform.GetChild(12);
  219. for (int i = 0; i < GlobalData.allServerMovePlans.Count; i++) {
  220. bool after = GlobalData.allServerMovePlans[i].isAfter;
  221. bool isOut = GlobalData.allServerMovePlans[i].isOut;
  222. if (!after)
  223. {
  224. LinePath lineParent = Instantiate(linePathPrefab);
  225. lineParent.transform.SetParent(beforeC);
  226. float clolorLerpUnit = 1.0f / (GlobalData.allServerMovePlans[i].paths.Count - 1);
  227. for (int j = 0; j < GlobalData.allServerMovePlans[i].paths.Count - 1; j++)
  228. {
  229. LinePathUnit linePath = Instantiate(linePathUnitPrefab);
  230. linePath.transform.SetParent(lineParent.transform);
  231. Vector3 localPos = CoordinateConverter.GeoToUGUISmall(GlobalData.allServerMovePlans[i].paths[j].longitude, GlobalData.allServerMovePlans[i].paths[j].latitude);
  232. Vector3 worldPos = runtimPointParent.TransformPoint(localPos);
  233. worldPos.z = -583;
  234. Vector3 localPos1 = CoordinateConverter.GeoToUGUISmall(GlobalData.allServerMovePlans[i].paths[j + 1].longitude, GlobalData.allServerMovePlans[i].paths[j + 1].latitude);
  235. Vector3 worldPos1 = runtimPointParent.TransformPoint(localPos1);
  236. worldPos1.z = -583;
  237. linePath.SetPath(worldPos, worldPos1);
  238. linePath.SetColor(Color.Lerp(Color.yellow, Color.red, j * clolorLerpUnit), Color.Lerp(Color.yellow, Color.red, (j + 1) * clolorLerpUnit));
  239. //linePath.SetColor(Color.red, Color.red);
  240. if (j == 0)
  241. {
  242. RectTransform startSign = Instantiate(startPos);
  243. startSign.SetParent(pathSign);
  244. startSign.transform.localScale = Vector3.one;
  245. startSign.GetComponent<PathSign>().SetIndex(beforeLinePaths.Count);
  246. int temp = beforeLinePaths.Count;
  247. startSign.GetComponentInChildren<Button>().onClick.AddListener(() =>
  248. {
  249. for (int i = 0; i < linePaths.Count; i++)
  250. {
  251. linePaths[i].gameObject.SetActive(false);
  252. }
  253. beforeLinePaths[temp].gameObject.SetActive(true);
  254. for (int k = 0; k < movePlans.Count; k++) {
  255. if (movePlans[k].bindLinePath == beforeLinePaths[temp]) {
  256. CheckCalcUsable(movePlans[k]);
  257. }
  258. }
  259. });
  260. startSign.GetComponent<PathSign>().bindObj = linePath.gameObject;
  261. startSign.GetComponent<PathSign>().bindPos = worldPos;
  262. }
  263. if (j == GlobalData.allServerMovePlans[i].paths.Count - 2)
  264. {
  265. RectTransform endSign = Instantiate(endPos);
  266. endSign.SetParent(pathSign);
  267. endSign.transform.localScale = Vector3.one;
  268. endSign.GetComponent<PathSign>().SetIndex(beforeLinePaths.Count);
  269. endSign.GetComponent<PathSign>().bindObj = linePath.gameObject;
  270. endSign.GetComponent<PathSign>().bindPos = worldPos1;
  271. }
  272. }
  273. lineParent.startPos = GlobalData.allServerMovePlans[i].from;
  274. lineParent.endPos = GlobalData.allServerMovePlans[i].to;
  275. lineParent.lineDir = isOut ? LineDir.Out : LineDir.In;
  276. lineParent.linePathContent = GlobalData.allServerMovePlans[i].desc;
  277. lineParent.manNum = GlobalData.allServerMovePlans[i].manNum;
  278. lineParent.homeNum = GlobalData.allServerMovePlans[i].homeNum;
  279. lineParent.completeNum = GlobalData.allServerMovePlans[i].completeNum;
  280. lineParent.carNum = GlobalData.allServerMovePlans[i].carNum.ToString();
  281. lineParent.xishu = UnityEngine.Random.Range(10f, 30.0f);
  282. if (lineParent.lineDir == LineDir.Out)
  283. {
  284. zYYADatas[1].totalmanNum += GlobalData.allServerMovePlans[i].manNum;
  285. zYYADatas[1].totalVillageCount += GlobalData.allServerMovePlans[i].villageCount;
  286. zYYADatas[1].totalCarNum += GlobalData.allServerMovePlans[i].carNum;
  287. zYYADatas[1].totalRoadCount += 1;
  288. }
  289. else
  290. {
  291. zYYADatas[2].totalmanNum += GlobalData.allServerMovePlans[i].manNum;
  292. zYYADatas[2].totalVillageCount += GlobalData.allServerMovePlans[i].villageCount;
  293. zYYADatas[2].totalCarNum += GlobalData.allServerMovePlans[i].carNum;
  294. zYYADatas[2].totalRoadCount += 1;
  295. }
  296. lineParent.transform.localPosition = new Vector3(lineParent.transform.localPosition.x, lineParent.transform.localPosition.y, lineOrderZ);
  297. lineOrderZ += 0.01f;
  298. beforeLinePaths.Add(lineParent);
  299. }
  300. else
  301. {
  302. LinePath lineParent = Instantiate(linePathPrefab);
  303. lineParent.transform.SetParent(afterC);
  304. float clolorLerpUnit = 1.0f / (GlobalData.allServerMovePlans[i].paths.Count - 1);
  305. for (int j = 0; j < GlobalData.allServerMovePlans[i].paths.Count - 1; j++)
  306. {
  307. LinePathUnit linePath = Instantiate(linePathUnitPrefab);
  308. linePath.transform.SetParent(lineParent.transform);
  309. Vector3 localPos = CoordinateConverter.GeoToUGUISmall(GlobalData.allServerMovePlans[i].paths[j].longitude, GlobalData.allServerMovePlans[i].paths[j].latitude);
  310. Vector3 worldPos = runtimPointParent.TransformPoint(localPos);
  311. worldPos.z = -583;
  312. Vector3 localPos1 = CoordinateConverter.GeoToUGUISmall(GlobalData.allServerMovePlans[i].paths[j + 1].longitude, GlobalData.allServerMovePlans[i].paths[j + 1].latitude);
  313. Vector3 worldPos1 = runtimPointParent.TransformPoint(localPos1);
  314. worldPos1.z = -583;
  315. linePath.SetPath(worldPos, worldPos1);
  316. //linePath.SetColor(Color.Lerp(Color.yellow, Color.red, j * clolorLerpUnit), Color.Lerp(Color.yellow, Color.red, (j + 1) * clolorLerpUnit));
  317. linePath.SetColor(Color.red, Color.red);
  318. if (j == 0)
  319. {
  320. RectTransform startSign = Instantiate(startPos);
  321. startSign.SetParent(pathSign);
  322. startSign.transform.localScale = Vector3.one;
  323. startSign.GetComponent<PathSign>().SetIndex(afterLinePaths.Count);
  324. int temp = afterLinePaths.Count;
  325. startSign.GetComponentInChildren<Button>().onClick.AddListener(() =>
  326. {
  327. for (int i = 0; i < linePaths.Count; i++)
  328. {
  329. linePaths[i].gameObject.SetActive(false);
  330. }
  331. afterLinePaths[temp].gameObject.SetActive(true);
  332. for (int k = 0; k < movePlans.Count; k++)
  333. {
  334. if (movePlans[k].bindLinePath == afterLinePaths[temp])
  335. {
  336. CheckCalcUsable(movePlans[k]);
  337. }
  338. }
  339. });
  340. startSign.GetComponent<PathSign>().bindObj = linePath.gameObject;
  341. startSign.GetComponent<PathSign>().bindPos = worldPos;
  342. }
  343. if (j == GlobalData.allServerMovePlans[i].paths.Count - 2)
  344. {
  345. RectTransform endSign = Instantiate(endPos);
  346. endSign.SetParent(pathSign);
  347. endSign.transform.localScale = Vector3.one;
  348. endSign.GetComponent<PathSign>().SetIndex(afterLinePaths.Count);
  349. endSign.GetComponent<PathSign>().bindObj = linePath.gameObject;
  350. endSign.GetComponent<PathSign>().bindPos = worldPos1;
  351. }
  352. }
  353. lineParent.startPos = GlobalData.allServerMovePlans[i].from;
  354. lineParent.endPos = GlobalData.allServerMovePlans[i].to;
  355. lineParent.lineDir = isOut ? LineDir.Out : LineDir.In;
  356. lineParent.linePathContent = GlobalData.allServerMovePlans[i].desc;
  357. lineParent.manNum = GlobalData.allServerMovePlans[i].manNum;
  358. lineParent.homeNum = GlobalData.allServerMovePlans[i].homeNum;
  359. lineParent.completeNum = GlobalData.allServerMovePlans[i].completeNum;
  360. lineParent.carNum = GlobalData.allServerMovePlans[i].carNum.ToString();
  361. lineParent.xishu = UnityEngine.Random.Range(10f, 30.0f);
  362. if (lineParent.lineDir == LineDir.Out)
  363. {
  364. zYYADatas[4].totalmanNum += GlobalData.allServerMovePlans[i].manNum;
  365. zYYADatas[4].totalVillageCount += GlobalData.allServerMovePlans[i].villageCount;
  366. zYYADatas[4].totalCarNum += GlobalData.allServerMovePlans[i].carNum;
  367. zYYADatas[4].totalRoadCount += 1;
  368. }
  369. else
  370. {
  371. zYYADatas[5].totalmanNum += GlobalData.allServerMovePlans[i].manNum;
  372. zYYADatas[5].totalVillageCount += GlobalData.allServerMovePlans[i].villageCount;
  373. zYYADatas[5].totalCarNum += GlobalData.allServerMovePlans[i].carNum;
  374. zYYADatas[5].totalRoadCount += 1;
  375. }
  376. lineParent.transform.localPosition = new Vector3(lineParent.transform.localPosition.x, lineParent.transform.localPosition.y, lineOrderZ);
  377. lineOrderZ += 0.01f;
  378. afterLinePaths.Add(lineParent);
  379. }
  380. zYYADatas[0].totalmanNum = zYYADatas[1].totalmanNum + zYYADatas[2].totalmanNum;
  381. zYYADatas[0].totalVillageCount = zYYADatas[1].totalVillageCount + zYYADatas[2].totalVillageCount;
  382. zYYADatas[0].totalCarNum = zYYADatas[1].totalCarNum + zYYADatas[2].totalCarNum;
  383. zYYADatas[0].totalRoadCount = zYYADatas[1].totalRoadCount + zYYADatas[2].totalRoadCount;
  384. //Debug.LogError(zYYADatas[1].totalmanNum);
  385. //Debug.LogError(zYYADatas[2].totalmanNum);
  386. //Debug.LogError(zYYADatas[1].totalVillageCount);
  387. //Debug.LogError(zYYADatas[2].totalVillageCount);
  388. //Debug.LogError(zYYADatas[1].totalMaterialPrize);
  389. //Debug.LogError(zYYADatas[2].totalMaterialPrize);
  390. //Debug.LogError(zYYADatas[1].totalRoadCount);
  391. //Debug.LogError(zYYADatas[2].totalRoadCount);
  392. zYYADatas[3].totalmanNum = zYYADatas[4].totalmanNum + zYYADatas[5].totalmanNum;
  393. zYYADatas[3].totalVillageCount = zYYADatas[4].totalVillageCount + zYYADatas[5].totalVillageCount;
  394. zYYADatas[3].totalCarNum = zYYADatas[4].totalCarNum + zYYADatas[5].totalCarNum;
  395. zYYADatas[3].totalRoadCount = zYYADatas[4].totalRoadCount + zYYADatas[5].totalRoadCount;
  396. RefreshZYYAData();
  397. }
  398. movePlans = new List<Thing1>();
  399. RectTransform title = Instantiate(title1);
  400. title.localScale = Vector3.one;
  401. title.SetParent(movePlanBeforeContent);
  402. RectTransform title2 = Instantiate(title1);
  403. title2.localScale = Vector3.one;
  404. title2.SetParent(movePlanAfterContent);
  405. List<ServerMovePlan> serverMovePlans = new List<ServerMovePlan>();
  406. for (int i = 0; i < beforeLinePaths.Count; i++)
  407. {
  408. int tempI = i;
  409. RectTransform plan = Instantiate(plan1);
  410. plan.SetParent(movePlanBeforeContent);
  411. Thing1 thing1 = plan.GetComponent<Thing1>();
  412. thing1.zyTime = ZYTime.Before;
  413. thing1.lineDir = beforeLinePaths[i].lineDir;
  414. thing1.bindLinePath = beforeLinePaths[i];
  415. thing1.GetComponent<Button>().onClick.AddListener(() =>
  416. {
  417. for (int i = 0; i < linePaths.Count; i++)
  418. {
  419. linePaths[i].gameObject.SetActive(false);
  420. }
  421. thing1.bindLinePath.gameObject.SetActive(true);
  422. CheckCalcUsable(thing1);
  423. });
  424. plan.localScale = Vector3.one;
  425. plan.GetChild(0).GetComponent<Text>().text = i.ToString();
  426. plan.GetChild(1).GetComponent<Text>().text = beforeLinePaths[i].startPos;
  427. plan.GetChild(2).GetComponent<Text>().text = beforeLinePaths[i].endPos;
  428. plan.GetChild(3).GetComponent<Text>().text = beforeLinePaths[i].manNum.ToString();
  429. plan.GetChild(4).GetComponent<Text>().text = beforeLinePaths[i].carNum.ToString() + "辆";
  430. movePlans.Add(thing1);
  431. }
  432. for (int i = 0; i < afterLinePaths.Count; i++)
  433. {
  434. RectTransform plan = Instantiate(plan1);
  435. plan.SetParent(movePlanAfterContent);
  436. Thing1 thing1 = plan.GetComponent<Thing1>();
  437. thing1.zyTime = ZYTime.After;
  438. thing1.lineDir = afterLinePaths[i].lineDir;
  439. thing1.bindLinePath = afterLinePaths[i];
  440. thing1.GetComponent<Button>().onClick.AddListener(() =>
  441. {
  442. for (int i = 0; i < linePaths.Count; i++)
  443. {
  444. linePaths[i].gameObject.SetActive(false);
  445. }
  446. thing1.bindLinePath.gameObject.SetActive(true);
  447. CheckCalcUsable(thing1);
  448. });
  449. plan.localScale = Vector3.one;
  450. plan.GetChild(0).GetComponent<Text>().text = i.ToString();
  451. plan.GetChild(1).GetComponent<Text>().text = afterLinePaths[i].startPos;
  452. plan.GetChild(2).GetComponent<Text>().text = afterLinePaths[i].endPos;
  453. plan.GetChild(3).GetComponent<Text>().text = afterLinePaths[i].manNum.ToString();
  454. plan.GetChild(4).GetComponent<Text>().text = afterLinePaths[i].carNum.ToString() + "辆";
  455. movePlans.Add(thing1);
  456. }
  457. movePlanAfterContent.gameObject.SetActive(false);
  458. }
  459. void CheckCalcUsable(Thing1 thing1 = null) {
  460. currentPath = thing1;
  461. if (currentPath != null)
  462. {
  463. calcMask.gameObject.SetActive(false);
  464. peopleCountText.text = currentPath.bindLinePath.manNum.ToString();
  465. lineNameText.text = currentPath.bindLinePath.lineDir == LineDir.In ? "内转安置" : "外传安置";
  466. lineStarToEndText.text = currentPath.bindLinePath.startPos + "→ " + currentPath.bindLinePath.endPos;
  467. moveTimeText.text = "待计算";
  468. tunTuText.text = currentPath.bindLinePath.xishu.ToString();
  469. }
  470. else {
  471. calcMask.gameObject.SetActive(true);
  472. }
  473. }
  474. void ChangeLinePathChannel(int index) {
  475. switch (index)
  476. {
  477. case 0:
  478. for (int i = 0; i < linePaths.Count; i++)
  479. {
  480. linePaths[i].gameObject.SetActive(true);
  481. }
  482. break;
  483. case 1:
  484. for (int i = 0; i < linePaths.Count; i++)
  485. {
  486. if (linePaths[i].lineDir == LineDir.Out)
  487. linePaths[i].gameObject.SetActive(true);
  488. else
  489. linePaths[i].gameObject.SetActive(false);
  490. }
  491. break;
  492. case 2:
  493. for (int i = 0; i < linePaths.Count; i++)
  494. {
  495. if (linePaths[i].lineDir == LineDir.In)
  496. linePaths[i].gameObject.SetActive(true);
  497. else
  498. linePaths[i].gameObject.SetActive(false);
  499. }
  500. break;
  501. }
  502. }
  503. void RefreshZYYAData() {
  504. zYYAIndex = beforeAfterIndex * 3 + inOutIndex;
  505. zYYAText[0].text = zYYADatas[zYYAIndex].totalVillageCount.ToString();
  506. zYYAText[1].text = (zYYADatas[zYYAIndex].totalmanNum / 10000.0f).ToString("0.00");
  507. zYYAText[2].text = (zYYADatas[zYYAIndex].totalCarNum).ToString();
  508. zYYAText[3].text = zYYADatas[zYYAIndex].totalRoadCount.ToString();
  509. }
  510. void BeforeBtnClick() {
  511. beforeAfterIndex = 0;
  512. beforeBtn.GetComponent<Image>().sprite = sprites[0];
  513. afterBtn.GetComponent<Image>().sprite = sprites[1];
  514. beforeC.gameObject.SetActive(true);
  515. afterC.gameObject.SetActive(false);
  516. movePlanBeforeContent.gameObject.SetActive(true);
  517. movePlanAfterContent.gameObject.SetActive(false);
  518. ChangeLinePathChannel(inOutIndex);
  519. RefreshZYYAData();
  520. page = 0;
  521. }
  522. void AfterBtnClick()
  523. {
  524. beforeAfterIndex = 1;
  525. beforeBtn.GetComponent<Image>().sprite = sprites[1];
  526. afterBtn.GetComponent<Image>().sprite = sprites[0];
  527. beforeC.gameObject.SetActive(false);
  528. afterC.gameObject.SetActive(true);
  529. movePlanBeforeContent.gameObject.SetActive(false);
  530. movePlanAfterContent.gameObject.SetActive(true);
  531. ChangeLinePathChannel(inOutIndex);
  532. RefreshZYYAData();
  533. page = 1;
  534. }
  535. void InitButton() {
  536. beforeBtn.onClick.AddListener(() => {
  537. BeforeBtnClick();
  538. });
  539. afterBtn.onClick.AddListener(() => {
  540. AfterBtnClick();
  541. });
  542. allLineButton.onClick.AddListener(() =>
  543. {
  544. ChangeLinePathChannel(inOutIndex);
  545. CheckCalcUsable();
  546. });
  547. calculateShowButton.onClick.AddListener(() =>
  548. {
  549. calcOpen = !calcOpen;
  550. if (calcOpen)
  551. {
  552. calculateShowButton.GetComponent<Image>().color = new UnityEngine.Color(1, 1, 1, 1f);
  553. calculatePanel.gameObject.SetActive(true);
  554. }
  555. else {
  556. calculateShowButton.GetComponent<Image>().color = new UnityEngine.Color(1, 1, 1, 0.5f);
  557. calculatePanel.gameObject.SetActive(false);
  558. }
  559. });
  560. searchPath.onValueChanged.AddListener((string searchItem) =>
  561. {
  562. allFilterPlans.Clear();
  563. for (int i = 0; i < movePlans.Count; i++)
  564. {
  565. if ((int)movePlans[i].bindLinePath.lineDir + 1 == inOutIndex || inOutIndex == 0)
  566. {
  567. if (searchItem.Trim().Length < 1)
  568. {
  569. movePlans[i].gameObject.SetActive(true);
  570. }
  571. else {
  572. if (movePlans[i].bindLinePath.startPos.Contains(searchItem) || movePlans[i].bindLinePath.endPos.Contains(searchItem))
  573. {
  574. movePlans[i].gameObject.SetActive(true);
  575. }
  576. else {
  577. movePlans[i].gameObject.SetActive(false);
  578. }
  579. }
  580. }
  581. else {
  582. movePlans[i].gameObject.SetActive(false);
  583. }
  584. }
  585. });
  586. calcTimeBtn.onClick.AddListener(() =>
  587. {
  588. int manNum = 1;
  589. int zzManNum = 1;
  590. float tuntu = 0;
  591. if (peopleCountText.text.Trim().Length < 1 || zhuangZaiText.text.Trim().Length < 1)
  592. {
  593. moveTimeText.text = "请输入数据";
  594. moveTimeText.transform.GetChild(2).GetComponent<Text>().color = Color.red;
  595. }
  596. else if (!int.TryParse(peopleCountText.text,out manNum) || !int.TryParse(zhuangZaiText.text, out zzManNum) ||
  597. !float.TryParse(tunTuText.text, out tuntu))
  598. {
  599. moveTimeText.text = "请检查数据";
  600. moveTimeText.transform.GetChild(2).GetComponent<Text>().color = Color.red;
  601. }
  602. else
  603. {
  604. moveTimeText.text = (manNum / tuntu / zzManNum).ToString("0.0") + "小时";
  605. moveTimeText.transform.GetChild(2).GetComponent<Text>().color = Color.white;
  606. }
  607. });
  608. resetTimeBtn.onClick.AddListener(() =>
  609. {
  610. peopleCountText.text = "";
  611. zhuangZaiText.text = "";
  612. moveTimeText.text = "待计算";
  613. });
  614. closeCalculateButton.onClick.AddListener(() =>
  615. {
  616. calculatePanel.gameObject.SetActive(false);
  617. calculateShowButton.GetComponent<Image>().color = new UnityEngine.Color(1, 1, 1, 0.5f);
  618. calcOpen = false;
  619. });
  620. allInOut[0].onClick.AddListener(() =>
  621. {
  622. inOutIndex = 0;
  623. ChangeLinePathChannel(0);
  624. for (int i = 0; i < movePlans.Count; i++)
  625. {
  626. movePlans[i].gameObject.SetActive(true);
  627. }
  628. allInOut[0].gameObject.GetComponent<Image>().sprite = sprites[0];
  629. allInOut[1].gameObject.GetComponent<Image>().sprite = sprites[1];
  630. allInOut[2].gameObject.GetComponent<Image>().sprite = sprites[1];
  631. RefreshZYYAData();
  632. CheckCalcUsable();
  633. });
  634. allInOut[1].onClick.AddListener(() =>
  635. {
  636. inOutIndex = 1;
  637. ChangeLinePathChannel(1);
  638. for (int i = 0; i < movePlans.Count; i++)
  639. {
  640. if (movePlans[i].lineDir == LineDir.Out)
  641. {
  642. movePlans[i].gameObject.SetActive(true);
  643. }
  644. else
  645. movePlans[i].gameObject.SetActive(false);
  646. }
  647. allInOut[0].gameObject.GetComponent<Image>().sprite = sprites[1];
  648. allInOut[1].gameObject.GetComponent<Image>().sprite = sprites[0];
  649. allInOut[2].gameObject.GetComponent<Image>().sprite = sprites[1];
  650. RefreshZYYAData();
  651. CheckCalcUsable();
  652. });
  653. allInOut[2].onClick.AddListener(() =>
  654. {
  655. inOutIndex = 2;
  656. ChangeLinePathChannel(2);
  657. for (int i = 0; i < movePlans.Count; i++)
  658. {
  659. if (movePlans[i].lineDir == LineDir.In)
  660. {
  661. movePlans[i].gameObject.SetActive(true);
  662. }
  663. else
  664. movePlans[i].gameObject.SetActive(false);
  665. }
  666. allInOut[0].gameObject.GetComponent<Image>().sprite = sprites[1];
  667. allInOut[1].gameObject.GetComponent<Image>().sprite = sprites[1];
  668. allInOut[2].gameObject.GetComponent<Image>().sprite = sprites[0];
  669. RefreshZYYAData();
  670. CheckCalcUsable();
  671. });
  672. BeforeBtnClick();
  673. }
  674. void InitAllPath() {
  675. for (int i = 0; i < beforeC.childCount; i++)
  676. {
  677. if (beforeC.GetChild(i).GetComponent<LinePath>())
  678. {
  679. linePaths.Add(beforeC.GetChild(i).GetComponent<LinePath>());
  680. }
  681. }
  682. for (int i = 0; i < afterC.childCount; i++)
  683. {
  684. if (afterC.GetChild(i).GetComponent<LinePath>())
  685. {
  686. linePaths.Add(afterC.GetChild(i).GetComponent<LinePath>());
  687. }
  688. }
  689. }
  690. // Update is called once per frame
  691. void Update()
  692. {
  693. // 获取当前时间
  694. DateTime now = DateTime.Now;
  695. // 格式化时间字符串
  696. string timeString = now.ToString("yyyy/MM/dd HH:mm");
  697. // 将格式化的时间字符串设置到UI Text组件上
  698. timeText.text = timeString;
  699. }
  700. LinePath lastPath;
  701. private void FixedUpdate()
  702. {
  703. if (lineInfo.linePaths.Count > 0)
  704. {
  705. lineInfo.gameObject.SetActive(true);
  706. }
  707. else
  708. {
  709. lineInfo.gameObject.SetActive(false);
  710. }
  711. Ray ray = CameraManager.instance.secondCamera.ScreenPointToRay(Input.mousePosition);
  712. RaycastHit hit;
  713. if (Physics.Raycast(ray, out hit, 10000))
  714. {
  715. Debug.Log(hit.collider.gameObject.name);
  716. // 检查射线是否击中 LineRenderer 所在的物体
  717. if (hit.collider.transform.parent.parent.GetComponent<LinePath>() != null)
  718. {
  719. if (lastPath != null && hit.collider.transform.parent.parent.GetComponent<LinePath>() != lastPath) {
  720. lastPath.UnShow();
  721. }
  722. hit.collider.transform.parent.parent.GetComponent<LinePath>().OnShow();
  723. lastPath = hit.collider.transform.parent.parent.GetComponent<LinePath>();
  724. }
  725. else
  726. {
  727. if (lastPath)
  728. {
  729. lastPath.UnShow();
  730. lastPath = null;
  731. }
  732. }
  733. }
  734. else {
  735. if (lastPath)
  736. {
  737. lastPath.UnShow();
  738. lastPath = null;
  739. }
  740. }
  741. }
  742. }