RKZYLayer.cs 25 KB

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