public void OnPopulateMesh(VertexBuffer vb) { if (_fillMesh != null && _fillMesh.method != FillMethod.None) { _fillMesh.OnPopulateMesh(vb); } else if (_scaleByTile) { float sourceW = texture.width; float sourceH = texture.height; if (texture.root == texture && texture.nativeTexture != null && texture.nativeTexture.wrapMode == TextureWrapMode.Repeat) { Rect uvRect = vb.uvRect; uvRect.width *= vb.contentRect.width / sourceW; uvRect.height *= vb.contentRect.height / sourceH; vb.AddQuad(vb.contentRect, vb.vertexColor, uvRect); vb.AddTriangles(); } else { TileFill(vb, vb.contentRect, vb.uvRect, sourceW, sourceH); vb.AddTriangles(); } } else if (_scale9Grid != null) { SliceFill(vb); } else graphics.OnPopulateMesh(vb); }
public void OnPopulateMesh(VertexBuffer vb) { Rectangle rect = texture.GetDrawRect(vb.contentRect); vb.AddQuad(rect, vb.vertexColor, vb.uvRect); vb.AddTriangles(); }
public void OnPopulateMesh(VertexBuffer vb) { Rect rect = texture.GetDrawRect(vb.contentRect); vb.AddQuad(rect, vb.vertexColor, vb.uvRect); vb.AddTriangles(); vb._isArbitraryQuad = _vertexMatrix != null; }
public void OnPopulateMesh(VertexBuffer vb) { Rect rect = texture.GetDrawRect(vb.contentRect); if (_vertexMatrix != null) //画多边形时,要对UV处理才能有正确的显示,暂时未掌握,这里用更多的面来临时解决。 { int hc = (int)Mathf.Min(Mathf.CeilToInt(rect.width / 30), 9); int vc = (int)Mathf.Min(Mathf.CeilToInt(rect.height / 30), 9); int eachPartX = Mathf.FloorToInt(rect.width / hc); int eachPartY = Mathf.FloorToInt(rect.height / vc); float x, y; for (int i = 0; i <= vc; i++) { if (i == vc) { y = rect.yMax; } else { y = rect.y + i * eachPartY; } for (int j = 0; j <= hc; j++) { if (j == hc) { x = rect.xMax; } else { x = rect.x + j * eachPartX; } vb.AddVert(new Vector3(x, y, 0)); } } for (int i = 0; i < vc; i++) { int k = i * (hc + 1); for (int j = 1; j <= hc; j++) { int m = k + j; vb.AddTriangle(m - 1, m, m + hc); vb.AddTriangle(m, m + hc + 1, m + hc); } } } else { vb.AddQuad(rect, vb.vertexColor, vb.uvRect); vb.AddTriangles(); } }
static void FillHorizontal(VertexBuffer vb, Rect vertRect, OriginHorizontal origin, float amount) { float a = vertRect.width * amount; if (origin == OriginHorizontal.Right) { vertRect.x += (vertRect.width - a); } vertRect.width = a; vb.AddQuad(vertRect); vb.AddTriangles(); }
public void OnPopulateMesh(VertexBuffer vb) { if (_fillMesh != null && _fillMesh.method != FillMethod.None) { _fillMesh.OnPopulateMesh(vb); } else if (_scaleByTile) { NTexture texture = graphics.texture; if (texture.root == texture && texture.nativeTexture != null && texture.nativeTexture.wrapMode == TextureWrapMode.Repeat) { Rect uvRect = vb.uvRect; uvRect.width *= vb.contentRect.width / texture.width * _textureScale.x; uvRect.height *= vb.contentRect.height / texture.height * _textureScale.y; vb.AddQuad(vb.contentRect, vb.vertexColor, uvRect); vb.AddTriangles(); } else { Rect contentRect = vb.contentRect; contentRect.width *= _textureScale.x; contentRect.height *= _textureScale.y; TileFill(vb, contentRect, vb.uvRect, texture.width, texture.height); vb.AddTriangles(); } } else if (_scale9Grid != null) { SliceFill(vb); } else { graphics.OnPopulateMesh(vb); } }
static void FillVertical(VertexBuffer vb, Rectangle vertRect, OriginVertical origin, float amount) { float a = vertRect.Height * amount; if (origin == OriginVertical.Bottom) { vertRect.Y += (vertRect.Height - a); } vertRect.Height = a; vb.AddQuad(vertRect); vb.AddTriangles(); }
static void FillVertical(VertexBuffer vb, Rect vertRect, int origin, float amount) { float a = vertRect.height * amount; if ((OriginHorizontal)origin == OriginHorizontal.Right || (OriginVertical)origin == OriginVertical.Bottom) { vertRect.y += (vertRect.height - a); } vertRect.height = a; vb.AddQuad(vertRect); vb.AddTriangles(); }
public void OnPopulateMesh(VertexBuffer vb, Color[] gradientColors) { Rect rect = texture.GetDrawRect(vb.contentRect); if (gradientColors != null) { vb.AddGradientColorsQuad(rect, vb.vertexColor, gradientColors, vb.uvRect); } else { vb.AddQuad(rect, vb.vertexColor, vb.uvRect); } vb.AddTriangles(); vb._isArbitraryQuad = vertexMatrix != null; }
public void OnPopulateMesh(VertexBuffer vb) { int count = rects.Count; if (count == 0) { return; } for (int i = 0; i < count; i++) { vb.AddQuad(rects[i]); } vb.AddTriangles(); }
public void OnPopulateMesh(VertexBuffer vb) { Rect rect = drawRect != null ? (Rect)drawRect : vb.contentRect; Color32 color = fillColor != null ? (Color32)fillColor : vb.vertexColor; if (lineWidth == 0) { if (color.a != 0)//optimized { vb.AddQuad(rect, color); } } else { Rect part; //left,right part = new Rect(rect.x, rect.y, lineWidth, rect.height); vb.AddQuad(part, lineColor); part = new Rect(rect.xMax - lineWidth, rect.y, lineWidth, rect.height); vb.AddQuad(part, lineColor); //top, bottom part = new Rect(rect.x + lineWidth, rect.y, rect.width - lineWidth * 2, lineWidth); vb.AddQuad(part, lineColor); part = new Rect(rect.x + lineWidth, rect.yMax - lineWidth, rect.width - lineWidth * 2, lineWidth); vb.AddQuad(part, lineColor); //middle if (color.a != 0)//optimized { part = Rect.MinMaxRect(rect.x + lineWidth, rect.y + lineWidth, rect.xMax - lineWidth, rect.yMax - lineWidth); if (part.width > 0 && part.height > 0) { vb.AddQuad(part, color); } } } if (colors != null) { vb.RepeatColors(colors, 0, vb.currentVertCount); } vb.AddTriangles(); }
public void OnPopulateMesh(VertexBuffer vb) { Rectangle rect = drawRect != null ? (Rectangle)drawRect : vb.contentRect; Color color = fillColor != null ? (Color)fillColor : vb.vertexColor; if (lineWidth == 0) { if (color.A != 0) //optimized { vb.AddQuad(rect, color); } } else { Rectangle part; //left,right part = Rectangle.FromLTRB(rect.X, rect.Y, lineWidth, rect.Height); vb.AddQuad(part, lineColor); part = Rectangle.FromLTRB(rect.Right - lineWidth, 0, rect.Right, rect.Bottom); vb.AddQuad(part, lineColor); //top, bottom part = Rectangle.FromLTRB(lineWidth, rect.X, rect.Right - lineWidth, lineWidth); vb.AddQuad(part, lineColor); part = Rectangle.FromLTRB(lineWidth, rect.Bottom - lineWidth, rect.Right - lineWidth, rect.Bottom); vb.AddQuad(part, lineColor); //middle if (color.A != 0) //optimized { part = Rectangle.FromLTRB(lineWidth, lineWidth, rect.Right - lineWidth, rect.Bottom - lineWidth); vb.AddQuad(part, color); } } if (colors != null) { vb.RepeatColors(colors, 0, vb.currentVertCount); } vb.AddTriangles(); }
public void OnPopulateMesh(VertexBuffer vb) { if (origin == end) { return; } float length = Vector2.Distance(origin, end); Vector3 lineVector = end - origin; Vector3 widthVector = Vector3.Cross(lineVector, new Vector3(0, 0, 1)); widthVector.Normalize(); Vector3 v0, v1, v2, v3; if (repeatFill) { float ratio = length / vb.textureSize.x; v0 = VertexBuffer.NormalizedUV[0]; v1 = VertexBuffer.NormalizedUV[1]; v2 = new Vector2(ratio, 1); v3 = new Vector2(ratio, 0); } else { v0 = new Vector2(vb.uvRect.xMin, vb.uvRect.yMin); v1 = new Vector2(vb.uvRect.xMin, vb.uvRect.yMax); v2 = new Vector2(vb.uvRect.xMax, vb.uvRect.yMax); v3 = new Vector2(vb.uvRect.xMax, vb.uvRect.yMin); } vb.AddVert(origin - widthVector * lineWidth * 0.5f, color, v0); vb.AddVert(origin + widthVector * lineWidth * 0.5f, color, v1); vb.AddVert(end + widthVector * lineWidth * 0.5f, color, v2); vb.AddVert(end - widthVector * lineWidth * 0.5f, color, v3); vb.AddTriangles(); }
public void SliceFill(VertexBuffer vb) { Rect gridRect = (Rect)_scale9Grid; Rect contentRect = vb.contentRect; Rect uvRect = vb.uvRect; float sourceW = texture.width; float sourceH = texture.height; if (graphics.flip != FlipType.None) { if (graphics.flip == FlipType.Horizontal || graphics.flip == FlipType.Both) { gridRect.x = sourceW - gridRect.xMax; gridRect.xMax = gridRect.x + gridRect.width; } if (graphics.flip == FlipType.Vertical || graphics.flip == FlipType.Both) { gridRect.y = sourceH - gridRect.yMax; gridRect.yMax = gridRect.y + gridRect.height; } } float sx = uvRect.width / sourceW; float sy = uvRect.height / sourceH; float xMax = uvRect.xMax; float yMax = uvRect.yMax; float xMax2 = gridRect.xMax; float yMax2 = gridRect.yMax; gridTexX[0] = uvRect.x; gridTexX[1] = uvRect.x + gridRect.x * sx; gridTexX[2] = uvRect.x + xMax2 * sx; gridTexX[3] = xMax; gridTexY[0] = yMax; gridTexY[1] = yMax - gridRect.y * sy; gridTexY[2] = yMax - yMax2 * sy; gridTexY[3] = uvRect.y; if (contentRect.width >= (sourceW - gridRect.width)) { gridX[1] = gridRect.x; gridX[2] = contentRect.width - (sourceW - xMax2); gridX[3] = contentRect.width; } else { float tmp = gridRect.x / (sourceW - xMax2); tmp = contentRect.width * tmp / (1 + tmp); gridX[1] = tmp; gridX[2] = tmp; gridX[3] = contentRect.width; } if (contentRect.height >= (sourceH - gridRect.height)) { gridY[1] = gridRect.y; gridY[2] = contentRect.height - (sourceH - yMax2); gridY[3] = contentRect.height; } else { float tmp = gridRect.y / (sourceH - yMax2); tmp = contentRect.height * tmp / (1 + tmp); gridY[1] = tmp; gridY[2] = tmp; gridY[3] = contentRect.height; } if (_tileGridIndice == 0) { for (int cy = 0; cy < 4; cy++) { for (int cx = 0; cx < 4; cx++) { vb.AddVert(new Vector2(gridX[cx], gridY[cy]), vb.vertexColor, new Vector2(gridTexX[cx], gridTexY[cy])); } } vb.AddTriangles(TRIANGLES_9_GRID); } else { Rect drawRect; Rect texRect; int row, col; int part; for (int pi = 0; pi < 9; pi++) { col = pi % 3; row = pi / 3; part = gridTileIndice[pi]; drawRect = Rect.MinMaxRect(gridX[col], gridY[row], gridX[col + 1], gridY[row + 1]); texRect = Rect.MinMaxRect(gridTexX[col], gridTexY[row + 1], gridTexX[col + 1], gridTexY[row]); if (part != -1 && (_tileGridIndice & (1 << part)) != 0) { TileFill(vb, drawRect, texRect, (part == 0 || part == 1 || part == 4) ? gridRect.width : drawRect.width, (part == 2 || part == 3 || part == 4) ? gridRect.height : drawRect.height); } else { vb.AddQuad(drawRect, vb.vertexColor, texRect); } } vb.AddTriangles(); } }
//12 vertex static void FillRadial360(VertexBuffer vb, Rect vertRect, Origin360 origin, float amount, bool clockwise) { switch (origin) { case Origin360.Top: if (amount < 0.5f) { vertRect.width /= 2; if (clockwise) { vertRect.x += vertRect.width; } FillRadial180(vb, vertRect, clockwise ? Origin180.Left : Origin180.Right, amount / 0.5f, clockwise); Vector3 vec = vb.GetPosition(-8); vb.AddQuad(new Rect(vec.x, vec.y, 0, 0)); vb.AddTriangles(-4); } else { vertRect.width /= 2; if (!clockwise) { vertRect.x += vertRect.width; } FillRadial180(vb, vertRect, clockwise ? Origin180.Right : Origin180.Left, (amount - 0.5f) / 0.5f, clockwise); if (clockwise) { vertRect.x += vertRect.width; } else { vertRect.x -= vertRect.width; } vb.AddQuad(vertRect); vb.AddTriangles(-4); } break; case Origin360.Bottom: if (amount < 0.5f) { vertRect.width /= 2; if (!clockwise) { vertRect.x += vertRect.width; } FillRadial180(vb, vertRect, clockwise ? Origin180.Right : Origin180.Left, amount / 0.5f, clockwise); Vector3 vec = vb.GetPosition(-8); vb.AddQuad(new Rect(vec.x, vec.y, 0, 0)); vb.AddTriangles(-4); } else { vertRect.width /= 2; if (clockwise) { vertRect.x += vertRect.width; } FillRadial180(vb, vertRect, clockwise ? Origin180.Left : Origin180.Right, (amount - 0.5f) / 0.5f, clockwise); if (clockwise) { vertRect.x -= vertRect.width; } else { vertRect.x += vertRect.width; } vb.AddQuad(vertRect); vb.AddTriangles(-4); } break; case Origin360.Left: if (amount < 0.5f) { vertRect.height /= 2; if (!clockwise) { vertRect.y += vertRect.height; } FillRadial180(vb, vertRect, clockwise ? Origin180.Bottom : Origin180.Top, amount / 0.5f, clockwise); Vector3 vec = vb.GetPosition(-8); vb.AddQuad(new Rect(vec.x, vec.y, 0, 0)); vb.AddTriangles(-4); } else { vertRect.height /= 2; if (clockwise) { vertRect.y += vertRect.height; } FillRadial180(vb, vertRect, clockwise ? Origin180.Top : Origin180.Bottom, (amount - 0.5f) / 0.5f, clockwise); if (clockwise) { vertRect.y -= vertRect.height; } else { vertRect.y += vertRect.height; } vb.AddQuad(vertRect); vb.AddTriangles(-4); } break; case Origin360.Right: if (amount < 0.5f) { vertRect.height /= 2; if (clockwise) { vertRect.y += vertRect.height; } FillRadial180(vb, vertRect, clockwise ? Origin180.Top : Origin180.Bottom, amount / 0.5f, clockwise); Vector3 vec = vb.GetPosition(-8); vb.AddQuad(new Rect(vec.x, vec.y, 0, 0)); vb.AddTriangles(-4); } else { vertRect.height /= 2; if (!clockwise) { vertRect.y += vertRect.height; } FillRadial180(vb, vertRect, clockwise ? Origin180.Bottom : Origin180.Top, (amount - 0.5f) / 0.5f, clockwise); if (clockwise) { vertRect.y += vertRect.height; } else { vertRect.y -= vertRect.height; } vb.AddQuad(vertRect); vb.AddTriangles(-4); } break; } }
public void SliceFill(VertexBuffer vb) { Rect gridRect = (Rect)_scale9Grid; Rect contentRect = vb.contentRect; Rect uvRect = vb.uvRect; float sourceW = texture.width; float sourceH = texture.height; float sx = uvRect.width / sourceW; float sy = uvRect.height / sourceH; float xMax = uvRect.xMax; float yMax = uvRect.yMax; float xMax2 = gridRect.xMax; float yMax2 = gridRect.yMax; gridTexX[0] = uvRect.x; gridTexX[1] = uvRect.x + gridRect.x * sx; gridTexX[2] = uvRect.x + xMax2 * sx; gridTexX[3] = xMax; gridTexY[0] = yMax; gridTexY[1] = yMax - gridRect.y * sy; gridTexY[2] = yMax - yMax2 * sy; gridTexY[3] = uvRect.y; if (contentRect.width >= (sourceW - gridRect.width)) { gridX[1] = gridRect.x; gridX[2] = contentRect.width - (sourceW - xMax2); gridX[3] = contentRect.width; } else { float tmp = gridRect.x / (sourceW - xMax2); tmp = contentRect.width * tmp / (1 + tmp); gridX[1] = tmp; gridX[2] = tmp; gridX[3] = contentRect.width; } if (contentRect.height >= (sourceH - gridRect.height)) { gridY[1] = gridRect.y; gridY[2] = contentRect.height - (sourceH - yMax2); gridY[3] = contentRect.height; } else { float tmp = gridRect.y / (sourceH - yMax2); tmp = contentRect.height * tmp / (1 + tmp); gridY[1] = tmp; gridY[2] = tmp; gridY[3] = contentRect.height; } if (_tileGridIndice == 0) { for (int cy = 0; cy < 4; cy++) { for (int cx = 0; cx < 4; cx++) { vb.AddVert(new Vector2(gridX[cx], gridY[cy]), vb.vertexColor, new Vector2(gridTexX[cx], gridTexY[cy])); } } vb.AddTriangles(TRIANGLES_9_GRID); } else { int hc, vc; Rect drawRect; Rect texRect; int row, col; int part; //先计算需要的顶点数量 int vertCount = 0; for (int pi = 0; pi < 9; pi++) { col = pi % 3; row = pi / 3; part = gridTileIndice[pi]; if (part != -1 && (_tileGridIndice & (1 << part)) != 0) { if (part == 0 || part == 1 || part == 4) { hc = Mathf.CeilToInt((gridX[col + 1] - gridX[col]) / gridRect.width); } else { hc = 1; } if (part == 2 || part == 3 || part == 4) { vc = Mathf.CeilToInt((gridY[row + 1] - gridY[row]) / gridRect.height); } else { vc = 1; } vertCount += hc * vc * 4; } else { vertCount += 4; } } for (int pi = 0; pi < 9; pi++) { col = pi % 3; row = pi / 3; part = gridTileIndice[pi]; drawRect = Rect.MinMaxRect(gridX[col], gridY[row], gridX[col + 1], gridY[row + 1]); texRect = Rect.MinMaxRect(gridTexX[col], gridTexY[row + 1], gridTexX[col + 1], gridTexY[row]); if (part != -1 && (_tileGridIndice & (1 << part)) != 0) { TileFill(vb, drawRect, texRect, (part == 0 || part == 1 || part == 4) ? gridRect.width : drawRect.width, (part == 2 || part == 3 || part == 4) ? gridRect.height : drawRect.height); } else { vb.AddQuad(drawRect, vb.vertexColor, texRect); } } vb.AddTriangles(); } }
public void OnPopulateMesh(VertexBuffer vb) { Rect rect = drawRect != null ? (Rect)drawRect : vb.contentRect; Color32 color = fillColor != null ? (Color32)fillColor : vb.vertexColor; float sectionStart = Mathf.Clamp(startDegree, 0, 360); float sectionEnd = Mathf.Clamp(endDegreee, 0, 360); bool clipped = sectionStart > 0 || sectionEnd < 360; sectionStart = sectionStart * Mathf.Deg2Rad; sectionEnd = sectionEnd * Mathf.Deg2Rad; Color32 centerColor2 = centerColor == null ? color : (Color32)centerColor; float radiusX = rect.width / 2; float radiusY = rect.height / 2; int sides = Mathf.CeilToInt(Mathf.PI * (radiusX + radiusY) / 4); sides = Mathf.Clamp(sides, 40, 800); float angleDelta = 2 * Mathf.PI / sides; float angle = 0; float lineAngle = 0; if (lineWidth > 0 && clipped) { lineAngle = lineWidth / Mathf.Max(radiusX, radiusY); sectionStart += lineAngle; sectionEnd -= lineAngle; } int vpos = vb.currentVertCount; float centerX = rect.x + radiusX; float centerY = rect.y + radiusY; vb.AddVert(new Vector3(centerX, centerY, 0), centerColor2); for (int i = 0; i < sides; i++) { if (angle < sectionStart) { angle = sectionStart; } else if (angle > sectionEnd) { angle = sectionEnd; } Vector3 vec = new Vector3(Mathf.Cos(angle) * (radiusX - lineWidth) + centerX, Mathf.Sin(angle) * (radiusY - lineWidth) + centerY, 0); vb.AddVert(vec, color); if (lineWidth > 0) { vb.AddVert(vec, lineColor); vb.AddVert(new Vector3(Mathf.Cos(angle) * radiusX + centerX, Mathf.Sin(angle) * radiusY + centerY, 0), lineColor); } angle += angleDelta; } if (lineWidth > 0) { int cnt = sides * 3; for (int i = 0; i < cnt; i += 3) { if (i != cnt - 3) { vb.AddTriangle(0, i + 1, i + 4); vb.AddTriangle(i + 5, i + 2, i + 3); vb.AddTriangle(i + 3, i + 6, i + 5); } else if (!clipped) { vb.AddTriangle(0, i + 1, 1); vb.AddTriangle(2, i + 2, i + 3); vb.AddTriangle(i + 3, 3, 2); } else { vb.AddTriangle(0, i + 1, i + 1); vb.AddTriangle(i + 2, i + 2, i + 3); vb.AddTriangle(i + 3, i + 3, i + 2); } } } else { for (int i = 0; i < sides; i++) { if (i != sides - 1) { vb.AddTriangle(0, i + 1, i + 2); } else if (!clipped) { vb.AddTriangle(0, i + 1, 1); } else { vb.AddTriangle(0, i + 1, i + 1); } } } if (lineWidth > 0 && clipped) { //扇形内边缘的线条 vb.AddVert(new Vector3(radiusX, radiusY, 0), lineColor); float centerRadius = lineWidth * 0.5f; sectionStart -= lineAngle; angle = sectionStart + lineAngle * 0.5f + Mathf.PI * 0.5f; vb.AddVert(new Vector3(Mathf.Cos(angle) * centerRadius + radiusX, Mathf.Sin(angle) * centerRadius + radiusY, 0), lineColor); angle -= Mathf.PI; vb.AddVert(new Vector3(Mathf.Cos(angle) * centerRadius + radiusX, Mathf.Sin(angle) * centerRadius + radiusY, 0), lineColor); vb.AddVert(new Vector3(Mathf.Cos(sectionStart) * radiusX + radiusX, Mathf.Sin(sectionStart) * radiusY + radiusY, 0), lineColor); vb.AddVert(vb.GetPosition(vpos + 3), lineColor); sectionEnd += lineAngle; angle = sectionEnd - lineAngle * 0.5f + Mathf.PI * 0.5f; vb.AddVert(new Vector3(Mathf.Cos(angle) * centerRadius + radiusX, Mathf.Sin(angle) * centerRadius + radiusY, 0), lineColor); angle -= Mathf.PI; vb.AddVert(new Vector3(Mathf.Cos(angle) * centerRadius + radiusX, Mathf.Sin(angle) * centerRadius + radiusY, 0), lineColor); vb.AddVert(vb.GetPosition(vpos + sides * 3), lineColor); vb.AddVert(new Vector3(Mathf.Cos(sectionEnd) * radiusX + radiusX, Mathf.Sin(sectionEnd) * radiusY + radiusY, 0), lineColor); vb.AddTriangles(SECTOR_CENTER_TRIANGLES, sides * 3 + 1); } }
//8 vertex static void FillRadial180(VertexBuffer vb, Rectangle vertRect, Origin180 origin, float amount, bool clockwise) { switch (origin) { case Origin180.Top: if (amount <= 0.5f) { vertRect.Width /= 2; if (clockwise) { vertRect.X += vertRect.Width; } FillRadial90(vb, vertRect, clockwise ? Origin90.TopLeft : Origin90.TopRight, amount / 0.5f, clockwise); Vector3 vec = vb.GetPosition(-4); vb.AddQuad(new Rectangle(vec.X, vec.Y, 0, 0)); vb.AddTriangles(-4); } else { vertRect.Width /= 2; if (!clockwise) { vertRect.X += vertRect.Width; } FillRadial90(vb, vertRect, clockwise ? Origin90.TopRight : Origin90.TopLeft, (amount - 0.5f) / 0.5f, clockwise); if (clockwise) { vertRect.X += vertRect.Width; } else { vertRect.X -= vertRect.Width; } vb.AddQuad(vertRect); vb.AddTriangles(-4); } break; case Origin180.Bottom: if (amount <= 0.5f) { vertRect.Width /= 2; if (!clockwise) { vertRect.X += vertRect.Width; } FillRadial90(vb, vertRect, clockwise ? Origin90.BottomRight : Origin90.BottomLeft, amount / 0.5f, clockwise); Vector3 vec = vb.GetPosition(-4); vb.AddQuad(new Rectangle(vec.X, vec.Y, 0, 0)); vb.AddTriangles(-4); } else { vertRect.Width /= 2; if (clockwise) { vertRect.X += vertRect.Width; } FillRadial90(vb, vertRect, clockwise ? Origin90.BottomLeft : Origin90.BottomRight, (amount - 0.5f) / 0.5f, clockwise); if (clockwise) { vertRect.X -= vertRect.Width; } else { vertRect.X += vertRect.Width; } vb.AddQuad(vertRect); vb.AddTriangles(-4); } break; case Origin180.Left: if (amount <= 0.5f) { vertRect.Height /= 2; if (!clockwise) { vertRect.Y += vertRect.Height; } FillRadial90(vb, vertRect, clockwise ? Origin90.BottomLeft : Origin90.TopLeft, amount / 0.5f, clockwise); Vector3 vec = vb.GetPosition(-4); vb.AddQuad(new Rectangle(vec.X, vec.Y, 0, 0)); vb.AddTriangles(-4); } else { vertRect.Height /= 2; if (clockwise) { vertRect.Y += vertRect.Height; } FillRadial90(vb, vertRect, clockwise ? Origin90.TopLeft : Origin90.BottomLeft, (amount - 0.5f) / 0.5f, clockwise); if (clockwise) { vertRect.Y -= vertRect.Height; } else { vertRect.Y += vertRect.Height; } vb.AddQuad(vertRect); vb.AddTriangles(-4); } break; case Origin180.Right: if (amount <= 0.5f) { vertRect.Height /= 2; if (clockwise) { vertRect.Y += vertRect.Height; } FillRadial90(vb, vertRect, clockwise ? Origin90.TopRight : Origin90.BottomRight, amount / 0.5f, clockwise); Vector3 vec = vb.GetPosition(-4); vb.AddQuad(new Rectangle(vec.X, vec.Y, 0, 0)); vb.AddTriangles(-4); } else { vertRect.Height /= 2; if (!clockwise) { vertRect.Y += vertRect.Height; } FillRadial90(vb, vertRect, clockwise ? Origin90.BottomRight : Origin90.TopRight, (amount - 0.5f) / 0.5f, clockwise); if (clockwise) { vertRect.Y += vertRect.Height; } else { vertRect.Y -= vertRect.Height; } vb.AddQuad(vertRect); vb.AddTriangles(-4); } break; } }
public void SliceFill(VertexBuffer vb) { Rectangle gridRect = (Rectangle)_scale9Grid; Rectangle contentRect = vb.contentRect; Rectangle uvRect = vb.uvRect; float sourceW = texture.width; float sourceH = texture.height; float sx = uvRect.Width / sourceW; float sy = uvRect.Height / sourceH; float xMax = uvRect.Right; float yMax = uvRect.Bottom; float xMax2 = gridRect.Right; float yMax2 = gridRect.Bottom; gridTexX[0] = uvRect.X; gridTexX[1] = uvRect.X + gridRect.X * sx; gridTexX[2] = uvRect.X + xMax2 * sx; gridTexX[3] = xMax; gridTexY[0] = yMax; gridTexY[1] = yMax - gridRect.Y * sy; gridTexY[2] = yMax - yMax2 * sy; gridTexY[3] = uvRect.Y; if (contentRect.Width >= (sourceW - gridRect.Width)) { gridX[1] = gridRect.X; gridX[2] = contentRect.Width - (sourceW - xMax2); gridX[3] = contentRect.Width; } else { float tmp = gridRect.X / (sourceW - xMax2); tmp = contentRect.Width * tmp / (1 + tmp); gridX[1] = tmp; gridX[2] = tmp; gridX[3] = contentRect.Width; } if (contentRect.Height >= (sourceH - gridRect.Height)) { gridY[1] = gridRect.Y; gridY[2] = contentRect.Height - (sourceH - yMax2); gridY[3] = contentRect.Height; } else { float tmp = gridRect.Y / (sourceH - yMax2); tmp = contentRect.Height * tmp / (1 + tmp); gridY[1] = tmp; gridY[2] = tmp; gridY[3] = contentRect.Height; } if (_tileGridIndice == 0) { for (int cy = 0; cy < 4; cy++) { for (int cx = 0; cx < 4; cx++) { vb.AddVert(new Vector3(gridX[cx], gridY[cy], 0), vb.vertexColor, new Vector2(gridTexX[cx], gridTexY[cy])); } } vb.AddTriangles(TRIANGLES_9_GRID); } else { Rectangle drawRect; Rectangle texRect; int row, col; int part; for (int pi = 0; pi < 9; pi++) { col = pi % 3; row = pi / 3; part = gridTileIndice[pi]; drawRect = Rectangle.FromLTRB(gridX[col], gridY[row], gridX[col + 1], gridY[row + 1]); texRect = Rectangle.FromLTRB(gridTexX[col], gridTexY[row + 1], gridTexX[col + 1], gridTexY[row]); if (part != -1 && (_tileGridIndice & (1 << part)) != 0) { TileFill(vb, drawRect, texRect, (part == 0 || part == 1 || part == 4) ? gridRect.Width : drawRect.Width, (part == 2 || part == 3 || part == 4) ? gridRect.Height : drawRect.Height); } else { vb.AddQuad(drawRect, vb.vertexColor, texRect); } } vb.AddTriangles(); } }