public void UpdateLine(int objectNumber, Vector2 pos, GameObject go)
    {
        var oldPos = controlLine.points2[objectNumber];         // Get previous position, so we can make the control point move with the anchor point

        controlLine.points2[objectNumber] = pos;
        int curveNumber = objectNumber / 4;
        int curveIndex  = curveNumber * 4;

        line.MakeCurve(controlLine.points2[curveIndex], controlLine.points2[curveIndex + 1], controlLine.points2[curveIndex + 2], controlLine.points2[curveIndex + 3],
                       segments, curveNumber * (segments + 1));

        // If it's an anchor point...
        if (objectNumber % 2 == 0)
        {
            // Move control point also
            controlLine.points2[objectNumber + 1] += pos - oldPos;
            go.GetComponent <CurvePointControl>().controlObject.transform.position = cam.ScreenToViewportPoint(controlLine.points2[objectNumber + 1]);
            // If it's not an end anchor point, move the next anchor/control points as well, and update the next curve
            if (objectNumber > 0 && objectNumber < controlLine.points2.Count - 2)
            {
                controlLine.points2[objectNumber + 2]  = pos;
                controlLine.points2[objectNumber + 3] += pos - oldPos;
                go.GetComponent <CurvePointControl>().controlObject2.transform.position = cam.ScreenToViewportPoint(controlLine.points2[objectNumber + 3]);
                line.MakeCurve(controlLine.points2[curveIndex + 4], controlLine.points2[curveIndex + 5], controlLine.points2[curveIndex + 6], controlLine.points2[curveIndex + 7],
                               segments, (curveNumber + 1) * (segments + 1));
            }
        }

        line.Draw();
        controlLine.Draw();
    }
    void Start()
    {
        use         = this;     // Reference to this script, so FindObjectOfType etc. are not needed
        cam         = Camera.main;
        oldWidth    = Screen.width;
        oldSegments = segments;

        // Set up initial curve points (also used for drawing the green lines that connect control points to anchor points)
        var curvePoints = new List <Vector2>();

        curvePoints.Add(new Vector2(Screen.width * .25f, Screen.height * .25f));
        curvePoints.Add(new Vector2(Screen.width * .125f, Screen.height * .5f));
        curvePoints.Add(new Vector2(Screen.width - Screen.width * .25f, Screen.height - Screen.height * .25f));
        curvePoints.Add(new Vector2(Screen.width - Screen.width * .125f, Screen.height * .5f));

        // Make the control lines
        controlLine       = new VectorLine("Control Line", curvePoints, 2.0f);
        controlLine.color = new Color(0.0f, .75f, .1f, .6f);
        controlLine.Draw();

        // Make the line object for the curve
        line = new VectorLine("Curve", new List <Vector2>(segments + 1), lineTexture, 5.0f, LineType.Continuous, Joins.Weld);

        // Create a curve in the VectorLine object
        line.MakeCurve(curvePoints[0], curvePoints[1], curvePoints[2], curvePoints[3], segments);
        line.Draw();

        // Make the GUITexture objects for anchor and control points (two anchor points and two control points)
        AddControlObjects();
        AddControlObjects();
    }
Esempio n. 3
0
    // Token: 0x06000B01 RID: 2817 RVA: 0x00030F04 File Offset: 0x0002F304
    private void Start()
    {
        if (this.curvePoints.Length != 4)
        {
            Debug.Log("Curve points array must have 4 elements only");
            return;
        }
        List <Vector2> points     = new List <Vector2>(this.segments + 1);
        VectorLine     vectorLine = new VectorLine("Curve", points, 2f, LineType.Continuous, Joins.Weld);

        vectorLine.MakeCurve(this.curvePoints, this.segments);
        vectorLine.Draw();
    }
Esempio n. 4
0
 private void Start()
 {
     if (this.curvePoints.Length != 4)
     {
         Debug.Log((object)"Curve points array must have 4 elements only");
     }
     else
     {
         VectorLine vectorLine = new VectorLine("Curve", new List <Vector2>(this.segments + 1), 2f, (LineType)0, (Joins)1);
         vectorLine.MakeCurve(this.curvePoints, this.segments);
         vectorLine.Draw();
     }
 }
Esempio n. 5
0
    void Start()
    {
        if (curvePoints.Length != 4)
        {
            Debug.Log("Curve points array must have 4 elements only");
            return;
        }

        // Make Vector2 list where the size is the number of segments plus one, since it's for a continuous line
        // (A discrete line would need the size to be segments*2)
        var linePoints = new List <Vector2>(segments + 1);

        // Make a VectorLine object using the above points and the default material,
        // with a width of 2 pixels, an end cap of 0 pixels, and depth 0
        var line = new VectorLine("Curve", linePoints, 2.0f, LineType.Continuous, Joins.Weld);

        // Create a curve in the VectorLine object using the curvePoints array as defined in the inspector
        line.MakeCurve(curvePoints, segments);

        // Draw the line
        line.Draw();
    }