public static void DrawRect(this UICanvas canvas, List <UIVertex> vertices, List <int> indices, UIRectVO rectVO) { Rect rect = rectVO.rect; Vector2 TL = rect.position; Vector2 TR = new Vector2(rect.xMax, rect.yMin); Vector2 BR = new Vector2(rect.xMax, rect.yMax); Vector2 BL = new Vector2(rect.xMin, rect.yMax); if (rectVO.fill) { var polygon = new List <Vector2>() { TL, TR, BR, BL }; canvas.FillPolygon(vertices, indices, polygon, rectVO.fillColor, rectVO.name); } if (rectVO.stroke) { var polygon = new List <Vector2>() { TL, TR, BR, BL, TL }; canvas.StrokePolygon(vertices, indices, polygon, rectVO.thickness, rectVO.strokeColor); } }
public static void DrawLine(this UICanvas canvas, List <UIVertex> vertices, List <int> indices, UILineVO line) { if (line.fill) { FillPolygon(canvas, vertices, indices, line); } if (line.stroke) { canvas.StrokePolygon(vertices, indices, line.points, line.thickness, line.color); } }
public static void DrawCircle(this UICanvas canvas, List <UIVertex> vertices, List <int> indices, UICircleVO circle) { float f = (circle.fillAmount / 100f); float fs = (circle.fillStart / 100f); float degrees = 360f / circle.segments; float fa = (circle.segments) * f; float start = (circle.segments) * fs; List <Vector2> allV = new List <Vector2>(); float i = start * degrees; float end = (fa + start) * degrees; while (i <= end) { float rad = Mathf.Deg2Rad * i; float c = Mathf.Cos(rad); float s = Mathf.Sin(rad); Vector2 p0 = new Vector2(circle.center.x + circle.radius * c, circle.center.y + circle.radius * s); // 外边框 顶点0 allV.Add(p0); if (i == end) { break; } i = Mathf.Min(i + degrees, end); } List <Vector2> polygonVertices = allV.ToArray().ToList(); if (circle.fillAmount < 100) { polygonVertices.Add(circle.center); } else { polygonVertices = polygonVertices.GetRange(0, polygonVertices.Count - 1); } if (circle.fill) { canvas.FillPolygon(vertices, indices, polygonVertices, circle.fillColor); } if (circle.stroke) { canvas.StrokePolygon(vertices, indices, allV, circle.thickness, circle.color); } }