using System.Collections; using System.Collections.Generic; using UnityEngine; public class test : MonoBehaviour { public CanvasManager3D CM; public List lines; public float width = 1.0f; Mesh mesh; bool tryGet = false; // Start is called before the first frame update void Start() { lines = new List(); mesh = GetComponent().mesh; } // Update is called once per frame void Update() { if(lines.Count != 0) { Vector3[] vertices = new Vector3[lines.Count * 4]; Vector3 offset = Camera.main.transform.up * width; int k = 0; foreach (Line l in lines) { Vector3 tmp1 = new Vector3(l.point1.x, l.point1.y, l.point1.z); Vector3 tmp2 = new Vector3(l.point2.x, l.point2.y, l.point2.z); vertices[k] = tmp1 + offset; vertices[k + 1] = tmp1 - offset; vertices[k + 2] = tmp2 + offset; vertices[k + 3] = tmp2 - offset; k += 4; } mesh.vertices = vertices; int[] triangles = new int[lines.Count * 6]; for (int i = 0; i < lines.Count; i++) { triangles[6 * i] = 4 * i; triangles[6 * i + 1] = 4 * i + 1; triangles[6 * i + 2] = 4 * i + 2; triangles[6 * i + 3] = 4 * i + 1; triangles[6 * i + 4] = 4 * i + 3; triangles[6 * i + 5] = 4 * i + 2; } mesh.SetIndices(triangles, MeshTopology.Triangles, 0); } if (tryGet) { getDig(); } } public void getDig() { if (CM.isFin) { lines = CM.GetLines(); tryGet = false; } } }