Hello everyone,
I’m currently trying to draw a circle using the Vector Graphic library. And it’s not quite pretty neither simple.
I don’t want to use the Unity’s RadialProgress example because it generates a mesh ; I want to do that with svg. I found that VisualElements have an event generateVisualContent
. So, I subscribe to it and when my element is renderer, I create a shape that I fill with the VectorUtils.MakeCircleShape
method. But when I draw the contours, it seems broken.
private void OnGenerateVisualContent(MeshGenerationContext context)
{
var center = new Vector2(
context.visualElement.resolvedStyle.width / 2,
context.visualElement.resolvedStyle.height / 2);
Shape shape = new();
VectorUtils.MakeCircleShape(shape, center, 100);
var paint2D = context.painter2D;
paint2D.strokeColor = Color.black;
paint2D.fillColor = Color.yellow;
foreach (var contour in shape.Contours)
{
paint2D.BeginPath();
foreach (var segment in contour.Segments)
paint2D.BezierCurveTo(segment.P0, segment.P1, segment.P2);
paint2D.ClosePath();
}
paint2D.Fill();
paint2D.Stroke();
}
I know that Vector Graphics are still on the UITK roadmap, but I want to know if someone has already tried to draw simple elements using this package and UITK. Also, it seems weird that there are no methods to draw simple shapes by using the painter2D ; maybe I’m using it badly?
Thank you