Esempio n. 1
0
        public static void SaveCurrentLevel(string savePath)
        {
            SerializableLevel level      = SerializableLevel.MakeSerializableLevel(ActiveGameObjects);
            Stream            saveStream = File.Open(savePath, FileMode.Create);
            BinaryFormatter   formatter  = new BinaryFormatter();

            formatter.Serialize(saveStream, level);
            saveStream.Close();

            SetDirty(false);

            LoadedLevelObject.name = string.Format("{0}|{1}", LOADED_LEVEL_NAME, savePath);
        }
Esempio n. 2
0
        public static void OpenLevel(string openPath)
        {
            if (LevelIsLoaded)
            {
                CloseLevel();
            }

            Stream            openStream        = File.Open(openPath, FileMode.Open);
            BinaryFormatter   formatter         = new BinaryFormatter();
            SerializableLevel deserializedLevel = formatter.Deserialize(openStream) as SerializableLevel;

            ActiveGameObjects = deserializedLevel.ReconstructLevel(new LevelObjectDatabase());
            openStream.Close();

            LoadedLevelObject.name = string.Format("{0}|{1}", LOADED_LEVEL_NAME, openPath);
        }
Esempio n. 3
0
    void serializeLevelData(SerializableLevel copyTo, WorldSectorLevel copyFrom)
    {
        // save index
        copyTo.y = copyFrom.y;

        // save level cells
        WorldCell[,] cells = copyFrom.getAllCells();
        for (int i = 0; i < GameSettings.LoadedConfig.SectorLength_Cells*GameSettings.LoadedConfig.SectorLength_Cells; ++i) {
            copyTo.cells.Add(new SerializableCell());

            int cx = i%GameSettings.LoadedConfig.SectorLength_Cells;
            int cz = Mathf.FloorToInt(i/GameSettings.LoadedConfig.SectorLength_Cells);
            serializeCellData(copyTo.cells[i], cells[cx, cz]);
        }
    }
Esempio n. 4
0
 public void restoreLevelData(SerializableLevel restoreFrom)
 {
     // restore cells
     for (int cell_x = 0; cell_x < GameSettings.LoadedConfig.SectorLength_Cells; ++cell_x) {
         for (int cell_z = 0; cell_z < GameSettings.LoadedConfig.SectorLength_Cells; ++cell_z) {
             SerializableCell loadedCell = restoreFrom.cells[
                 cell_z * GameSettings.LoadedConfig.SectorLength_Cells + cell_x
             ];
             cells[cell_x, cell_z].restoreCellData(loadedCell);
         }
     }
 }