Esempio n. 1
0
    ComplexPath loadLane(Transform lane)
    {
        ComplexPath cPath = new ComplexPath();

        for (int i = 0; i < lane.childCount; i++)
        {
            Transform vec = lane.GetChild(i);
            IPath     nextPath;
            int       next = i + 1;
            if (next == lane.childCount)
            {
                next = 0;
            }

            if (vec.childCount > 1)
            {
                // bezier path
                Transform start      = vec.GetChild(0);
                Vector2   startPoint = new Vector2(start.transform.position.x, start.transform.position.y);
                //Debug.Log("startPoint - x " + startPoint.X + " y: " + startPoint.Y);

                Transform ch1      = vec.GetChild(1);
                Vector2   ch1Point = new Vector2(ch1.transform.position.x, ch1.transform.position.y);
                //Debug.Log("ch1Point  - x " + ch1Point.X + " y: " + ch1Point.Y);

                Transform ch2      = vec.GetChild(2);
                Vector2   ch2Point = new Vector2(ch2.transform.position.x, ch2.transform.position.y);
                //Debug.Log("ch2Point - x " + ch2Point.X + " y: " + ch2Point.Y);

                Transform end      = vec.GetChild(3);
                Vector2   endPoint = new Vector2(end.transform.position.x, end.transform.position.y);
                //Debug.Log("endPoint - x " + endPoint.X + " y: " + endPoint.Y);

                nextPath = new BezierPath(startPoint, ch1Point, ch2Point, endPoint);
            }
            else
            {
                //lineal path
                Transform vec2 = lane.GetChild(next);
                if (vec2.childCount > 1)
                {
                    vec2 = vec2.GetChild(0);
                }
                float x  = vec.transform.position.x;
                float y  = vec.transform.position.y;
                float x2 = vec2.transform.position.x;
                float y2 = vec2.transform.position.y;
                nextPath = new LinearPath(new Vector2(x, y), new Vector2(x2, y2));
            }


            cPath.AddPathSegment(nextPath);
        }
        return(cPath);
    }
Esempio n. 2
0
 void LoadLanes()
 {
     for (int i = 0; i < track.childCount; i++)
     {
         Transform   lane    = track.GetChild(i);
         ComplexPath lanPath = loadLane(lane);
         lanPath.name = "track" + i;
         lanes.SetValue(lanPath, i);
         LoadLanePoints(lanPath);
     }
 }
Esempio n. 3
0
    private void LoadLanePoints(ComplexPath lanPath)
    {
        float s      = (float)1 / pointDensity;
        float sCount = s;

        for (float i = 0; i < pointDensity; i++)
        {
            Vector2 p = lanPath.GetPos(sCount);
            lanPath.points.Add(new KeyValuePair <float, Vector2>(sCount, p));
            if (debugging)
            {
                point.transform.position = p;
                Instantiate(point);
            }
            sCount = sCount + s;
        }
    }
Esempio n. 4
0
 public int Test([FromPath] ComplexPath value) => 42;