예제 #1
0
    void Update()
    {
        if (ranTests)
        {
            return;
        }

        // Just some smoke tests to make sure we don't segfault.
        var gState = GetComponent <GlobalStateScript>();

        if (!gState.IsPathfinderEnabled())
        {
            return;
        }

        var path = new PFPath();

        // We should be able to clone paths.
        path.Clone();

        var canvas = new PFCanvas(gState.GetFontContext(), new Vector2(10, 10));

        // We should be able to pass empty strings.
        canvas.FillText("", new Vector2(0, 0));

        ranTests = true;
        print("Successfully ran smoke tests.");
    }
    public void OnPostRender()
    {
        var   tex          = textureCamera.targetTexture;
        var   drawableSize = new Vector2(tex.width, tex.height);
        float time         = Time.frameCount;
        var   sinTime      = Mathf.Sin(time * VELOCITY);
        var   cosTime      = Mathf.Cos(time * VELOCITY);
        var   colorTime    = time * COLOR_CYCLE_SPEED;
        var   bgColor      = colors.Sample(colorTime);
        var   fgColor      = colors.Sample(colorTime + 0.5f);

        fgColor.a = 0.75f;

        var windowCenter = drawableSize * 0.5f;
        var outerCenter  = windowCenter + OUTER_RADIUS * new Vector2(sinTime, cosTime);
        var innerCenter  = windowCenter + cosTime * INNER_RADIUS * new Vector2(1.0f, sinTime);

        textureCamera.backgroundColor = bgColor;

        if (gState.IsPathfinderEnabled())
        {
            var canvas = new PFCanvas(gState.GetFontContext(), drawableSize);
            canvas.SetLineWidth(CIRCLE_THICKNESS * SCALE);
            canvas.SetStrokeStyle(fgColor);

            drawCircles(canvas, outerCenter);
            drawCircles(canvas, innerCenter);

            canvas.QueueForRendering();
        }
    }
    private void DrawHouse(PFCanvas canvas)
    {
        var scale = 0.5f;

        canvas.Save();

        canvas.SetCurrentTransform(
            Matrix4x4.Translate(new Vector2(0, Screen.height - 160)) *
            Matrix4x4.Scale(new Vector2(scale, scale))
            );
        canvas.SetLineWidth(10.0f * scale);
        canvas.SetStrokeStyle(Color.black);
        canvas.SetFillStyle(Color.black);
        canvas.SetLineJoin(PFLineJoin.Round);

        // Draw walls.
        canvas.StrokeRect(new Rect(75.0f, 140.0f, 150.0f, 110.0f));

        // Draw door.
        canvas.FillRect(new Rect(130.0f, 190.0f, 40.0f, 60.0f));

        // Draw roof.
        var path = new PFPath();

        path.MoveTo(new Vector2(50.0f, 140.0f));
        path.LineTo(new Vector2(150.0f, 60.0f));
        path.LineTo(new Vector2(250.0f, 140.0f));
        path.ClosePath();
        canvas.StrokePath(path);

        canvas.Restore();
    }
 private void drawCircles(PFCanvas canvas, Vector2 center)
 {
     for (int index = 0; index < CIRCLE_COUNT; index++)
     {
         var radius = (index + 1) * CIRCLE_SPACING * SCALE;
         var path   = new PFPath();
         path.Ellipse(center, new Vector2(radius, radius), 0, 0, Mathf.PI * 2.0f);
         canvas.StrokePath(path);
     }
 }
    private void DrawInstructions(PFCanvas canvas)
    {
        canvas.SetFillStyle(Color.black);
        canvas.SetFontSize(24.0f);
        var textWidth = canvas.MeasureText(instructions).width;

        canvas.FillText(
            instructions,
            new Vector2(Screen.width / 2 - textWidth / 2, 40.0f)
            );
    }
    public void OnPostRender()
    {
        if (!gState.IsPathfinderEnabled())
        {
            return;
        }

        var canvas = new PFCanvas(gState.GetFontContext(), new Vector2(Screen.width, Screen.height));

        DrawHouse(canvas);
        DrawInstructions(canvas);

        canvas.QueueForRendering();
    }