LinePath.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using XCharts.Runtime;
  6. public enum LineDir
  7. {
  8. Out,
  9. In
  10. };
  11. public enum ZYTime
  12. {
  13. Before,
  14. After,
  15. };
  16. public class LinePath : MonoBehaviour
  17. {
  18. public LineDir lineDir;
  19. public string startPos;
  20. public string endPos;
  21. public string linePathContent;
  22. public int manNum;
  23. public int homeNum;
  24. public int completeNum;
  25. public string dateTime;
  26. public LineRenderer line;
  27. private List<Vector3> points = new List<Vector3>();
  28. // Use this for initialization
  29. public void Start()
  30. {
  31. line = this.GetComponent<LineRenderer>();
  32. points.Clear();
  33. // line = lines;
  34. GameObject caret = null;
  35. caret = new GameObject("Lines");
  36. Vector3 left, right; // A position to the left of the current line
  37. // For all but the last point
  38. for (var i = 0; i < line.positionCount - 1; i++)
  39. {
  40. caret.transform.position = line.GetPosition(i);
  41. caret.transform.LookAt(line.GetPosition(i + 1));
  42. right = caret.transform.position + transform.right * line.startWidth / 2;
  43. left = caret.transform.position - transform.right * line.startWidth / 2;
  44. points.Add(left);
  45. points.Add(right);
  46. }
  47. // Last point looks backwards and reverses
  48. caret.transform.position = line.GetPosition(line.positionCount - 1);
  49. caret.transform.LookAt(line.GetPosition(line.positionCount - 2));
  50. right = caret.transform.position + transform.right * line.startWidth / 2;
  51. left = caret.transform.position - transform.right * line.startWidth / 2;
  52. points.Add(left);
  53. points.Add(right);
  54. Destroy(caret);
  55. DrawMesh();
  56. }
  57. private void DrawMesh()
  58. {
  59. Vector3[] verticies = new Vector3[points.Count];
  60. for (int i = 0; i < verticies.Length; i++)
  61. {
  62. verticies[i] = points[i];
  63. }
  64. int[] triangles = new int[((points.Count / 2) - 1) * 6];
  65. //Works on linear patterns tn = bn+c
  66. int position = 6;
  67. for (int i = 0; i < (triangles.Length / 6); i++)
  68. {
  69. triangles[i * position] = 2 * i;
  70. triangles[i * position + 3] = 2 * i;
  71. triangles[i * position + 1] = 2 * i + 3;
  72. triangles[i * position + 4] = (2 * i + 3) - 1;
  73. triangles[i * position + 2] = 2 * i + 1;
  74. triangles[i * position + 5] = (2 * i + 1) + 2;
  75. }
  76. Mesh mesh = GetComponent<MeshFilter>().mesh;
  77. mesh.Clear();
  78. mesh.vertices = verticies;
  79. mesh.triangles = triangles;
  80. mesh.RecalculateNormals();
  81. }
  82. public void OnShow()
  83. {
  84. if (RKZYLayer.lineInfoStatic)
  85. {
  86. RKZYLayer.lineInfoStatic.SetData(this);
  87. RKZYLayer.lineInfoStatic.GetComponent<RectTransform>().anchoredPosition = this.GetComponent<RectTransform>().anchoredPosition;
  88. RKZYLayer.lineInfoStatic.linePaths.Add(this);
  89. }
  90. }
  91. }