Beispiel #1
0
    // 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]);
        }
    }