Beispiel #1
0
        ILevelData ILevelSerializer.LoadLevel(string levelName)
        {
            Debug.LogFormat("Loading level {0}...", levelName);

            if (forceCreateNewLevelOnLoad)
            {
                ILevelData levelData = new LevelData(10, 10, levelName);
                levelData.id = 42;
                return(levelData);
            }

            if (FileExists(levelName) == false)
            {
                Debug.LogError(string.Format("Level {0} could not be found. Creating a default one.", levelName));
                ILevelData levelData = new LevelData(10, 10);
                levelData.name = levelName;

                return(levelData);
            }

            FileStream            saveFile         = File.Open(FullSavePath(levelName), FileMode.Open);
            BinaryFormatter       formatter        = new BinaryFormatter();
            SerializableLevelData serializableData = (SerializableLevelData)formatter.Deserialize(saveFile);

            return(serializableData.ToLevelData());
        }
Beispiel #2
0
        void ILevelSerializer.SaveLevel(ILevelData levelData)
        {
            SerializableLevelData webLevelData = new SerializableLevelData(levelData);

            PersistentAPI.SaveRoom(webLevelData);
            Debug.Log("Saving room");
        }
Beispiel #3
0
        ILevelData ILevelSerializer.LoadLevel(string levelName)
        {
            if (forceCreateNewLevelOnLoad)
            {
                ILevelData newLevelData = new LevelData(10, 10, levelName);
                newLevelData.owner = "1";
                newLevelData.id    = 1;
                return(newLevelData);
            }

            string jsonResponse = PersistentAPI.GetRoom(levelName);

            SerializableLevelData webLevelData = JsonUtility.FromJson <SerializableLevelData>(jsonResponse);
            ILevelData            levelData    = webLevelData.ToLevelData();

            return(levelData);
        }
Beispiel #4
0
        void ILevelSerializer.SaveLevel(ILevelData levelData)
        {
            Debug.Log("Saving level " + levelData.name + "...");

            SerializableLevelData serializableData = new SerializableLevelData(levelData);

            if (!Directory.Exists(basePath))
            {
                Directory.CreateDirectory(basePath);
                Debug.Log("Creating saving directory...");
            }

            FileStream      saveFile  = File.Create(FullSavePath(levelData.name));
            BinaryFormatter formatter = new BinaryFormatter();

            formatter.Serialize(saveFile, serializableData);
            saveFile.Close();
        }