public void OnSpawn(RoadManager.LaneDirection startDirection, Road startRoad) { currentDirection = startDirection; currentRoad = startRoad; dstTravelled = 0; GetCurrentPath(); }
public void ResetLane(RoadManager.LaneDirection laneDirection) { foreach (Lane lane in lanes) { if (lane.laneDirection == laneDirection) { lane.roadWaypoints.Clear(); } } }
public bool LaneExists(RoadManager.LaneDirection laneDirection) { foreach (Lane lane in lanes) { if (lane.laneDirection == laneDirection) { return(true); } } return(false); }
public Lane GetLane(RoadManager.LaneDirection laneDirection) { foreach (Lane lane in lanes) { if (lane.laneDirection == laneDirection) { return(lane); } } return(null); // Lane with that direction doesn't exist }
public void AddEmptyLane(RoadManager.LaneDirection laneDirectionToAdd) { bool laneAlreadyExists = false; foreach (Lane lane in lanes) { if (lane.laneDirection == laneDirectionToAdd) { laneAlreadyExists = true; } } if (!laneAlreadyExists) { lanes.Add(new Lane(laneDirectionToAdd)); } }
public VertexPath GetPath(Vehicle vehicleRequestingPath, RoadManager.LaneDirection laneDirection) { if (IsJunction()) { return(GetRandomTurningPath(vehicleRequestingPath, laneDirection)); } Lane lane = GetLane(laneDirection); if (lane != null) { return(new VertexPath(new BezierPath(lane.GetLaneWaypoints(), false, PathSpace.xyz))); } else { return(null); } }
public Road GetNextRoad(RoadManager.LaneDirection direction, bool recursive) { switch (direction) { case RoadManager.LaneDirection.north_north: return(northRoadNeighbor); case RoadManager.LaneDirection.south_south: return(southRoadNeighbor); case RoadManager.LaneDirection.east_east: return(eastRoadNeighbor); case RoadManager.LaneDirection.west_west: return(westRoadNeighbor); } if (recursive) { GetRoadNeighbors(); return(GetNextRoad(direction, false)); } return(null); }
public Lane(RoadManager.LaneDirection direction) { empty = true; laneDirection = direction; }
public VertexPath GetRandomTurningPath(Vehicle vehicleRequestingPath, RoadManager.LaneDirection fromDirection) { List <Lane> possibleTurnLanes = new List <Lane>(); switch (fromDirection) { case RoadManager.LaneDirection.north_north: if (LaneExists(RoadManager.LaneDirection.north_north)) { possibleTurnLanes.Add(GetLane(RoadManager.LaneDirection.north_north)); } if (LaneExists(RoadManager.LaneDirection.north_east)) { possibleTurnLanes.Add(GetLane(RoadManager.LaneDirection.north_east)); } if (LaneExists(RoadManager.LaneDirection.north_west)) { possibleTurnLanes.Add(GetLane(RoadManager.LaneDirection.north_west)); } break; case RoadManager.LaneDirection.south_south: if (LaneExists(RoadManager.LaneDirection.south_south)) { possibleTurnLanes.Add(GetLane(RoadManager.LaneDirection.south_south)); } if (LaneExists(RoadManager.LaneDirection.south_east)) { possibleTurnLanes.Add(GetLane(RoadManager.LaneDirection.south_east)); } if (LaneExists(RoadManager.LaneDirection.south_west)) { possibleTurnLanes.Add(GetLane(RoadManager.LaneDirection.south_west)); } break; case RoadManager.LaneDirection.east_east: if (LaneExists(RoadManager.LaneDirection.east_east)) { possibleTurnLanes.Add(GetLane(RoadManager.LaneDirection.east_east)); } if (LaneExists(RoadManager.LaneDirection.east_north)) { possibleTurnLanes.Add(GetLane(RoadManager.LaneDirection.east_north)); } if (LaneExists(RoadManager.LaneDirection.east_south)) { possibleTurnLanes.Add(GetLane(RoadManager.LaneDirection.east_south)); } break; case RoadManager.LaneDirection.west_west: if (LaneExists(RoadManager.LaneDirection.west_west)) { possibleTurnLanes.Add(GetLane(RoadManager.LaneDirection.west_west)); } if (LaneExists(RoadManager.LaneDirection.west_north)) { possibleTurnLanes.Add(GetLane(RoadManager.LaneDirection.west_north)); } if (LaneExists(RoadManager.LaneDirection.west_south)) { possibleTurnLanes.Add(GetLane(RoadManager.LaneDirection.west_south)); } break; } Lane randomLane = possibleTurnLanes[Random.Range(0, possibleTurnLanes.Count)]; vehicleRequestingPath.currentDirection = RoadManager.GetEndDirection(randomLane.laneDirection); return(new VertexPath(new BezierPath(randomLane.GetLaneWaypoints(), false, PathSpace.xyz))); }