RKZYLayer.cs 25 KB

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