RKZYLayer.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798
  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. if (j == 0)
  240. {
  241. RectTransform startSign = Instantiate(startPos);
  242. startSign.SetParent(pathSign);
  243. startSign.transform.localScale = Vector3.one;
  244. startSign.GetComponent<PathSign>().bindObj = linePath.gameObject;
  245. startSign.GetComponent<PathSign>().bindPos = worldPos;
  246. }
  247. if (j == GlobalData.allServerMovePlans[i].paths.Count - 2)
  248. {
  249. RectTransform endSign = Instantiate(endPos);
  250. endSign.SetParent(pathSign);
  251. endSign.transform.localScale = Vector3.one;
  252. endSign.GetComponent<PathSign>().bindObj = linePath.gameObject;
  253. endSign.GetComponent<PathSign>().bindPos = worldPos1;
  254. }
  255. }
  256. lineParent.startPos = GlobalData.allServerMovePlans[i].from;
  257. lineParent.endPos = GlobalData.allServerMovePlans[i].to;
  258. lineParent.lineDir = isOut ? LineDir.Out : LineDir.In;
  259. lineParent.linePathContent = GlobalData.allServerMovePlans[i].desc;
  260. lineParent.manNum = GlobalData.allServerMovePlans[i].manNum;
  261. lineParent.homeNum = GlobalData.allServerMovePlans[i].homeNum;
  262. lineParent.completeNum = GlobalData.allServerMovePlans[i].completeNum;
  263. lineParent.dateTime = GlobalData.allServerMovePlans[i].dateTime;
  264. lineParent.xishu = UnityEngine.Random.Range(10f, 30.0f);
  265. if (lineParent.lineDir == LineDir.Out)
  266. {
  267. zYYADatas[1].totalmanNum += GlobalData.allServerMovePlans[i].manNum;
  268. zYYADatas[1].totalVillageCount += GlobalData.allServerMovePlans[i].villageCount;
  269. zYYADatas[1].totalMaterialPrize += GlobalData.allServerMovePlans[i].materialPrize;
  270. zYYADatas[1].totalRoadCount += 1;
  271. }
  272. else
  273. {
  274. zYYADatas[2].totalmanNum += GlobalData.allServerMovePlans[i].manNum;
  275. zYYADatas[2].totalVillageCount += GlobalData.allServerMovePlans[i].villageCount;
  276. zYYADatas[2].totalMaterialPrize += GlobalData.allServerMovePlans[i].materialPrize;
  277. zYYADatas[2].totalRoadCount += 1;
  278. }
  279. lineParent.transform.localPosition = new Vector3(lineParent.transform.localPosition.x, lineParent.transform.localPosition.y, lineOrderZ);
  280. lineOrderZ += 0.01f;
  281. beforeLinePaths.Add(lineParent);
  282. }
  283. else
  284. {
  285. LinePath lineParent = Instantiate(linePathPrefab);
  286. lineParent.transform.SetParent(afterC);
  287. float clolorLerpUnit = 1.0f / (GlobalData.allServerMovePlans[i].paths.Count - 1);
  288. for (int j = 0; j < GlobalData.allServerMovePlans[i].paths.Count - 1; j++)
  289. {
  290. LinePathUnit linePath = Instantiate(linePathUnitPrefab);
  291. linePath.transform.SetParent(lineParent.transform);
  292. Vector3 localPos = CoordinateConverter.GeoToUGUISmall(GlobalData.allServerMovePlans[i].paths[j].longitude, GlobalData.allServerMovePlans[i].paths[j].latitude);
  293. Vector3 worldPos = runtimPointParent.TransformPoint(localPos);
  294. worldPos.z = -583;
  295. Vector3 localPos1 = CoordinateConverter.GeoToUGUISmall(GlobalData.allServerMovePlans[i].paths[j + 1].longitude, GlobalData.allServerMovePlans[i].paths[j + 1].latitude);
  296. Vector3 worldPos1 = runtimPointParent.TransformPoint(localPos1);
  297. worldPos1.z = -583;
  298. linePath.SetPath(worldPos, worldPos1);
  299. linePath.SetColor(Color.Lerp(Color.yellow, Color.red, j * clolorLerpUnit), Color.Lerp(Color.yellow, Color.red, (j + 1) * clolorLerpUnit));
  300. if (j == 0)
  301. {
  302. RectTransform startSign = Instantiate(startPos);
  303. startSign.SetParent(pathSign);
  304. startSign.transform.localScale = Vector3.one;
  305. startSign.GetComponent<PathSign>().bindObj = linePath.gameObject;
  306. startSign.GetComponent<PathSign>().bindPos = worldPos;
  307. }
  308. if (j == GlobalData.allServerMovePlans[i].paths.Count - 2)
  309. {
  310. RectTransform endSign = Instantiate(endPos);
  311. endSign.SetParent(pathSign);
  312. endSign.transform.localScale = Vector3.one;
  313. endSign.GetComponent<PathSign>().bindObj = linePath.gameObject;
  314. endSign.GetComponent<PathSign>().bindPos = worldPos1;
  315. }
  316. }
  317. lineParent.startPos = GlobalData.allServerMovePlans[i].from;
  318. lineParent.endPos = GlobalData.allServerMovePlans[i].to;
  319. lineParent.lineDir = isOut ? LineDir.Out : LineDir.In;
  320. lineParent.linePathContent = GlobalData.allServerMovePlans[i].desc;
  321. lineParent.manNum = GlobalData.allServerMovePlans[i].manNum;
  322. lineParent.homeNum = GlobalData.allServerMovePlans[i].homeNum;
  323. lineParent.completeNum = GlobalData.allServerMovePlans[i].completeNum;
  324. lineParent.dateTime = GlobalData.allServerMovePlans[i].dateTime;
  325. lineParent.xishu = UnityEngine.Random.Range(10f, 30.0f);
  326. if (lineParent.lineDir == LineDir.Out)
  327. {
  328. zYYADatas[4].totalmanNum += GlobalData.allServerMovePlans[i].manNum;
  329. zYYADatas[4].totalVillageCount += GlobalData.allServerMovePlans[i].villageCount;
  330. zYYADatas[4].totalMaterialPrize += GlobalData.allServerMovePlans[i].materialPrize;
  331. zYYADatas[4].totalRoadCount += 1;
  332. }
  333. else
  334. {
  335. zYYADatas[5].totalmanNum += GlobalData.allServerMovePlans[i].manNum;
  336. zYYADatas[5].totalVillageCount += GlobalData.allServerMovePlans[i].villageCount;
  337. zYYADatas[5].totalMaterialPrize += GlobalData.allServerMovePlans[i].materialPrize;
  338. zYYADatas[5].totalRoadCount += 1;
  339. }
  340. lineParent.transform.localPosition = new Vector3(lineParent.transform.localPosition.x, lineParent.transform.localPosition.y, lineOrderZ);
  341. lineOrderZ += 0.01f;
  342. afterLinePaths.Add(lineParent);
  343. }
  344. zYYADatas[0].totalmanNum = zYYADatas[1].totalmanNum + zYYADatas[2].totalmanNum;
  345. zYYADatas[0].totalVillageCount = zYYADatas[1].totalVillageCount + zYYADatas[2].totalVillageCount;
  346. zYYADatas[0].totalMaterialPrize = zYYADatas[1].totalMaterialPrize + zYYADatas[2].totalMaterialPrize;
  347. zYYADatas[0].totalRoadCount = zYYADatas[1].totalRoadCount + zYYADatas[2].totalRoadCount;
  348. zYYADatas[3].totalmanNum = zYYADatas[4].totalmanNum + zYYADatas[5].totalmanNum;
  349. zYYADatas[3].totalVillageCount = zYYADatas[4].totalVillageCount + zYYADatas[5].totalVillageCount;
  350. zYYADatas[3].totalMaterialPrize = zYYADatas[4].totalMaterialPrize + zYYADatas[5].totalMaterialPrize;
  351. zYYADatas[3].totalRoadCount = zYYADatas[4].totalRoadCount + zYYADatas[5].totalRoadCount;
  352. RefreshZYYAData();
  353. }
  354. movePlans = new List<Thing1>();
  355. RectTransform title = Instantiate(title1);
  356. title.localScale = Vector3.one;
  357. title.SetParent(movePlanBeforeContent);
  358. RectTransform title2 = Instantiate(title1);
  359. title2.localScale = Vector3.one;
  360. title2.SetParent(movePlanAfterContent);
  361. List<ServerMovePlan> serverMovePlans = new List<ServerMovePlan>();
  362. for (int i = 0; i < beforeLinePaths.Count; i++)
  363. {
  364. int tempI = i;
  365. RectTransform plan = Instantiate(plan1);
  366. plan.SetParent(movePlanBeforeContent);
  367. Thing1 thing1 = plan.GetComponent<Thing1>();
  368. thing1.zyTime = ZYTime.Before;
  369. thing1.lineDir = beforeLinePaths[i].lineDir;
  370. thing1.bindLinePath = beforeLinePaths[i];
  371. thing1.GetComponent<Button>().onClick.AddListener(() =>
  372. {
  373. for (int i = 0; i < linePaths.Count; i++)
  374. {
  375. linePaths[i].gameObject.SetActive(false);
  376. }
  377. thing1.bindLinePath.gameObject.SetActive(true);
  378. CheckCalcUsable(thing1);
  379. });
  380. plan.localScale = Vector3.one;
  381. plan.GetChild(0).GetComponent<Text>().text = i.ToString();
  382. plan.GetChild(1).GetComponent<Text>().text = beforeLinePaths[i].startPos;
  383. plan.GetChild(2).GetComponent<Text>().text = beforeLinePaths[i].endPos;
  384. plan.GetChild(3).GetComponent<Text>().text = beforeLinePaths[i].manNum.ToString();
  385. plan.GetChild(4).GetComponent<Text>().text = beforeLinePaths[i].dateTime.ToString();
  386. movePlans.Add(thing1);
  387. }
  388. for (int i = 0; i < afterLinePaths.Count; i++)
  389. {
  390. RectTransform plan = Instantiate(plan1);
  391. plan.SetParent(movePlanAfterContent);
  392. Thing1 thing1 = plan.GetComponent<Thing1>();
  393. thing1.zyTime = ZYTime.After;
  394. thing1.lineDir = afterLinePaths[i].lineDir;
  395. thing1.bindLinePath = afterLinePaths[i];
  396. thing1.GetComponent<Button>().onClick.AddListener(() =>
  397. {
  398. for (int i = 0; i < linePaths.Count; i++)
  399. {
  400. linePaths[i].gameObject.SetActive(false);
  401. }
  402. thing1.bindLinePath.gameObject.SetActive(true);
  403. CheckCalcUsable(thing1);
  404. });
  405. plan.localScale = Vector3.one;
  406. plan.GetChild(0).GetComponent<Text>().text = i.ToString();
  407. plan.GetChild(1).GetComponent<Text>().text = afterLinePaths[i].startPos;
  408. plan.GetChild(2).GetComponent<Text>().text = afterLinePaths[i].endPos;
  409. plan.GetChild(3).GetComponent<Text>().text = afterLinePaths[i].manNum.ToString();
  410. plan.GetChild(4).GetComponent<Text>().text = afterLinePaths[i].dateTime.ToString();
  411. movePlans.Add(thing1);
  412. }
  413. movePlanAfterContent.gameObject.SetActive(false);
  414. }
  415. void CheckCalcUsable(Thing1 thing1 = null) {
  416. currentPath = thing1;
  417. if (currentPath != null)
  418. {
  419. calcMask.gameObject.SetActive(false);
  420. peopleCountText.text = currentPath.bindLinePath.manNum.ToString();
  421. lineNameText.text = currentPath.bindLinePath.lineDir == LineDir.In ? "内转安置" : "外传安置";
  422. lineStarToEndText.text = currentPath.bindLinePath.startPos + "→ " + currentPath.bindLinePath.endPos;
  423. moveTimeText.text = "待计算";
  424. tunTuText.text = currentPath.bindLinePath.xishu.ToString();
  425. }
  426. else {
  427. calcMask.gameObject.SetActive(true);
  428. }
  429. }
  430. void ChangeLinePathChannel(int index) {
  431. switch (index)
  432. {
  433. case 0:
  434. for (int i = 0; i < linePaths.Count; i++)
  435. {
  436. linePaths[i].gameObject.SetActive(true);
  437. }
  438. break;
  439. case 1:
  440. for (int i = 0; i < linePaths.Count; i++)
  441. {
  442. if (linePaths[i].lineDir == LineDir.Out)
  443. linePaths[i].gameObject.SetActive(true);
  444. else
  445. linePaths[i].gameObject.SetActive(false);
  446. }
  447. break;
  448. case 2:
  449. for (int i = 0; i < linePaths.Count; i++)
  450. {
  451. if (linePaths[i].lineDir == LineDir.In)
  452. linePaths[i].gameObject.SetActive(true);
  453. else
  454. linePaths[i].gameObject.SetActive(false);
  455. }
  456. break;
  457. }
  458. }
  459. void RefreshZYYAData() {
  460. zYYAIndex = beforeAfterIndex * 3 + inOutIndex;
  461. zYYAText[0].text = zYYADatas[zYYAIndex].totalVillageCount.ToString();
  462. zYYAText[1].text = (zYYADatas[zYYAIndex].totalmanNum / 10000.0f).ToString("0.00");
  463. zYYAText[2].text = (zYYADatas[zYYAIndex].totalMaterialPrize / 100000000.0f).ToString("0.00");
  464. zYYAText[3].text = zYYADatas[zYYAIndex].totalRoadCount.ToString();
  465. }
  466. void BeforeBtnClick() {
  467. beforeAfterIndex = 0;
  468. beforeBtn.GetComponent<Image>().sprite = sprites[0];
  469. afterBtn.GetComponent<Image>().sprite = sprites[1];
  470. beforeC.gameObject.SetActive(true);
  471. afterC.gameObject.SetActive(false);
  472. movePlanBeforeContent.gameObject.SetActive(true);
  473. movePlanAfterContent.gameObject.SetActive(false);
  474. ChangeLinePathChannel(inOutIndex);
  475. RefreshZYYAData();
  476. page = 0;
  477. }
  478. void AfterBtnClick()
  479. {
  480. beforeAfterIndex = 1;
  481. beforeBtn.GetComponent<Image>().sprite = sprites[1];
  482. afterBtn.GetComponent<Image>().sprite = sprites[0];
  483. beforeC.gameObject.SetActive(false);
  484. afterC.gameObject.SetActive(true);
  485. movePlanBeforeContent.gameObject.SetActive(false);
  486. movePlanAfterContent.gameObject.SetActive(true);
  487. ChangeLinePathChannel(inOutIndex);
  488. RefreshZYYAData();
  489. page = 1;
  490. }
  491. void InitButton() {
  492. beforeBtn.onClick.AddListener(() => {
  493. BeforeBtnClick();
  494. });
  495. afterBtn.onClick.AddListener(() => {
  496. AfterBtnClick();
  497. });
  498. allLineButton.onClick.AddListener(() =>
  499. {
  500. ChangeLinePathChannel(inOutIndex);
  501. CheckCalcUsable();
  502. });
  503. calculateShowButton.onClick.AddListener(() =>
  504. {
  505. calcOpen = !calcOpen;
  506. if (calcOpen)
  507. {
  508. calculateShowButton.GetComponent<Image>().color = new UnityEngine.Color(1, 1, 1, 1f);
  509. calculatePanel.gameObject.SetActive(true);
  510. }
  511. else {
  512. calculateShowButton.GetComponent<Image>().color = new UnityEngine.Color(1, 1, 1, 0.5f);
  513. calculatePanel.gameObject.SetActive(false);
  514. }
  515. });
  516. searchPath.onValueChanged.AddListener((string searchItem) =>
  517. {
  518. allFilterPlans.Clear();
  519. for (int i = 0; i < movePlans.Count; i++)
  520. {
  521. if ((int)movePlans[i].bindLinePath.lineDir + 1 == inOutIndex || inOutIndex == 0)
  522. {
  523. if (searchItem.Trim().Length < 1)
  524. {
  525. movePlans[i].gameObject.SetActive(true);
  526. }
  527. else {
  528. if (movePlans[i].bindLinePath.startPos.Contains(searchItem) || movePlans[i].bindLinePath.endPos.Contains(searchItem))
  529. {
  530. movePlans[i].gameObject.SetActive(true);
  531. }
  532. else {
  533. movePlans[i].gameObject.SetActive(false);
  534. }
  535. }
  536. }
  537. else {
  538. movePlans[i].gameObject.SetActive(false);
  539. }
  540. }
  541. });
  542. calcTimeBtn.onClick.AddListener(() =>
  543. {
  544. int manNum = 1;
  545. int zzManNum = 1;
  546. float tuntu = 0;
  547. if (peopleCountText.text.Trim().Length < 1 || zhuangZaiText.text.Trim().Length < 1)
  548. {
  549. moveTimeText.text = "请输入数据";
  550. moveTimeText.transform.GetChild(2).GetComponent<Text>().color = Color.red;
  551. }
  552. else if (!int.TryParse(peopleCountText.text,out manNum) || !int.TryParse(zhuangZaiText.text, out zzManNum) ||
  553. !float.TryParse(tunTuText.text, out tuntu))
  554. {
  555. moveTimeText.text = "请检查数据";
  556. moveTimeText.transform.GetChild(2).GetComponent<Text>().color = Color.red;
  557. }
  558. else
  559. {
  560. moveTimeText.text = (manNum / tuntu / zzManNum).ToString("0.0") + "小时";
  561. moveTimeText.transform.GetChild(2).GetComponent<Text>().color = Color.white;
  562. }
  563. });
  564. resetTimeBtn.onClick.AddListener(() =>
  565. {
  566. peopleCountText.text = "";
  567. zhuangZaiText.text = "";
  568. moveTimeText.text = "待计算";
  569. });
  570. closeCalculateButton.onClick.AddListener(() =>
  571. {
  572. calculatePanel.gameObject.SetActive(false);
  573. calculateShowButton.GetComponent<Image>().color = new UnityEngine.Color(1, 1, 1, 0.5f);
  574. calcOpen = false;
  575. });
  576. allInOut[0].onClick.AddListener(() =>
  577. {
  578. inOutIndex = 0;
  579. ChangeLinePathChannel(0);
  580. for (int i = 0; i < movePlans.Count; i++)
  581. {
  582. movePlans[i].gameObject.SetActive(true);
  583. }
  584. allInOut[0].gameObject.GetComponent<Image>().sprite = sprites[0];
  585. allInOut[1].gameObject.GetComponent<Image>().sprite = sprites[1];
  586. allInOut[2].gameObject.GetComponent<Image>().sprite = sprites[1];
  587. RefreshZYYAData();
  588. CheckCalcUsable();
  589. });
  590. allInOut[1].onClick.AddListener(() =>
  591. {
  592. inOutIndex = 1;
  593. ChangeLinePathChannel(1);
  594. for (int i = 0; i < movePlans.Count; i++)
  595. {
  596. if (movePlans[i].lineDir == LineDir.Out)
  597. {
  598. movePlans[i].gameObject.SetActive(true);
  599. }
  600. else
  601. movePlans[i].gameObject.SetActive(false);
  602. }
  603. allInOut[0].gameObject.GetComponent<Image>().sprite = sprites[1];
  604. allInOut[1].gameObject.GetComponent<Image>().sprite = sprites[0];
  605. allInOut[2].gameObject.GetComponent<Image>().sprite = sprites[1];
  606. RefreshZYYAData();
  607. CheckCalcUsable();
  608. });
  609. allInOut[2].onClick.AddListener(() =>
  610. {
  611. inOutIndex = 2;
  612. ChangeLinePathChannel(2);
  613. for (int i = 0; i < movePlans.Count; i++)
  614. {
  615. if (movePlans[i].lineDir == LineDir.In)
  616. {
  617. movePlans[i].gameObject.SetActive(true);
  618. }
  619. else
  620. movePlans[i].gameObject.SetActive(false);
  621. }
  622. allInOut[0].gameObject.GetComponent<Image>().sprite = sprites[1];
  623. allInOut[1].gameObject.GetComponent<Image>().sprite = sprites[1];
  624. allInOut[2].gameObject.GetComponent<Image>().sprite = sprites[0];
  625. RefreshZYYAData();
  626. CheckCalcUsable();
  627. });
  628. BeforeBtnClick();
  629. }
  630. void InitAllPath() {
  631. for (int i = 0; i < beforeC.childCount; i++)
  632. {
  633. if (beforeC.GetChild(i).GetComponent<LinePath>())
  634. {
  635. linePaths.Add(beforeC.GetChild(i).GetComponent<LinePath>());
  636. }
  637. }
  638. for (int i = 0; i < afterC.childCount; i++)
  639. {
  640. if (afterC.GetChild(i).GetComponent<LinePath>())
  641. {
  642. linePaths.Add(afterC.GetChild(i).GetComponent<LinePath>());
  643. }
  644. }
  645. }
  646. // Update is called once per frame
  647. void Update()
  648. {
  649. // 获取当前时间
  650. DateTime now = DateTime.Now;
  651. // 格式化时间字符串
  652. string timeString = now.ToString("yyyy/MM/dd HH:mm");
  653. // 将格式化的时间字符串设置到UI Text组件上
  654. timeText.text = timeString;
  655. }
  656. LinePath lastPath;
  657. private void FixedUpdate()
  658. {
  659. if (lineInfo.linePaths.Count > 0)
  660. {
  661. lineInfo.gameObject.SetActive(true);
  662. }
  663. else
  664. {
  665. lineInfo.gameObject.SetActive(false);
  666. }
  667. Ray ray = CameraManager.instance.secondCamera.ScreenPointToRay(Input.mousePosition);
  668. RaycastHit hit;
  669. if (Physics.Raycast(ray, out hit, 10000))
  670. {
  671. Debug.Log(hit.collider.gameObject.name);
  672. // 检查射线是否击中 LineRenderer 所在的物体
  673. if (hit.collider.transform.parent.parent.GetComponent<LinePath>() != null)
  674. {
  675. if (lastPath != null && hit.collider.transform.parent.parent.GetComponent<LinePath>() != lastPath) {
  676. lastPath.UnShow();
  677. }
  678. hit.collider.transform.parent.parent.GetComponent<LinePath>().OnShow();
  679. lastPath = hit.collider.transform.parent.parent.GetComponent<LinePath>();
  680. }
  681. else
  682. {
  683. if (lastPath)
  684. {
  685. lastPath.UnShow();
  686. lastPath = null;
  687. }
  688. }
  689. }
  690. else {
  691. if (lastPath)
  692. {
  693. lastPath.UnShow();
  694. lastPath = null;
  695. }
  696. }
  697. }
  698. }