protected override void DoRepaint(IStylePainter painter) { if (m_Mesh != null) { if (m_Mat == null) { m_Mat = new Material(EditorGUIUtility.LoadRequired("Shaders/UIElements/AACurveField.shader") as Shader); m_Mat.hideFlags = HideFlags.HideAndDontSave; } float scale = worldTransform.MultiplyVector(Vector3.one).x; float realWidth = CurveField.k_EdgeWidth; if (realWidth * scale < CurveField.k_MinEdgeWidth) { realWidth = CurveField.k_MinEdgeWidth / scale; } // Send the view zoom factor so that the antialias width do not grow when zooming in. m_Mat.SetFloat("_ZoomFactor", scale * realWidth / CurveField.k_EdgeWidth * EditorGUIUtility.pixelsPerPoint); // Send the view zoom correction so that the vertex shader can scale the edge triangles when below m_MinWidth. m_Mat.SetFloat("_ZoomCorrection", realWidth / CurveField.k_EdgeWidth); m_Mat.SetColor("_Color", (QualitySettings.activeColorSpace == ColorSpace.Linear) ? curveColor.gamma : curveColor); var stylePainter = (IStylePainterInternal)painter; var meshParams = MeshStylePainterParameters.GetDefault(m_Mesh, m_Mat); stylePainter.DrawMesh(meshParams); } }
bool DrawUsingUIVertices(IStylePainterInternal painter) { if (edgeWidth <= 0) { return(true); } UpdateRenderPoints(); if (m_RenderPoints.Count == 0) { return(true); // Don't draw anything } Color inColor = this.inputColor; Color outColor = this.outputColor; inColor *= UIElementsUtility.editorPlayModeTintColor; outColor *= UIElementsUtility.editorPlayModeTintColor; uint cpt = (uint)m_RenderPoints.Count; uint wantedLength = (cpt) * 2; uint indexCount = (wantedLength - 2) * 3; NativeSlice <Vertex> vertices; NativeSlice <UInt16> indices; var meshParams = MeshStylePainterParameters.GetDefault(null, wantedLength, indexCount); meshParams.uvIsDisplacement = true; // We store displacement data in the UV channel painter.DrawMesh(MeshStylePainterParameters.GetDefault(null, wantedLength, indexCount), out vertices, out indices); if (vertices.Length == 0) { return(false); } 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; float flags = (float)VertexFlags.LastType; 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); int index = i * 2; vertices[index] = new Vertex() { position = new Vector3(pos.x, pos.y, 1), uv = uv, tint = tint, flags = flags }; vertices[index + 1] = new Vertex() { position = new Vector3(pos.x, pos.y, -1), uv = uv, tint = tint, flags = flags }; 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) { int index = (int)(i * 3); if ((i & 0x01) == 0) { indices[index] = (UInt16)i; indices[index + 1] = (UInt16)(i + 1); indices[index + 2] = (UInt16)(i + 2); } else { indices[index] = (UInt16)(i + 1); indices[index + 1] = (UInt16)i; indices[index + 2] = (UInt16)(i + 2); } } return(true); }
public void DrawMesh(MeshStylePainterParameters painterParameters) { // Unused }