/* * Called by UpdateConnectionsStraightToStraight() when two straights need to be * replaced by one, and the old roads deleted */ void CreateTwoStraights(RoadStraight otherRoad) { Vector2 min_array = new Vector2(Mathf.Min(grid_position_min.x, otherRoad.grid_position_min.x), Mathf.Min(grid_position_min.y, otherRoad.grid_position_min.y)); Vector2 max_array = new Vector2(Mathf.Max(grid_position_max.x, otherRoad.grid_position_max.x), Mathf.Max(grid_position_max.y, otherRoad.grid_position_max.y)); GameObject new_go = GridBuilder.CreateRectangle(min_array, max_array, this.transform.localScale.y, this.transform.parent, true); // create component, createRoad() and then update RoadStraight road_component = new_go.AddComponent <RoadStraight>(); road_component.CreateRoad(this); /* * print(this.gameObject.name + "is creating two straights"); * StartCoroutine(DelayedUpdateRoad(road_component, otherRoad)); */ road_component.UpdateRoad(this.trafficDirection); Object.Destroy(otherRoad.gameObject); Object.Destroy(this.gameObject); }
/* * Setup when place road is first started */ public void Setup(PlaceRoad place_road) { placeRoad = place_road; // also grab components road_straight_one_component = road_straight_one.GetComponent <RoadStraight>(); road_straight_two_component = road_straight_two.GetComponent <RoadStraight>(); road_corner_component = road_corner.GetComponent <RoadCorner>(); }
public override GameObject CreateRoad(Road oldRoad) { base.CreateRoad(oldRoad); RoadStraight oldRoadStraight = (RoadStraight)oldRoad; trafficDirection = oldRoadStraight.trafficDirection; return(this.gameObject); }
/* * Need to delay updating new road, so other roads being constructed can finish * their new road connections first (and then be overridden ) */ IEnumerator DelayedUpdateRoad(RoadStraight road_component, RoadStraight otherRoad) { yield return(new WaitForSeconds(0.0001f)); //Wait one frame road_component.UpdateRoad(this.trafficDirection); print("updated new road!"); // delete two old gameObjects Object.Destroy(otherRoad.gameObject); Object.Destroy(this.gameObject); }
/* * Called by UpdateConnectionsStraightToStraight() when one straight connects to * another perpendicularly, and there needs to be a corner and two straights to * replace the old road, which is deleted */ void CreateTwoStraightsAndCorner(RoadStraight otherRoad) { RoadStraight straightUpper, straightLower; Road corner; if (otherRoad.trafficDirection.y != 0) { straightLower = (RoadStraight)CreateRoad(otherRoad.grid_position_min, new Vector2(otherRoad.grid_position_max.x, grid_position_min.y - 1), false); straightUpper = (RoadStraight)CreateRoad(new Vector2(otherRoad.grid_position_min.x, grid_position_max.y + 1), otherRoad.grid_position_max, false); corner = CreateRoad(new Vector2(otherRoad.grid_position_min.x, grid_position_min.y), new Vector2(otherRoad.grid_position_max.x, grid_position_max.y), true); } else { straightLower = (RoadStraight)CreateRoad(otherRoad.grid_position_min, new Vector2(grid_position_min.x - 1, otherRoad.grid_position_max.y), false); straightUpper = (RoadStraight)CreateRoad(new Vector2(grid_position_max.x + 1, otherRoad.grid_position_min.y), otherRoad.grid_position_max, false); corner = CreateRoad(new Vector2(grid_position_min.x, otherRoad.grid_position_min.y), new Vector2(grid_position_max.x, otherRoad.grid_position_max.y), true); } if (straightLower != null) { straightLower.UpdateRoad(otherRoad.trafficDirection); } if (straightUpper != null) { straightUpper.UpdateRoad(otherRoad.trafficDirection); } corner.UpdateRoad(); Object.Destroy(otherRoad.gameObject); //UpdateRoad(); }
public void SetConnection(RoadStraight straight, Vector2 direction) { if (direction == new Vector2(0, 1)) { bottomConnection = straight; } else if (direction == new Vector2(1, 0)) { leftConnection = straight; } else if (direction == new Vector2(0, -1)) { topConnection = straight; } else if (direction == new Vector2(-1, 0)) { rightConnection = straight; } UpdateMaterials(); }
public void SetConnection(RoadStraight straight, Vector2 direction) { if (direction == new Vector2(0,1)) bottomConnection = straight; else if (direction == new Vector2(1,0)) leftConnection = straight; else if (direction == new Vector2(0,-1)) topConnection = straight; else if (direction == new Vector2(-1,0)) rightConnection = straight; UpdateMaterials(); }
/* * Setup when place road is first started */ public void Setup(PlaceRoad place_road) { placeRoad = place_road; // also grab components road_straight_one_component = road_straight_one.GetComponent<RoadStraight>(); road_straight_two_component = road_straight_two.GetComponent<RoadStraight>(); road_corner_component = road_corner.GetComponent<RoadCorner>(); }