RKZYLayer.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  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 materialPrize;
  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 totalMaterialPrize;
  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.dateTime = GlobalData.allServerMovePlans[i].dateTime;
  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].totalMaterialPrize += GlobalData.allServerMovePlans[i].materialPrize;
  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].totalMaterialPrize += GlobalData.allServerMovePlans[i].materialPrize;
  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.dateTime = GlobalData.allServerMovePlans[i].dateTime;
  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].totalMaterialPrize += GlobalData.allServerMovePlans[i].materialPrize;
  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].totalMaterialPrize += GlobalData.allServerMovePlans[i].materialPrize;
  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].totalMaterialPrize = zYYADatas[1].totalMaterialPrize + zYYADatas[2].totalMaterialPrize;
  383. zYYADatas[0].totalRoadCount = zYYADatas[1].totalRoadCount + zYYADatas[2].totalRoadCount;
  384. zYYADatas[3].totalmanNum = zYYADatas[4].totalmanNum + zYYADatas[5].totalmanNum;
  385. zYYADatas[3].totalVillageCount = zYYADatas[4].totalVillageCount + zYYADatas[5].totalVillageCount;
  386. zYYADatas[3].totalMaterialPrize = zYYADatas[4].totalMaterialPrize + zYYADatas[5].totalMaterialPrize;
  387. zYYADatas[3].totalRoadCount = zYYADatas[4].totalRoadCount + zYYADatas[5].totalRoadCount;
  388. RefreshZYYAData();
  389. }
  390. movePlans = new List<Thing1>();
  391. RectTransform title = Instantiate(title1);
  392. title.localScale = Vector3.one;
  393. title.SetParent(movePlanBeforeContent);
  394. RectTransform title2 = Instantiate(title1);
  395. title2.localScale = Vector3.one;
  396. title2.SetParent(movePlanAfterContent);
  397. List<ServerMovePlan> serverMovePlans = new List<ServerMovePlan>();
  398. for (int i = 0; i < beforeLinePaths.Count; i++)
  399. {
  400. int tempI = i;
  401. RectTransform plan = Instantiate(plan1);
  402. plan.SetParent(movePlanBeforeContent);
  403. Thing1 thing1 = plan.GetComponent<Thing1>();
  404. thing1.zyTime = ZYTime.Before;
  405. thing1.lineDir = beforeLinePaths[i].lineDir;
  406. thing1.bindLinePath = beforeLinePaths[i];
  407. thing1.GetComponent<Button>().onClick.AddListener(() =>
  408. {
  409. for (int i = 0; i < linePaths.Count; i++)
  410. {
  411. linePaths[i].gameObject.SetActive(false);
  412. }
  413. thing1.bindLinePath.gameObject.SetActive(true);
  414. CheckCalcUsable(thing1);
  415. });
  416. plan.localScale = Vector3.one;
  417. plan.GetChild(0).GetComponent<Text>().text = i.ToString();
  418. plan.GetChild(1).GetComponent<Text>().text = beforeLinePaths[i].startPos;
  419. plan.GetChild(2).GetComponent<Text>().text = beforeLinePaths[i].endPos;
  420. plan.GetChild(3).GetComponent<Text>().text = beforeLinePaths[i].manNum.ToString();
  421. plan.GetChild(4).GetComponent<Text>().text = beforeLinePaths[i].dateTime.ToString();
  422. movePlans.Add(thing1);
  423. }
  424. for (int i = 0; i < afterLinePaths.Count; i++)
  425. {
  426. RectTransform plan = Instantiate(plan1);
  427. plan.SetParent(movePlanAfterContent);
  428. Thing1 thing1 = plan.GetComponent<Thing1>();
  429. thing1.zyTime = ZYTime.After;
  430. thing1.lineDir = afterLinePaths[i].lineDir;
  431. thing1.bindLinePath = afterLinePaths[i];
  432. thing1.GetComponent<Button>().onClick.AddListener(() =>
  433. {
  434. for (int i = 0; i < linePaths.Count; i++)
  435. {
  436. linePaths[i].gameObject.SetActive(false);
  437. }
  438. thing1.bindLinePath.gameObject.SetActive(true);
  439. CheckCalcUsable(thing1);
  440. });
  441. plan.localScale = Vector3.one;
  442. plan.GetChild(0).GetComponent<Text>().text = i.ToString();
  443. plan.GetChild(1).GetComponent<Text>().text = afterLinePaths[i].startPos;
  444. plan.GetChild(2).GetComponent<Text>().text = afterLinePaths[i].endPos;
  445. plan.GetChild(3).GetComponent<Text>().text = afterLinePaths[i].manNum.ToString();
  446. plan.GetChild(4).GetComponent<Text>().text = afterLinePaths[i].dateTime.ToString();
  447. movePlans.Add(thing1);
  448. }
  449. movePlanAfterContent.gameObject.SetActive(false);
  450. }
  451. void CheckCalcUsable(Thing1 thing1 = null) {
  452. currentPath = thing1;
  453. if (currentPath != null)
  454. {
  455. calcMask.gameObject.SetActive(false);
  456. peopleCountText.text = currentPath.bindLinePath.manNum.ToString();
  457. lineNameText.text = currentPath.bindLinePath.lineDir == LineDir.In ? "内转安置" : "外传安置";
  458. lineStarToEndText.text = currentPath.bindLinePath.startPos + "→ " + currentPath.bindLinePath.endPos;
  459. moveTimeText.text = "待计算";
  460. tunTuText.text = currentPath.bindLinePath.xishu.ToString();
  461. }
  462. else {
  463. calcMask.gameObject.SetActive(true);
  464. }
  465. }
  466. void ChangeLinePathChannel(int index) {
  467. switch (index)
  468. {
  469. case 0:
  470. for (int i = 0; i < linePaths.Count; i++)
  471. {
  472. linePaths[i].gameObject.SetActive(true);
  473. }
  474. break;
  475. case 1:
  476. for (int i = 0; i < linePaths.Count; i++)
  477. {
  478. if (linePaths[i].lineDir == LineDir.Out)
  479. linePaths[i].gameObject.SetActive(true);
  480. else
  481. linePaths[i].gameObject.SetActive(false);
  482. }
  483. break;
  484. case 2:
  485. for (int i = 0; i < linePaths.Count; i++)
  486. {
  487. if (linePaths[i].lineDir == LineDir.In)
  488. linePaths[i].gameObject.SetActive(true);
  489. else
  490. linePaths[i].gameObject.SetActive(false);
  491. }
  492. break;
  493. }
  494. }
  495. void RefreshZYYAData() {
  496. zYYAIndex = beforeAfterIndex * 3 + inOutIndex;
  497. zYYAText[0].text = zYYADatas[zYYAIndex].totalVillageCount.ToString();
  498. zYYAText[1].text = (zYYADatas[zYYAIndex].totalmanNum / 10000.0f).ToString("0.00");
  499. //zYYAText[2].text = (zYYADatas[zYYAIndex].totalMaterialPrize / 100000000.0f).ToString("0.00");
  500. zYYAText[3].text = zYYADatas[zYYAIndex].totalRoadCount.ToString();
  501. }
  502. void BeforeBtnClick() {
  503. beforeAfterIndex = 0;
  504. beforeBtn.GetComponent<Image>().sprite = sprites[0];
  505. afterBtn.GetComponent<Image>().sprite = sprites[1];
  506. beforeC.gameObject.SetActive(true);
  507. afterC.gameObject.SetActive(false);
  508. movePlanBeforeContent.gameObject.SetActive(true);
  509. movePlanAfterContent.gameObject.SetActive(false);
  510. ChangeLinePathChannel(inOutIndex);
  511. RefreshZYYAData();
  512. page = 0;
  513. }
  514. void AfterBtnClick()
  515. {
  516. beforeAfterIndex = 1;
  517. beforeBtn.GetComponent<Image>().sprite = sprites[1];
  518. afterBtn.GetComponent<Image>().sprite = sprites[0];
  519. beforeC.gameObject.SetActive(false);
  520. afterC.gameObject.SetActive(true);
  521. movePlanBeforeContent.gameObject.SetActive(false);
  522. movePlanAfterContent.gameObject.SetActive(true);
  523. ChangeLinePathChannel(inOutIndex);
  524. RefreshZYYAData();
  525. page = 1;
  526. }
  527. void InitButton() {
  528. beforeBtn.onClick.AddListener(() => {
  529. BeforeBtnClick();
  530. });
  531. afterBtn.onClick.AddListener(() => {
  532. AfterBtnClick();
  533. });
  534. allLineButton.onClick.AddListener(() =>
  535. {
  536. ChangeLinePathChannel(inOutIndex);
  537. CheckCalcUsable();
  538. });
  539. calculateShowButton.onClick.AddListener(() =>
  540. {
  541. calcOpen = !calcOpen;
  542. if (calcOpen)
  543. {
  544. calculateShowButton.GetComponent<Image>().color = new UnityEngine.Color(1, 1, 1, 1f);
  545. calculatePanel.gameObject.SetActive(true);
  546. }
  547. else {
  548. calculateShowButton.GetComponent<Image>().color = new UnityEngine.Color(1, 1, 1, 0.5f);
  549. calculatePanel.gameObject.SetActive(false);
  550. }
  551. });
  552. searchPath.onValueChanged.AddListener((string searchItem) =>
  553. {
  554. allFilterPlans.Clear();
  555. for (int i = 0; i < movePlans.Count; i++)
  556. {
  557. if ((int)movePlans[i].bindLinePath.lineDir + 1 == inOutIndex || inOutIndex == 0)
  558. {
  559. if (searchItem.Trim().Length < 1)
  560. {
  561. movePlans[i].gameObject.SetActive(true);
  562. }
  563. else {
  564. if (movePlans[i].bindLinePath.startPos.Contains(searchItem) || movePlans[i].bindLinePath.endPos.Contains(searchItem))
  565. {
  566. movePlans[i].gameObject.SetActive(true);
  567. }
  568. else {
  569. movePlans[i].gameObject.SetActive(false);
  570. }
  571. }
  572. }
  573. else {
  574. movePlans[i].gameObject.SetActive(false);
  575. }
  576. }
  577. });
  578. calcTimeBtn.onClick.AddListener(() =>
  579. {
  580. int manNum = 1;
  581. int zzManNum = 1;
  582. float tuntu = 0;
  583. if (peopleCountText.text.Trim().Length < 1 || zhuangZaiText.text.Trim().Length < 1)
  584. {
  585. moveTimeText.text = "请输入数据";
  586. moveTimeText.transform.GetChild(2).GetComponent<Text>().color = Color.red;
  587. }
  588. else if (!int.TryParse(peopleCountText.text,out manNum) || !int.TryParse(zhuangZaiText.text, out zzManNum) ||
  589. !float.TryParse(tunTuText.text, out tuntu))
  590. {
  591. moveTimeText.text = "请检查数据";
  592. moveTimeText.transform.GetChild(2).GetComponent<Text>().color = Color.red;
  593. }
  594. else
  595. {
  596. moveTimeText.text = (manNum / tuntu / zzManNum).ToString("0.0") + "小时";
  597. moveTimeText.transform.GetChild(2).GetComponent<Text>().color = Color.white;
  598. }
  599. });
  600. resetTimeBtn.onClick.AddListener(() =>
  601. {
  602. peopleCountText.text = "";
  603. zhuangZaiText.text = "";
  604. moveTimeText.text = "待计算";
  605. });
  606. closeCalculateButton.onClick.AddListener(() =>
  607. {
  608. calculatePanel.gameObject.SetActive(false);
  609. calculateShowButton.GetComponent<Image>().color = new UnityEngine.Color(1, 1, 1, 0.5f);
  610. calcOpen = false;
  611. });
  612. allInOut[0].onClick.AddListener(() =>
  613. {
  614. inOutIndex = 0;
  615. ChangeLinePathChannel(0);
  616. for (int i = 0; i < movePlans.Count; i++)
  617. {
  618. movePlans[i].gameObject.SetActive(true);
  619. }
  620. allInOut[0].gameObject.GetComponent<Image>().sprite = sprites[0];
  621. allInOut[1].gameObject.GetComponent<Image>().sprite = sprites[1];
  622. allInOut[2].gameObject.GetComponent<Image>().sprite = sprites[1];
  623. RefreshZYYAData();
  624. CheckCalcUsable();
  625. });
  626. allInOut[1].onClick.AddListener(() =>
  627. {
  628. inOutIndex = 1;
  629. ChangeLinePathChannel(1);
  630. for (int i = 0; i < movePlans.Count; i++)
  631. {
  632. if (movePlans[i].lineDir == LineDir.Out)
  633. {
  634. movePlans[i].gameObject.SetActive(true);
  635. }
  636. else
  637. movePlans[i].gameObject.SetActive(false);
  638. }
  639. allInOut[0].gameObject.GetComponent<Image>().sprite = sprites[1];
  640. allInOut[1].gameObject.GetComponent<Image>().sprite = sprites[0];
  641. allInOut[2].gameObject.GetComponent<Image>().sprite = sprites[1];
  642. RefreshZYYAData();
  643. CheckCalcUsable();
  644. });
  645. allInOut[2].onClick.AddListener(() =>
  646. {
  647. inOutIndex = 2;
  648. ChangeLinePathChannel(2);
  649. for (int i = 0; i < movePlans.Count; i++)
  650. {
  651. if (movePlans[i].lineDir == LineDir.In)
  652. {
  653. movePlans[i].gameObject.SetActive(true);
  654. }
  655. else
  656. movePlans[i].gameObject.SetActive(false);
  657. }
  658. allInOut[0].gameObject.GetComponent<Image>().sprite = sprites[1];
  659. allInOut[1].gameObject.GetComponent<Image>().sprite = sprites[1];
  660. allInOut[2].gameObject.GetComponent<Image>().sprite = sprites[0];
  661. RefreshZYYAData();
  662. CheckCalcUsable();
  663. });
  664. BeforeBtnClick();
  665. }
  666. void InitAllPath() {
  667. for (int i = 0; i < beforeC.childCount; i++)
  668. {
  669. if (beforeC.GetChild(i).GetComponent<LinePath>())
  670. {
  671. linePaths.Add(beforeC.GetChild(i).GetComponent<LinePath>());
  672. }
  673. }
  674. for (int i = 0; i < afterC.childCount; i++)
  675. {
  676. if (afterC.GetChild(i).GetComponent<LinePath>())
  677. {
  678. linePaths.Add(afterC.GetChild(i).GetComponent<LinePath>());
  679. }
  680. }
  681. }
  682. // Update is called once per frame
  683. void Update()
  684. {
  685. // 获取当前时间
  686. DateTime now = DateTime.Now;
  687. // 格式化时间字符串
  688. string timeString = now.ToString("yyyy/MM/dd HH:mm");
  689. // 将格式化的时间字符串设置到UI Text组件上
  690. timeText.text = timeString;
  691. }
  692. LinePath lastPath;
  693. private void FixedUpdate()
  694. {
  695. if (lineInfo.linePaths.Count > 0)
  696. {
  697. lineInfo.gameObject.SetActive(true);
  698. }
  699. else
  700. {
  701. lineInfo.gameObject.SetActive(false);
  702. }
  703. Ray ray = CameraManager.instance.secondCamera.ScreenPointToRay(Input.mousePosition);
  704. RaycastHit hit;
  705. if (Physics.Raycast(ray, out hit, 10000))
  706. {
  707. Debug.Log(hit.collider.gameObject.name);
  708. // 检查射线是否击中 LineRenderer 所在的物体
  709. if (hit.collider.transform.parent.parent.GetComponent<LinePath>() != null)
  710. {
  711. if (lastPath != null && hit.collider.transform.parent.parent.GetComponent<LinePath>() != lastPath) {
  712. lastPath.UnShow();
  713. }
  714. hit.collider.transform.parent.parent.GetComponent<LinePath>().OnShow();
  715. lastPath = hit.collider.transform.parent.parent.GetComponent<LinePath>();
  716. }
  717. else
  718. {
  719. if (lastPath)
  720. {
  721. lastPath.UnShow();
  722. lastPath = null;
  723. }
  724. }
  725. }
  726. else {
  727. if (lastPath)
  728. {
  729. lastPath.UnShow();
  730. lastPath = null;
  731. }
  732. }
  733. }
  734. }