// Start is called before the first frame update void Start() { roadDropdown = gameObject.transform.Find("LoadRoadControls/RoadNameDropdown").GetComponent <Dropdown>(); // add lane types to dropdown, then set current active roadDropdown.ClearOptions(); List <string> roadFileNames = new List <string>(RoadVizSaveSystem.getFilenames()); gameObject.transform.Find("LoadRoadControls/LoadButton").GetComponent <Button>().interactable = roadFileNames.Count > 0; roadDropdown.AddOptions(new List <string>(RoadVizSaveSystem.getFilenames())); }
public void handleLoadDesign() { Debug.Log("Load design selected"); string roadNameToLoad = RoadVizSaveSystem.getFilenames()[roadDropdown.value]; IEnumerator LoadLevel() { DontDestroyOnLoad(this.transform.gameObject); Debug.Log(this); AsyncOperation asyncLoadLevel = SceneManager.LoadSceneAsync("DevelopmentEnvironment", LoadSceneMode.Single); //while (!asyncLoadLevel.isDone) //{ // Debug.Log("Async loading scene ongoing..."); //yield return null; //} yield return(new WaitWhile(() => !asyncLoadLevel.isDone)); yield return(new WaitForEndOfFrame()); Debug.Log("Async loading scene complete!"); Road rd = GameObject.Find("Road").GetComponent <Road>(); rd.loadRoad(roadNameToLoad); Destroy(this.transform.gameObject); } StartCoroutine(LoadLevel()); //SceneManager.LoadScene("DevelopmentEnvironment"); }
// 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]); } }
// Nathan wrote this // saves the road to a binary file public void saveRoad() { RoadVizSaveSystem.saveRoad(this); }
public void onSavePress() { RoadVizSaveSystem.saveRoad(GameObject.Find("Road").GetComponent <Road>()); }