public static UICircleVO Arc(this UICanvas canvas, Vector2 center, float radius, bool stroke, Color32 strokeColor, float thickness, bool fill, Color32 fillColor, float fillStart = 0, float fillAmount = 100, int segments = 360) { var vo = new UICircleVO(); vo.center = center; vo.radius = radius; vo.fillAmount = fillAmount; vo.fill = fill; vo.fillColor = fillColor; vo.stroke = stroke; vo.color = strokeColor; vo.thickness = thickness; vo.segments = segments; vo.fillStart = fillStart; canvas.DrawingGraphics.Add(vo); return(vo); }
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); } }