/// <summary> /// Modifies the mesh. /// </summary> public override void ModifyMesh(VertexHelper vh) { // Invalid. if (!isActiveAndEnabled || vh.currentVertCount == 0 || (vh.currentVertCount % 4 != 0 && vh.currentVertCount % 6 != 0)) { return; } _rect = graphic.rectTransform.rect; var quad = UIVertexUtil.s_QuadVerts; var inputVerts = UIVertexUtil.s_InputVerts; var outputVerts = UIVertexUtil.s_OutputVerts; inputVerts.Clear(); outputVerts.Clear(); vh.GetUIVertexStream(inputVerts); for (int i = 0; i < inputVerts.Count; i += 6) { if (graphic is Text) { quad[0] = inputVerts[i + 4]; // bottom-left quad[1] = inputVerts[i + 0]; // top-left quad[2] = inputVerts[i + 1]; // top-right quad[3] = inputVerts[i + 2]; // bottom-right } else { quad[0] = inputVerts[i + 0]; // bottom-left quad[1] = inputVerts[i + 1]; // top-left quad[2] = inputVerts[i + 2]; // top-right quad[3] = inputVerts[i + 4]; // bottom-right } var originalQuad = new UIVertex[quad.Length]; Array.Copy(quad, originalQuad, quad.Length); AddMirrorReflectedQuad(quad, outputVerts); // reflected quad UIVertexUtil.AddQuadToStream(originalQuad, outputVerts); // origin quad } vh.Clear(); vh.AddUIVertexTriangleStream(outputVerts); inputVerts.Clear(); outputVerts.Clear(); }
void AddMirrorReflectedQuad(UIVertex[] quad, List <UIVertex> result) { // Read the existing quad vertices UIVertex v0 = quad[0]; // bottom-left UIVertex v1 = quad[1]; // top-left UIVertex v2 = quad[2]; // top-right UIVertex v3 = quad[3]; // bottom-right // Reflection is unnecessary. if (m_Height < (v0.position.y - _rect.yMin) && m_Height < (v3.position.y - _rect.yMin)) { return; } // Trim quad. if (m_Height < (v1.position.y - _rect.yMin) || m_Height < (v2.position.y - _rect.yMin)) { v1 = UIVertexUtil.Lerp(v0, v1, GetLerpFactor(v0.position.y, v1.position.y)); v2 = UIVertexUtil.Lerp(v3, v2, GetLerpFactor(v3.position.y, v2.position.y)); } // Calculate reflected position and color. MirrorReflectVertex(ref v0); MirrorReflectVertex(ref v1); MirrorReflectVertex(ref v2); MirrorReflectVertex(ref v3); // Reverse quad index. quad[0] = v1; quad[1] = v0; quad[2] = v3; quad[3] = v2; // Add reflected quad. UIVertexUtil.AddQuadToStream(quad, result); }