void SetUpNewIntersection(Road road, Road otherRoad, Vector3 intersection, Junction j, RoadMap map)
    {
        // split road that is being intersected
        Road newRoad = segFactory.CreateRoad(intersection, otherRoad.end, otherRoad.t, otherRoad.type);

        otherRoad.MoveEnd(intersection);

        // set up links between roads
        newRoad.next.AddRange(otherRoad.next);
        newRoad.Parent = otherRoad;
        newRoad.prev.Add(new Road.Neighbour(road, true));
        road.next.Add(new Road.Neighbour(newRoad, true));
        road.next.Add(new Road.Neighbour(otherRoad, false));
        foreach (Road.Neighbour n in otherRoad.next)
        {
            n.r.ReplaceNeighbour(otherRoad, newRoad);
            //n.r.RemoveNeighbour(otherRoad);
            //n.r.prev.Add(new Road.Neighbour(newRoad, true));
        }

        otherRoad.next.Clear();
        otherRoad.next.Add(new Road.Neighbour(newRoad, true));
        otherRoad.next.Add(new Road.Neighbour(road, false));
        j.AddIncoming(road);
        j.AddOutgoing(newRoad);
        j.AddIncoming(otherRoad);
        map.AddRoad(newRoad);
    }
Example #2
0
    Road AddBranch(Road prevSegment, Road straight, Junction j, float angle, float length, float t, RoadType type)
    {
        Road branchRoad = segFactory.CreateRoad(
            prevSegment.end,
            Quaternion.Euler(prevSegment.transform.localEulerAngles.x, angle, 0),
            length,
            t,
            type
            );

        if (j == null)
        {
            j = segFactory.CreateJunction(prevSegment.end, Quaternion.identity);
            straight.attachedSegments.Add(j);
            j.AddOutgoing(straight);
        }
        branchRoad.attachedSegments.Add(j);
        j.AddIncoming(prevSegment);
        j.AddOutgoing(branchRoad);

        return(branchRoad);
    }