void DrawEdge(MeshGenerationContext mgc) { if (edgeWidth <= 0) { return; } UpdateRenderPoints(); if (m_RenderPoints.Count == 0) { return; // Don't draw anything } Color inColor = this.inputColor; Color outColor = this.outputColor; #if UNITY_EDITOR inColor *= GraphViewStaticBridge.EditorPlayModeTint; outColor *= GraphViewStaticBridge.EditorPlayModeTint; #endif // UNITY_EDITOR uint cpt = (uint)m_RenderPoints.Count; uint wantedLength = (cpt) * 2; uint indexCount = (wantedLength - 2) * 3; var md = GraphViewStaticBridge.AllocateMeshWriteData(mgc, (int)wantedLength, (int)indexCount); if (md.vertexCount == 0) { return; } float polyLineLength = 0; for (int i = 1; i < cpt; ++i) { polyLineLength += (m_RenderPoints[i - 1] - m_RenderPoints[i]).sqrMagnitude; } float halfWidth = edgeWidth * 0.5f; float currentLength = 0; Vector2 unitPreviousSegment = Vector2.zero; for (int i = 0; i < cpt; ++i) { Vector2 dir; Vector2 unitNextSegment = Vector2.zero; Vector2 nextSegment = Vector2.zero; if (i < cpt - 1) { nextSegment = (m_RenderPoints[i + 1] - m_RenderPoints[i]); unitNextSegment = nextSegment.normalized; } if (i > 0 && i < cpt - 1) { dir = unitPreviousSegment + unitNextSegment; dir.Normalize(); } else if (i > 0) { dir = unitPreviousSegment; } else { dir = unitNextSegment; } Vector2 pos = m_RenderPoints[i]; Vector2 uv = new Vector2(dir.y * halfWidth, -dir.x * halfWidth); // Normal scaled by half width Color32 tint = Color.LerpUnclamped(outColor, inColor, currentLength / polyLineLength); md.SetNextVertex(new Vector3(pos.x, pos.y, 1), uv, tint); md.SetNextVertex(new Vector3(pos.x, pos.y, -1), uv, tint); if (i < cpt - 2) { currentLength += nextSegment.sqrMagnitude; } else { currentLength = polyLineLength; } unitPreviousSegment = unitNextSegment; } // Fill triangle indices as it is a triangle strip for (uint i = 0; i < wantedLength - 2; ++i) { if ((i & 0x01) == 0) { md.SetNextIndex((UInt16)i); md.SetNextIndex((UInt16)(i + 2)); md.SetNextIndex((UInt16)(i + 1)); } else { md.SetNextIndex((UInt16)i); md.SetNextIndex((UInt16)(i + 1)); md.SetNextIndex((UInt16)(i + 2)); } } }