void SubmitLines(RetainedGizmos gizmos, ulong hash) { // Unity only supports 65535 vertices per mesh. 65532 used because MaxLineEndPointsPerBatch needs to be even. const int MaxLineEndPointsPerBatch = 65532 / 2; int batches = (lines.Count + MaxLineEndPointsPerBatch - 1) / MaxLineEndPointsPerBatch; for (int batch = 0; batch < batches; batch++) { int startIndex = MaxLineEndPointsPerBatch * batch; int endIndex = Mathf.Min(startIndex + MaxLineEndPointsPerBatch, lines.Count); int lineEndPointCount = endIndex - startIndex; UnityEngine.Assertions.Assert.IsTrue(lineEndPointCount % 2 == 0); // Use pooled lists to avoid excessive allocations var vertices = ListPool <Vector3> .Claim(lineEndPointCount *2); var colors = ListPool <Color32> .Claim(lineEndPointCount *2); var normals = ListPool <Vector3> .Claim(lineEndPointCount *2); var uv = ListPool <Vector2> .Claim(lineEndPointCount *2); var tris = ListPool <int> .Claim(lineEndPointCount *3); // Loop through each endpoint of the lines // and add 2 vertices for each for (int j = startIndex; j < endIndex; j++) { var vertex = (Vector3)lines[j]; vertices.Add(vertex); vertices.Add(vertex); var color = (Color32)lineColors[j]; colors.Add(color); colors.Add(color); uv.Add(new Vector2(0, 0)); uv.Add(new Vector2(1, 0)); } // Loop through each line and add // one normal for each vertex for (int j = startIndex; j < endIndex; j += 2) { var lineDir = (Vector3)(lines[j + 1] - lines[j]); // Store the line direction in the normals. // A line consists of 4 vertices. The line direction will be used to // offset the vertices to create a line with a fixed pixel thickness normals.Add(lineDir); normals.Add(lineDir); normals.Add(lineDir); normals.Add(lineDir); } // Setup triangle indices // A triangle consists of 3 indices // A line (4 vertices) consists of 2 triangles, so 6 triangle indices for (int j = 0, v = 0; j < lineEndPointCount * 3; j += 6, v += 4) { // First triangle tris.Add(v + 0); tris.Add(v + 1); tris.Add(v + 2); // Second triangle tris.Add(v + 1); tris.Add(v + 3); tris.Add(v + 2); } var mesh = gizmos.GetMesh(); // Set all data on the mesh mesh.SetVertices(vertices); mesh.SetTriangles(tris, 0); mesh.SetColors(colors); mesh.SetNormals(normals); mesh.SetUVs(0, uv); // Upload all data and mark the mesh as unreadable mesh.UploadMeshData(true); // Release the lists back to the pool ListPool <Vector3> .Release(ref vertices); ListPool <Color32> .Release(ref colors); ListPool <Vector3> .Release(ref normals); ListPool <Vector2> .Release(ref uv); ListPool <int> .Release(ref tris); gizmos.meshes.Add(new MeshWithHash { hash = hash, mesh = mesh, lines = true }); gizmos.existingHashes.Add(hash); } }
// Token: 0x06002960 RID: 10592 RVA: 0x001C0BE4 File Offset: 0x001BEDE4 public static void Release(ref List <T> list) { ListPool <T> .Release(list); list = null; }