Esempio n. 1
0
    public void InitPolygon(PredefinedCloth cloth)
    {
        InitBoundaryCollection();

        SimpleLineBehaviour lb = null;

        foreach (Vector2 p in cloth.points)
        {
            //Make a new boundary point
            GameObject o = Instantiate(boundaryPointPrefab, boundaries) as GameObject;
            o.transform.Translate(new Vector3(p.x, p.y, 0.0f));
            boundaryPoints.Add(o);

            //Make a new line
            GameObject l = Instantiate(boundaryLinePrefab, boundaries) as GameObject;
            boundaryLines.Add(l);
            o.GetComponent <BoundaryPointBehaviour> ().line = l;
            //Add this point as second to the previous line
            if (lb != null)
            {
                lb.second = o.transform;
            }
            //Get the new line behaviour
            lb = l.GetComponent <SimpleLineBehaviour> ();

            //Add this point as first to the new line
            lb.first = o.transform;
        }

        //Set last line's second point to be the first point of the set
        lb.second = boundaryPoints [0].transform;

        InitMesh();
    }
Esempio n. 2
0
    public GameObject CreateDart(Vector3 start, Vector3 end, SimpleLineBehaviour simpleLine)
    {
        Vector2 position = end;

        GameObject o = new GameObject();

        o.transform.parent        = simpleLine.transform;
        o.transform.localPosition = Vector3.zero;

        GameObject d = Instantiate(dartPrefab, o.transform) as GameObject;

        d.transform.Translate(position);

        var positions = InitPositions(position);

        BoundaryPointsHandler bph = d.GetComponent <BoundaryPointsHandler> ();

        InitBoundaryPointsHandler(bph, positions);

        bph.DeactivateBoundaryPoint(bph.boundaryPoints[2]);

        Destroy(d.GetComponent <Movable>());
        var movable = d.AddComponent <Movable1D> ();

        movable.Init(simpleLine.first, simpleLine.second);

        return(d);
    }