Ejemplo n.º 1
0
    void DrawGeometry(Geometry geo)
    {
        wkbGeometryType t = Ogr.GT_Flatten(geo.GetGeometryType());

        switch (t)
        {
        case wkbGeometryType.wkbUnknown:
            break;

        case wkbGeometryType.wkbPoint:
            break;

        case wkbGeometryType.wkbPolygon:
        {
            Geometry linestring = geo.GetGeometryRef(0);
            if (Ogr.GT_Flatten(linestring.GetGeometryType()) == wkbGeometryType.wkbLineString)
            {
                DrawGeometry(linestring);
            }
        }
        break;

        case wkbGeometryType.wkbLineString:
        {
            int count = geo.GetPointCount();
            if (count >= 2)
            {
                double[] pt = new double[2];
                for (int i = 0; i < count - 1; i++)
                {
                    geo.GetPoint(i, pt);
                    props.Start = new Vector2((float)pt[0], (float)pt[1]);
                    lineRenderer.AppendLine(props);
                }
                geo.GetPoint(count - 1, pt);
                props.Start = new Vector2((float)pt[0], (float)pt[1]);
                lineRenderer.EndLine(props);
            }
        }
        break;

        default:
            break;
        }
    }
Ejemplo n.º 2
0
    void DrawLineString(Geometry geo)
    {
        int count = geo.GetPointCount();

        if (count >= 2)
        {
            double[] pt = new double[2];
            for (int i = 0; i < count - 1; i++)
            {
                geo.GetPoint(i, pt);
                props.Start = new Vector3((float)pt[0], (float)pt[1], 0);
                lineRenderer.AppendLine(props);
            }
            geo.GetPoint(count - 1, pt);
            props.Start = new Vector3((float)pt[0], (float)pt[1], 0);
            lineRenderer.EndLine(props);
        }
    }
Ejemplo n.º 3
0
    void Update()
    {
        float inputX = Input.GetAxis("Horizontal");
        float inputY = Input.GetAxis("Vertical");
        float rtaxis = Input.GetAxis("Fire");

        if (rtaxis > 0.5)
        {
            is_drawing = true;
        }
        else
        {
            is_drawing = false;
        }

        movement = new Vector2(speed.x * inputX, speed.y * inputY);
        GetComponent <Rigidbody2D>().velocity = movement;
        crnt_pos = GetComponent <Transform>().position;
        if (System.Math.Abs(inputX) > 0.5 && System.Math.Abs(inputY) < 0.5)
        {
            if (inputX > 0)
            {
                GetComponent <SpriteRenderer>().sprite = right;
            }
            else
            {
                GetComponent <SpriteRenderer>().sprite = left;
            }
        }
        if (System.Math.Abs(inputY) > 0.5 && System.Math.Abs(inputX) < 0.5)
        {
            GetComponent <SpriteRenderer>().sprite = front;
        }

        // Draw line

        if (dist(crnt_pos, prev_pos) >= 5)
        {
            if (is_drawing != last)
            {
                if (last == true)
                {
                    FLR.EndLine(FLRP);
                }
                else
                {
                    crnt_edge_collider_OBJ       = new GameObject();
                    crnt_edge_collider_OBJ.layer = 8;
                    crnt_edge_collider_OBJ.transform.position = crnt_pos;
                    crnt_edge_collider = crnt_edge_collider_OBJ.AddComponent <EdgeCollider2D>();
                    EC_points.Add(new List <Vector2>());
                    EC_count++;
                }
            }
            if (is_drawing)
            {
                EC_points[EC_count].Add(new Vector2(crnt_pos.x - crnt_edge_collider.transform.position.x, crnt_pos.y - crnt_edge_collider.transform.position.y));
                crnt_edge_collider.points = EC_points[EC_count].ToArray();
                FLRP.Start = crnt_pos;
                FLR.AppendLine(FLRP);
                FLR.Apply();
                prev_pos = crnt_pos;
            }
            last = is_drawing;
        }
    }