// Nathan wrote this // changes a lane's type // parameter targetLane is the lane we are trying to change // parameter newType is the name of the lane type we want to insert // parameter defaultWidth is the default width of the type to be inserted public GameObject setLaneType(GameObject targetLane, string newType) { // REASONING BEHIND THIS PROCESS: // We actually cannot overwrite gameObject from within BasicLane // (we don't have access), and the following code: // targetLane = laneTypes[2] // causes an exception. Therefore, my current solution for changing a lane type is // to insert a whole new lane, adjust its width to be what a sidewalk's should be, // and finally remove the old lane. // 1. obtain the prefab for the specified lane type GameObject newTypeObject = findLaneType(newType); // 2. insert the lane of the specified type insertLane(targetLane, newTypeObject, "right"); // 3. obtain the new lane's information LinkedListNode <GameObject> laneNode = roadLanes.Find(targetLane); LinkedListNode <GameObject> newLaneNode = laneNode.Next; GameObject newLane = newLaneNode.Value; BasicLane newLaneScript = (BasicLane)newLane.GetComponent("BasicLane"); // 4. delete the old lane removeLane(targetLane); // 5. adjust the stripes of the new lane if (!newLaneScript.isVehicleLane()) { handleNonVehicleLaneStripes(newLaneScript, newLaneNode); } StartCoroutine(FrameDelayBuildingUpdate()); return(newLane); }
//Max wrote this //Updates the object's rotation based on the current direction of its parent, the lane. //This allows for things such as turn arrows, bus signs, and bike signs to be //rotated correctly to indicate the direction of their lane. public void updateRotation() { //Get the lane reference and check the direction by accessing the parent BasicLane laneReference = this.transform.parent.gameObject.GetComponent <BasicLane>(); //Figure out the current direction int direction = laneReference.getDirection(); //Use the current direction to set the rotation if (direction == 0) { //Rotation changed to point forward this.transform.localEulerAngles = new Vector3(0, -90, 0); } else if (direction == 1) { //Rotation changed to point back this.transform.localEulerAngles = new Vector3(0, 90, 0); } //If an invalid direction is given else { Debug.Log("Error. Not updating direction in signDirection.cs due to invalid direction."); } }
// Nathan wrote this // used to shift lanes back in after a deletion public void shiftLanesIn(GameObject currLane, float currLaneSize) { // variable to let us know we've found the lane bool foundLane = false; foreach (GameObject g in roadLanes) { BasicLane laneScript = g.GetComponent <BasicLane>(); // check if we've found our lane, if so, everything else will shift right from here on out // we must check this before, unlike what we do in shiftLanesAfter if (currLane == g) { foundLane = true; } // if we haven't gotten to our lane yet, shift the lane to the left by newlaneSize / 2 // this won't need to be changed for when we're adjusting the width of a new lane we // are inserting because we will use adjustRoadAroundLane else if (!foundLane) { laneScript.setLanePosition(currLaneSize / 2); } // looks like we've found our lane, so shift everything to the right now else { laneScript.setLanePosition(-currLaneSize / 2); } } StartCoroutine(FrameDelayBuildingUpdate()); }
// Luke wrote this // used for modifying widths of lanes // shifts the lanes by the amount the current lane's width is modified by // this will get called quite often when changing width as it will be every time // the width number changes public void adjustRoadAroundLane(GameObject currLane, float sizeDifference) { bool foundLane = false; foreach (GameObject g in roadLanes) { // get the lane that we are looking at's current position BasicLane laneScript = g.GetComponent <BasicLane>(); // if we have found our current lane (that is being made wider or thinner), indicate that we found it if (currLane == g) { // essentially do nothing because it will be widened after foundLane = true; } // if we haven't found our lane yet, shift things to the left by the sizeDifference else if (foundLane == false) { laneScript.setLanePosition(-sizeDifference); } // if we HAVE found our lane, shift things right else // foundLane is 1 { laneScript.setLanePosition(sizeDifference); } } //Update position of buildings StartCoroutine(FrameDelayBuildingUpdate()); }
// overload the constructor to properly deal with lanes that can have props public LaneData(BasicLane lane, PropManager propManager) { // store the lane position Vector3 lanePositionVector = lane.getLanePosition(); lanePosition[0] = lanePositionVector.x; lanePosition[1] = lanePositionVector.y; lanePosition[2] = lanePositionVector.z; // store the lane width and the max/min values laneWidth = lane.getLaneWidth(); maxWidth = lane.getMaxWidth(); minWidth = lane.getMinWidth(); // store the lane type laneType = lane.getLaneType(); // store the booleans vehicleLane = lane.isVehicleLane(); nonVehicleAsphalt = lane.isNonVehicleAsphaltLane(); nonAsphalt = lane.isNonAsphaltLane(); // store the stripes' data GameObject leftStripe = lane.getStripe("left"); GameObject rightStripe = lane.getStripe("right"); if (leftStripe != null) { Stripe leftStripeScriptRef = (Stripe)leftStripe.GetComponent("Stripe"); leftStripeData = new StripeData(leftStripeScriptRef); } if (rightStripe != null) { Stripe rightStripeScriptRef = (Stripe)rightStripe.GetComponent("Stripe"); rightStripeData = new StripeData(rightStripeScriptRef); } propManagerData = new PropManagerData(propManager); }
public void init(GameObject[] basicLaneRef) { selectedLane = basicLaneRef[0].GetComponent <BasicLane>(); speedField = transform.Find("SpeedControls/SpeedBackground/SpeedField").GetComponent <Text>(); speedField.text = "15"; vehicleSender = GameObject.Find("VehicleSender").GetComponent <sendVehicle>(); vehicleSelectDd = transform.Find("VehicleSelectControls/VehicleType").GetComponent <Dropdown>(); vehicleSelectDd.ClearOptions(); vehicleSelectDd.AddOptions(new List <string>(VEHICLE_OPTIONS)); }
// Nathan wrote this // helper for removeLane // adjusts stripes after deletion private void resetStripes(BasicLane leftScript, BasicLane rightScript) { GameObject newStripe; Vector3 newStripePosition; // 4 cases: // case 1: this case should not happen (you can't reset the stripes of the last lane in the road) if (leftScript == null && rightScript == null) { throw new System.ArgumentException("There should be lanes in the road but there are not."); } // case 2: there is a left neighbor but no right neighbor else if (leftScript != null && rightScript == null) { // if the lane to the left has asphalt, we must insert a new stripe if (!leftScript.isNonAsphaltLane()) { // instantiate a new stripe on the left lane and set it's orientation newStripePosition = leftScript.getLanePosition(); newStripe = Instantiate(stripeContainer, newStripePosition, transform.rotation); leftScript.setStripeOrientation(newStripe, "right"); } } // case 3: there is a right neighbor but no left neighbor else if (leftScript == null && rightScript != null) { // if the lane to the right has asphalt we must insert a new stripe if (!rightScript.isNonAsphaltLane()) { // instantiate a new stripe on the right lane and set its orientation newStripePosition = rightScript.getLanePosition(); newStripe = Instantiate(stripeContainer, newStripePosition, transform.rotation); rightScript.setStripeOrientation(newStripe, "left"); } } // case 4: there are both left and right neighbors else { // neither the left nor right neighbor is a non-asphalt lane if (!leftScript.isNonAsphaltLane() && !rightScript.isNonAsphaltLane()) { // instantiate a new stripe on the left lane and set it's orientation // for both the left and the right lane newStripePosition = leftScript.getLanePosition(); newStripe = Instantiate(stripeContainer, newStripePosition, transform.rotation); leftScript.setStripeOrientation(newStripe, "right"); rightScript.setStripeOrientation(newStripe, "left"); } } }
// Nathan wrote this // insertLane inserts a lane object into the road // laneType: the type of lane to be inserted into the road // shift: the distance by which the lane's position must be // moved (so that it does not paste over another lane) public void insertLane(GameObject currLane, GameObject laneType, string side) { // steps: // 1. check to make sure the lane is an acceptable type // 2. check that the road is not already full of lanes // 3. set new position to 0 and currLaneNode to null by default // 4. check if currLane is not null; if not: // a. get the scripts of the current lane and the lane that's being inserted // b. get the position of the current lane // c. get the width of the current lane // d. set the position of the new lane // e. shift the other lanes in the road // f. get the node of the current lane // 5. instantiate the lane into the development environment // 6. set the new lane to be a child of the road object // 7. add the lane to the linked list // 8. set the stripes of the new lane if (isValidLaneType(laneType) && !isFull()) { Vector3 newPosition = transform.position; LinkedListNode <GameObject> currLaneNode = null; if (currLane != null) { BasicLane currLaneScript = (BasicLane)currLane.GetComponent("BasicLane"); BasicLane newLaneScript = (BasicLane)laneType.GetComponent("BasicLane"); Vector3 currLanePosition = currLane.transform.position; float currLaneZScale = currLaneScript.getLaneWidth(); // side is left if (side.Equals("left")) { newPosition = new Vector3(currLanePosition.x, currLanePosition.y, currLanePosition.z - (currLaneZScale / 2)); } else // side is "right" { newPosition = new Vector3(currLanePosition.x, currLanePosition.y, currLanePosition.z + (currLaneZScale / 2)); } currLaneNode = roadLanes.Find(currLane); } // back to default cases GameObject newLane = Instantiate(laneType, newPosition, transform.rotation); newLane.transform.parent = transform; addLaneToList(newLane, currLaneNode, side); Transform newAsphaltTransform = newLane.transform.Find("PrimaryAsphalt"); float newLaneZScale = newAsphaltTransform.localScale.z; adjustRoadAroundLane(newLane, newLaneZScale / 2); setStripes(newLane); } }
// Nathan wrote this // this function is used for removing a lane public void removeLane(GameObject targetLane) { if (!isAtMinSize()) { // steps: // 1. obtain a reference to the script of the target lane // 2. get the target lane's width // 3. get references to the neighboring lanes' scripts // 4. destroy both stripes // 5. shift the rest of the lanes inward // 6. remove target lane from linked list // 7. destroy the target lane game objet // 8. add stripes back in accordingly // 1. get target lane script BasicLane targetLaneScriptReference = (BasicLane)targetLane.GetComponent("BasicLane"); // 2. get target lane's width float targetLaneWidth = targetLaneScriptReference.getLaneWidth(); // 3. get the neighbors' scripts LinkedListNode <GameObject> targetLaneNode = roadLanes.Find(targetLane); BasicLane leftNeighborScriptReference = null; BasicLane rightNeighborScriptReference = null; if (targetLaneNode.Previous != null) { leftNeighborScriptReference = (BasicLane)targetLaneNode.Previous.Value.GetComponent("BasicLane"); } if (targetLaneNode.Next != null) { rightNeighborScriptReference = (BasicLane)targetLaneNode.Next.Value.GetComponent("BasicLane"); } // 4. destroy the stripes Destroy(targetLaneScriptReference.getStripe("left")); Destroy(targetLaneScriptReference.getStripe("right")); // 5. shift the rest of the lanes inward //shiftLanesIn(targetLane, targetLaneWidth); adjustRoadAroundLane(targetLane, -(targetLaneWidth / 2)); // 6. remove lane from list roadLanes.Remove(targetLane); // 7. destroy the game object Destroy(targetLane); // 8. reset the stripes of the remaining lanes resetStripes(leftNeighborScriptReference, rightNeighborScriptReference); } }
public void init(GameObject[] laneRefs) { Debug.Assert(laneRefs.Length == 1); laneTypedd = gameObject.transform.Find("LaneTypeControls/LaneType").GetComponent <Dropdown>(); sendVehicleButton = transform.Find("SendVehicleButton").GetComponent <Button>(); deleteLaneButton = gameObject.transform.Find("Delete").GetComponent <Button>(); workingLaneReference = laneRefs[0]; basicLaneScriptReference = workingLaneReference.GetComponent <BasicLane>(); if (workingLaneReference == null || basicLaneScriptReference == null) { Debug.Log("Tried to set working reference, but failed."); } updateWidthField(); resolveButtonActivationStates(); }
// Nathan partially completed this public void handleLaneTypeChange() { Debug.Log("Lane type change selected. *There is something weird with the height of shoulders!"); // we will need to change the line below to something more substantial // once we get more lane types involved - maybe create a helper function to handle this List <string> laneTypeNames = GameObject.Find("Road").GetComponent <Road>().getLaneTypeNames(); int laneTypeSelectionIndex = gameObject.transform.Find("LaneTypeControls/LaneType").GetComponent <Dropdown>().value; string newSelection = laneTypeNames[laneTypeSelectionIndex]; // we only want to change, if the selection changes if (basicLaneScriptReference.getLaneType() != newSelection) { workingLaneReference = GameObject.Find("Road").GetComponent <Road>().setLaneType(workingLaneReference, laneTypeNames[laneTypeSelectionIndex]); basicLaneScriptReference = workingLaneReference.GetComponent <BasicLane>(); updateWidthField(); } resolveStripeUIState(); }
// Nathan wrote this // class constructor // road is the road object in the development environment public RoadData(Road road) { // store the environment as an EnvironmentData variable Buildings buildingScriptReference = road.getBuildingsReference(); buildingsIndex = buildingScriptReference.getBuildingIndex(); // store the fog variables FogControl fogControlScriptReference = road.getFogControl(); fogDistance = fogControlScriptReference.getFogDistance(); // store the lighting intensities BrightnessControl[] lightScripts = road.getLights(); for (int i = 0; i < lightScripts.Length; i++) { lightIntensities[i] = lightScripts[i].getBrightness(); } // store the lanes as a list of LaneData LinkedList <GameObject> roadLanes = road.getLanes(); // store the lanes foreach (GameObject lane in roadLanes) { BasicLane laneScriptRef = (BasicLane)lane.GetComponent("BasicLane"); LaneData indLaneData = null; // if we have a non-vehicle lane, create the independent lane data with a prop manager if (!laneScriptRef.isVehicleLane()) { PropManager propManagerRef = lane.GetComponent <PropManager>(); indLaneData = new LaneData(laneScriptRef, propManagerRef); } else { indLaneData = new LaneData(laneScriptRef); } laneData.Add(indLaneData); } }
// Luke wrote this // sets the width of a lane. Also calls the correct shift function in Road.cs public void setWidth(float width) { // obtain the scale of the asphalt and the locations of the lines and button BasicLane laneScript = lane.GetComponent <BasicLane>(); laneScript.setLaneWidth(width); /*Vector3 newSize = asphalt.transform.localScale; * Vector3 leftLinePos = leftLine.transform.localPosition; * Vector3 rightLinePos = rightLine.transform.localPosition; * Vector3 buttonPos = insertButton.transform.localPosition; * * // was testing to see how multiple size increases would work * //width += newSize.z; * * // the amount we need to move the lines and button * float adjuster = (width - newSize.z) / 2; * * // create a reference to the in-game road object * GameObject road = GameObject.Find("Road"); * // reference script that controls the road's behavior * Road roadScript = (Road)road.GetComponent("Road"); * // adjust the lane positions around the lane we are modifying * roadScript.adjustRoadAroundLane(lane, adjuster); * * // adjust the width of the lane and the locations of the lines and button * newSize.z = width; * leftLinePos.z -= adjuster; * rightLinePos.z += adjuster; * buttonPos.z += adjuster; * * // set the new sizes and locations * asphalt.transform.localScale = newSize; * leftLine.transform.localPosition = leftLinePos; * rightLine.transform.localPosition = rightLinePos; * insertButton.transform.localPosition = buttonPos;*/ }
// Nathan wrote this // deals with non-vehicle lane stripe adjustment // parameter newLaneScript is a reference to the BasicLane script of a lane // parameter newLaneNode is the node in roadLanes that contains the lane object private void handleNonVehicleLaneStripes(BasicLane newLaneScript, LinkedListNode <GameObject> newLaneNode) { // delete both stripes Destroy(newLaneScript.getStripe("left")); Destroy(newLaneScript.getStripe("right")); newLaneScript.setStripeOrientation(null, "reset"); // if this is a shoulder or a parking lane, we need to reinsert one of the stripes if (!newLaneScript.isNonAsphaltLane()) { // obtain the lane's position Vector3 newLanePosition = newLaneScript.getLanePosition(); // instantiate a new stripe GameObject remainingStripe = Instantiate(stripeContainer, newLanePosition, transform.rotation) as GameObject; // case 1: this is the only lane in the road if (newLaneNode.Previous == null && newLaneNode.Next == null) { newLaneScript.setStripeOrientation(remainingStripe, "right"); } // case 2: this is the rightmost lane in the road else if (newLaneNode.Previous != null && newLaneNode.Next == null) { BasicLane leftNeighborScriptReference = (BasicLane)newLaneNode.Previous.Value.GetComponent("BasicLane"); if (leftNeighborScriptReference.isNonAsphaltLane()) { // if the lane to the left is a non-asphalt type lane, just make this the // right stripe of the new lane newLaneScript.setStripeOrientation(remainingStripe, "right"); } else { // otherwise, make this the left stripe of the new lane // and the right stripe of its left neighbor newLaneScript.setStripeOrientation(remainingStripe, "left"); leftNeighborScriptReference.setStripeOrientation(remainingStripe, "right"); } } // case 3: this is the leftmost lane in the road else if (newLaneNode.Previous == null && newLaneNode.Next != null) { BasicLane rightNeighborScriptReference = (BasicLane)newLaneNode.Next.Value.GetComponent("BasicLane"); if (rightNeighborScriptReference.isNonAsphaltLane()) { // if the lane to the right is a non-asphalt type lane, just make this the // left stripe of the new lane newLaneScript.setStripeOrientation(remainingStripe, "left"); } else { // otherwise, make this the right stripe of the new lane // and the left stripe of its right neighbor newLaneScript.setStripeOrientation(remainingStripe, "right"); rightNeighborScriptReference.setStripeOrientation(remainingStripe, "left"); } } // finally, this is one of the middle lanes in the road else { BasicLane leftNeighborScriptReference = (BasicLane)newLaneNode.Previous.Value.GetComponent("BasicLane"); BasicLane rightNeighborScriptReference = (BasicLane)newLaneNode.Next.Value.GetComponent("BasicLane"); // case a: both the neighbors are a non-asphalt lane if (leftNeighborScriptReference.isNonAsphaltLane() && rightNeighborScriptReference.isNonAsphaltLane()) { // leave the stripes out if both neighbors are a non-asphalt lane (don't do anything) Destroy(remainingStripe); } // case b: only the left neighbor is an asphalt lane else if (!leftNeighborScriptReference.isNonAsphaltLane() && rightNeighborScriptReference.isNonAsphaltLane()) { // make this the left stripe of the new lane // and the right stripe of its left neighbor newLaneScript.setStripeOrientation(remainingStripe, "left"); leftNeighborScriptReference.setStripeOrientation(remainingStripe, "right"); } // case c: only the right neighbor is an asphalt lane else if (leftNeighborScriptReference.isNonAsphaltLane() && !rightNeighborScriptReference.isNonAsphaltLane()) { // make this the right stripe of the new lane // and the left stripe of its right neighbor newLaneScript.setStripeOrientation(remainingStripe, "right"); rightNeighborScriptReference.setStripeOrientation(remainingStripe, "left"); } // case d: both neighbors are asphalt lanes else { // now we must have a stripe on either side; // rare but important case GameObject leftStripe = Instantiate(stripeContainer, newLanePosition, transform.rotation) as GameObject; newLaneScript.setStripeOrientation(leftStripe, "left"); newLaneScript.setStripeOrientation(remainingStripe, "right"); leftNeighborScriptReference.setStripeOrientation(leftStripe, "right"); rightNeighborScriptReference.setStripeOrientation(remainingStripe, "left"); } } } }
// Nathan wrote this // helper for insertLane // sets the stripes of a new lane // parameter lane is the new lane // parameter stripe type is the type of stripe that will be // inserted into the lane private void setStripes(GameObject lane) { // steps: // 1. obtain reference to lane's script // 2. get the current lane's node // 3. obtain the lane's position // 4. declare two GameObjects to contain the stripes // 5. set stripe and lane references // 6. set stripe orientations // 1. obtain script reference BasicLane laneScriptReference = (BasicLane)lane.GetComponent("BasicLane"); // 2. obtain lane's node LinkedListNode <GameObject> laneNode = roadLanes.Find(lane); // 3. obtain lane's position Vector3 lanePosition = laneScriptReference.getLanePosition(); // 4. instantiate game objects to contain stripes GameObject leftStripe; GameObject rightStripe; // 5. set up references between stripes and lanes // case 1: lane has no left neighbor and no right neighbor if (laneNode.Previous == null && laneNode.Next == null) { // this means this is the only lane in the road, so just add 2 new stripes leftStripe = Instantiate(stripeContainer, lanePosition, transform.rotation); rightStripe = Instantiate(stripeContainer, lanePosition, transform.rotation); } // case 2: lane has a left neighbor but no right neighbor else if (laneNode.Previous != null && laneNode.Next == null) { // 1. get the left neighbor GameObject leftNeighbor = laneNode.Previous.Value; // 2. get the left neighbor's script BasicLane leftNeighborScriptReference = (BasicLane)leftNeighbor.GetComponent("BasicLane"); // 3. place stripes accordingly // case 1: the left neighbor is vehicle or non asphalt if (!leftNeighborScriptReference.isNonVehicleAsphaltLane()) { leftStripe = leftNeighborScriptReference.getStripe("right"); } // case 2: the left neighbor is non vehicle lane asphalt else { if (leftNeighborScriptReference.getStripe("right") != null) { leftStripe = leftNeighborScriptReference.getStripe("right"); } else { leftStripe = Instantiate(stripeContainer, lanePosition, transform.rotation); } } rightStripe = Instantiate(stripeContainer, lanePosition, transform.rotation); } // case 3: lane has no left neighbor but has a right neighbor else if (laneNode.Previous == null && laneNode.Next != null) { // 1. get the right neighbor GameObject rightNeighbor = laneNode.Next.Value; // 2. get the right neighbor's script BasicLane rightNeighborScriptReference = (BasicLane)rightNeighbor.GetComponent("BasicLane"); // 3. place stripes accordingly leftStripe = Instantiate(stripeContainer, lanePosition, transform.rotation); // case 1: right neighbor is vehicle or non asphalt if (!rightNeighborScriptReference.isNonVehicleAsphaltLane()) { rightStripe = rightNeighborScriptReference.getStripe("left"); } // case 2: right neighbor is non vehicle asphalt else { if (rightNeighborScriptReference.getStripe("left") != null) { rightStripe = rightNeighborScriptReference.getStripe("left"); } else { rightStripe = Instantiate(stripeContainer, lanePosition, transform.rotation); } } } // case 4: lane has both left and right neighbors (most complicated case) else { // 1. get the neighbors GameObject leftNeighbor = laneNode.Previous.Value; GameObject rightNeighbor = laneNode.Next.Value; // 2. get the neighbors' scripts BasicLane leftNeighborScriptReference = (BasicLane)leftNeighbor.GetComponent("BasicLane"); BasicLane rightNeighborScriptReference = (BasicLane)rightNeighbor.GetComponent("BasicLane"); // case a: the neighboring lanes are asphalt lanes if (!leftNeighborScriptReference.isNonAsphaltLane() && !rightNeighborScriptReference.isNonAsphaltLane()) { if (leftNeighborScriptReference.getLaneType() == "TurnLane" || leftNeighborScriptReference.getLaneType() == "BusLane") { // make the left stripe the right stripe of the left neighbor leftStripe = leftNeighborScriptReference.getStripe("right"); // make the right stripe a new game object and set it as the left // stripe of the right neighbor rightStripe = Instantiate(stripeContainer, lanePosition, transform.rotation); rightNeighborScriptReference.setStripeOrientation(rightStripe, "left"); } else { // make the left stripe a new game object and set it as the right // stripe of the left neighbor leftStripe = Instantiate(stripeContainer, lanePosition, transform.rotation); leftNeighborScriptReference.setStripeOrientation(leftStripe, "right"); // make the right stripe the left stripe of the right neighbor rightStripe = rightNeighborScriptReference.getStripe("left"); } } // case b: the right neighbor is not a lane with asphalt else if (!leftNeighborScriptReference.isNonAsphaltLane() && rightNeighborScriptReference.isNonAsphaltLane()) { // make the left stripe a new game object and make it the right stripe // of the left neighbor leftStripe = Instantiate(stripeContainer, lanePosition, transform.rotation); leftNeighborScriptReference.setStripeOrientation(leftStripe, "right"); // make right stripe null (because we don't want to add a stripe to a lane that's been set // to not have one) rightStripe = null; } // case c: just the left neighbor is not a vehicle lane else if (leftNeighborScriptReference.isNonAsphaltLane() && !rightNeighborScriptReference.isNonAsphaltLane()) { // make the left stripe null leftStripe = null; // make the right stripe a new game object and make it the left stripe // of the right neighbor rightStripe = Instantiate(stripeContainer, lanePosition, transform.rotation); rightNeighborScriptReference.setStripeOrientation(rightStripe, "left"); } // case d: both neighbors are non-asphalt lanes else { leftStripe = null; rightStripe = null; } } // finally, set the stripe orientations laneScriptReference.setStripeOrientation(leftStripe, "left"); laneScriptReference.setStripeOrientation(rightStripe, "right"); }
// Nathan wrote this // loads the road from a binary file public void loadRoad(string filename) { UIManager.Instance.closeCurrentUI(); // steps: // 1. clear the contents of the road // 2. obtain the saved road data // 3. insert each saved lane into the road: // a. obtain the saved lane's type // b. find that lane type and insert it // c. obtain a reference to the lane's script // d. adjust the lane's stripes if it's not a vehicle lane // e. load the rest of the attributes // f. load the lanes props (if not a vehicle lane) // 4. load the saved environment // 5. load the saved fog settings // 6. load the saved lighting settings // 1. we have to clear whatever else the user has loaded in since the last save clearRoad(); // 2. obtain the saved data RoadData roadData = RoadVizSaveSystem.loadRoadFromMemory(filename); List <LaneData> savedLanes = roadData.loadLaneData(); // 3. load each of the saved lanes in GameObject currLane = null; foreach (LaneData savedLane in savedLanes) { // 3a: obtain the lane's type string loadedLaneType = savedLane.loadLaneType(); // 3b. find the type and insert it GameObject loadedLane = findLaneType(loadedLaneType); insertLane(currLane, loadedLane, "right"); currLane = roadLanes.Last.Value; // 3c. obtain a script reference BasicLane loadedLaneScriptReference = (BasicLane)currLane.GetComponent("BasicLane"); // 3d. adjust stripes if (!loadedLaneScriptReference.isVehicleLane()) { LinkedListNode <GameObject> loadedLaneNode = roadLanes.Last; handleNonVehicleLaneStripes(loadedLaneScriptReference, loadedLaneNode); } // 3e. load the rest of the lane's variables loadedLaneScriptReference.loadLaneAtts(savedLane); // 3f. load the lanes props (if not a vehicle lane) if (!loadedLaneScriptReference.isVehicleLane()) { PropManager loadedPropManagerRef = currLane.GetComponent <PropManager>(); loadedPropManagerRef.loadProps(savedLane.loadPropManagerData()); } } // 4. load the saved buildings Buildings buildingsScriptReference = (Buildings)buildingsReference.GetComponent("Buildings"); buildingsScriptReference.setBuildingType(roadData.loadBuildingsIndex()); StartCoroutine(FrameDelayBuildingUpdate()); // 5. load the saved fog settings FogControl fogControlScriptReference = (FogControl)fogController.GetComponent("FogControl"); fogControlScriptReference.setFogDistance(roadData.loadFogDistance()); // 6. load the saved lighting settings float[] lightIntensities = roadData.loadLightIntensities(); BrightnessControl[] lightScripts = getLights(); for (int i = 0; i < lightScripts.Length; i++) { lightScripts[i].setBrightness(lightIntensities[i]); } }
//written by Max, as stated it sends the vehicle down the lane. To do this, it does the following //broad steps: //1) Gather the references from the lane to use its variables //2) Checks the validity of the lane reference and aborts if they're invalid. //3) Conducting the proper motion when all prerequisites are made // -Instantiate measurements from the lane // -Use them to construct targets and instantiate the vehicle based on direction // -Make the target invisible // Once the proper vehicles and targets are instantiated, the update() function takes over. public void sendVehicleDownLane(int userInputMPH, GameObject lane) { //--- GATHERING REFERENCES --- //Get the BasicLane component BasicLane vehicleLaneReference = lane.GetComponent <BasicLane>(); //--- CHECKING REFERENCE VALIDITY --- //If vehicleLaneReference is null then this is not a vehicle lane and this script SHOULD NOT be attached. if (vehicleLaneReference == null) { Debug.Log("This is not a lane."); Debug.Log("Aborting function of sendVehicle.cs"); return; } //If vehicleLane is not null but it is not set to a vehicle lane, then it aborts as well. if (!vehicleLaneReference.isVehicleLane()) { Debug.Log("vehicleLane is set to false."); Debug.Log("Aborting function of sendVehicle.cs"); return; } // --- CONDUCTING MOTION --- //If it's both 1) a lane and 2) a vehicle lane, it can proceed to send the vehicle object at the correct miles per hour. //Set the sending status to true. sendingStatus = true; //To get speed in meters per second, multiply it by the conversion factor. speed = userInputMPH * 0.44704f; //0.44704 is the conversion factor between mph and meters/second. //Temporary instance is instantiated then destroyed in order to attain the bounds for a vehicle. //Not meant to be seen. //GameObject TempInstance = Instantiate(currentVehicle, new Vector3(-9999, -9999, -9999), Quaternion.identity); //Instantiate the vehicle //Get the lane position in order to set it. Vector3 laneCenter = vehicleLaneReference.getLanePosition(); //Getting the direction of the lane //0 is from positive to negative x, //1 is from negative x to positive x int direction = vehicleLaneReference.getDirection(); //If the direction is zero, then it will spawn in the positive X and go negative. Vector3 startLocation; Vector3 oppositeLocation; float laneLength = 100; //Default, hard-coded lane length is 100 in the X direction. if (direction == 0) { startLocation = new Vector3(laneCenter.x + laneLength / 2, //Spawn at positive X end, laneCenter.y, // + TempInstance.transform.localScale.y/2, //Adjust height to be perfectly balanced laneCenter.z); //With the same Z as the center. oppositeLocation = new Vector3(laneCenter.x - laneLength / 2, //Targets negative X end, laneCenter.y, // + TempInstance.transform.localScale.y / 2, //Adjust height to be perfectly balanced laneCenter.z); //With the same Z as the center. if (instance == null) { instance = Instantiate(currentVehicle, startLocation, Quaternion.identity); } else { Destroy(instance); instance = Instantiate(currentVehicle, startLocation, Quaternion.identity); } //target = Instantiate(currentVehicle, oppositeLocation, Quaternion.identity); target = oppositeLocation; //Debug.Log(instance); } //If the direction is one, it will spawn in the negative X and go positive. else if (direction == 1) { startLocation = new Vector3(laneCenter.x - laneLength / 2, //Spawn at negative X end, laneCenter.y, // + TempInstance.transform.localScale.y / 2, //Adjust height to be perfectly balanced laneCenter.z); //With the same Z as the center. oppositeLocation = new Vector3(laneCenter.x + laneLength / 2, //Target at positive X end, laneCenter.y, // + TempInstance.transform.localScale.y / 2, //Adjust height to be perfectly balanced laneCenter.z); //With the same Z as the center. if (instance == null) { instance = Instantiate(currentVehicle, startLocation, Quaternion.identity); } else { Destroy(instance); instance = Instantiate(currentVehicle, startLocation, Quaternion.identity); } //target = Instantiate(currentVehicle, oppositeLocation, Quaternion.identity); target = oppositeLocation; //Finally, we have to rotate it 180 degrees around in the Y direction rotation. instance.transform.Rotate(0.0f, 180.0f, 0.0f, Space.Self); } //The temporary instance is destroyed //Destroy(TempInstance); //The target is invisible (including its children) //Gather a list of the children's renderings /*Renderer[] renderers = target.GetComponentsInChildren<Renderer>(); * //Iterate through every child * foreach (Renderer child in renderers) * { * //Turn off rendering for the children * child.GetComponent<Renderer>().enabled = false; * }*/ }
public void setBasicLaneParent(BasicLane bl) { basicLaneParent = bl; }