예제 #1
0
    // Update is called once per frame
    void Update()
    {
        DestroySpriteIfNeeded();

        var lineSegment     = VectorUtils.MakeLine(from, to);
        var lineSegmentPath = VectorUtils.BezierSegmentToPath(lineSegment);

        var path = new Shape()
        {
            Contours = new BezierContour[] { new BezierContour()
                                             {
                                                 Segments = lineSegmentPath
                                             } },
            PathProps = new PathProperties()
            {
                Stroke = new Stroke()
                {
                    Color = pathColor, HalfThickness = pathHalfThickness
                }
            }
        };

        var options = MakeLineOptions(stepDistance);
        var geo     = BuildGeometry(path, options);
        var sprite  = VectorUtils.BuildSprite(
            geo, 1.0f,
            VectorUtils.Alignment.Center,
            Vector2.zero, 128);

        spriteRenderer.sprite = sprite;
    }
    public void BezierSegmentToPath_ReturnsBezierPathSegments()
    {
        var points = new Vector2[4];

        for (int i = 0; i < points.Length; ++i)
        {
            points[i] = Vector2.one * i;
        }

        var seg = new BezierSegment()
        {
            P0 = points[0], P1 = points[1], P2 = points[2], P3 = points[3]
        };
        var pathSeg = VectorUtils.BezierSegmentToPath(seg);

        Assert.AreEqual(2, pathSeg.Length);
        Assert.AreEqual(points[0], pathSeg[0].P0);
        Assert.AreEqual(points[1], pathSeg[0].P1);
        Assert.AreEqual(points[2], pathSeg[0].P2);
        Assert.AreEqual(points[3], pathSeg[1].P0);
    }