Esempio n. 1
0
    private void DrawGraph()
    {
        // Background
        Vector2 startingPos = GraphArea.position;
        Rect    size        = GraphArea.rect;

        CameraPrimitives.DrawQuad(new Rect(startingPos.x, startingPos.y, size.width, size.height), BackgroundColour);

        if (samples.Count < 2)
        {
            // Don't draw unless there are at least two points.
            return;
        }

        // Draw the current samples.
        Vector2 a      = new Vector2();
        Vector2 b      = new Vector2();
        int     total  = samples.Count - 1;
        float   yStart = SupportNegatives ? size.height / 2f : 0f;

        for (int i = 0; i < total; i++)
        {
            // Draw line from this point to the next point.
            // We need to work out the X and Y positions.

            // How many vertical pixels do we have?

            float sx = size.width * ((float)i / total);
            float ex = size.width * ((float)(i + 1) / total);
            float sy = yStart + size.height * (samples[i] / Scale * (SupportNegatives ? 0.5f : 1f));
            float ey = yStart + size.height * (samples[i + 1] / Scale * (SupportNegatives ? 0.5f : 1f));

            // Apply values.
            a.x = startingPos.x + sx;
            b.x = startingPos.x + ex;
            a.y = startingPos.y + sy;
            b.y = startingPos.y + ey;

            // Draw
            CameraPrimitives.DrawLine(a, b, Color.red);
        }
    }
Esempio n. 2
0
 public void OnDestroy()
 {
     Instance = null;
 }
Esempio n. 3
0
 public void Awake()
 {
     Instance = this;
 }