RKZYLayer.cs 25 KB

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