/// <summary> /// loads the game data from the choosen file path /// </summary> public static void Load() { // sets the path to use string path = Application.persistentDataPath + "/GameSave.NotASaveFile"; // checks for if the file exists if (File.Exists(path)) { // formatts the file BinaryFormatter formatter = new BinaryFormatter(); // opens the stream and file FileStream stream = new FileStream(path, FileMode.Open); // deserializes the data as systemData then closes the stream SaveSystemData data = formatter.Deserialize(stream) as SaveSystemData; stream.Close(); // sets data as = to data loadedData = data; } else { // else sends an error log Debug.LogError("No Save File in" + path); } }
// Loads the data for the high scores from a file. public static SaveSystemData LoadFromFile(string savedFile, int size) { _path = Application.dataPath + "/" + savedFile; SaveSystemData data = new SaveSystemData(size); if (File.Exists(_path)) { using (StreamReader sr = new StreamReader(_path)) { int i = 0; while (!sr.EndOfStream) { data.playerName[i] = sr.ReadLine(); data.score[i] = int.Parse(sr.ReadLine()); i++; } } } else { data.playerName[0] = "James"; data.score[0] = 500; data.playerName[1] = "David"; data.score[1] = 300; data.playerName[2] = "Jacob"; data.score[2] = 100; } return(data); }
void Start() { _maxIndex = _alphabet.Length; data = s_HighScoreSystem.LoadFromFile(_saveGameData, 3); _score = s_HighScoreSystem.ReadFromFile(_fileName); s_HighScoreSystem.ScoreCheck(data, int.Parse(_score)); _playerName = ""; }
// Use this for initialization void Start() { data = s_HighScoreSystem.LoadFromFile(_fileName, 3); _screenInfo[0].GetComponent <TextMesh>().text = data.playerName[0]; _screenInfo[1].GetComponent <TextMesh>().text = data.score[0].ToString(); _screenInfo[2].GetComponent <TextMesh>().text = data.playerName[1]; _screenInfo[3].GetComponent <TextMesh>().text = data.score[1].ToString(); _screenInfo[4].GetComponent <TextMesh>().text = data.playerName[2]; _screenInfo[5].GetComponent <TextMesh>().text = data.score[2].ToString(); }
public void SaveLanguageData() { BinaryFormatter bf = new BinaryFormatter(); string path = Application.persistentDataPath + "/Saves5.bin"; FileStream fs = new FileStream(path, FileMode.Create); SaveSystemData data = new SaveSystemData(); data.languageSwitch = languageSwitch; bf.Serialize(fs, data); fs.Close(); }
public void SaveLvlData() { BinaryFormatter bf = new BinaryFormatter(); string path = Application.persistentDataPath + "/Saves.bin"; FileStream fs = new FileStream(path, FileMode.Create); SaveSystemData data = new SaveSystemData(); data.nextLvl = savedScene + 1; bf.Serialize(fs, data); fs.Close(); }
public void SaveCoinsData() { BinaryFormatter bf = new BinaryFormatter(); string path = Application.persistentDataPath + "/Saves2.bin"; FileStream fs = new FileStream(path, FileMode.Create); SaveSystemData data = new SaveSystemData(); data.coins = coinLogic.coins; bf.Serialize(fs, data); fs.Close(); }
public void SaveWatchedAdData() { BinaryFormatter bf = new BinaryFormatter(); string path = Application.persistentDataPath + "/Saves3.bin"; FileStream fs = new FileStream(path, FileMode.Create); SaveSystemData data = new SaveSystemData(); data.adWatched = adWatched; bf.Serialize(fs, data); fs.Close(); }
// Checks to see if the players score is high enough to be entered in the high score system. public static void ScoreCheck(SaveSystemData data, int score) { for (int i = 0; i < data.Count; i++) { if (score > data.score[i]) { _isHighScore = true; break; } } }
public void SaveMusicSoundData() { BinaryFormatter bf = new BinaryFormatter(); string path = Application.persistentDataPath + "/SaveShop.bin"; FileStream fs = new FileStream(path, FileMode.Create); SaveSystemData data = new SaveSystemData(); data.MusicSwitched = localMusicSwitched; data.SoundSwitched = localSoundSwitched; bf.Serialize(fs, data); fs.Close(); }
public void SaveShopData() { BinaryFormatter bf = new BinaryFormatter(); string path = Application.persistentDataPath + "/SaveShop.bin"; FileStream fs = new FileStream(path, FileMode.Create); SaveSystemData data = new SaveSystemData(); data.isBackPackBuyed = localIsBackPackBuyed; data.buttonCounter = localButtonCounter; bf.Serialize(fs, data); fs.Close(); }
// Used to store the high scores to a file. public static void SaveToFile(SaveSystemData data, string _file) { _path = Application.dataPath + "/" + _file; using (StreamWriter writer = new StreamWriter(_path)) { for (int i = 0; i < data.Count; i++) { writer.WriteLine(data.playerName[i]); writer.WriteLine(data.score[i].ToString()); } } }
public void LoadWatchedAdData() { string path = Application.persistentDataPath + "/Saves3.bin"; if (File.Exists(path)) { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = new FileStream(path, FileMode.Open); SaveSystemData data = (SaveSystemData)bf.Deserialize(fs); fs.Close(); adWatched = data.adWatched; } }
public void LoadCoinData() { string path = Application.persistentDataPath + "/Saves2.bin"; if (File.Exists(path)) { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = new FileStream(path, FileMode.Open); SaveSystemData data = (SaveSystemData)bf.Deserialize(fs); fs.Close(); coinLogic.coins = data.coins; } }
public void LoadLvlData() { string path = Application.persistentDataPath + "/Saves.bin"; if (File.Exists(path)) { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = new FileStream(path, FileMode.Open); SaveSystemData data = (SaveSystemData)bf.Deserialize(fs); fs.Close(); savedScene = data.nextLvl; } }
public void LoadLanguageData() { string path = Application.persistentDataPath + "/Saves5.bin"; if (File.Exists(path)) { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = new FileStream(path, FileMode.Open); SaveSystemData data = (SaveSystemData)bf.Deserialize(fs); fs.Close(); languageSwitch = data.languageSwitch; } }
public void LoadShopData() { string path = Application.persistentDataPath + "/SaveShop.bin"; if (File.Exists(path)) { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = new FileStream(path, FileMode.Open); SaveSystemData data = (SaveSystemData)bf.Deserialize(fs); localIsBackPackBuyed = data.isBackPackBuyed; localButtonCounter = data.buttonCounter; fs.Close(); } }
public void LoadMusicSoundData() { string path = Application.persistentDataPath + "/SaveShop.bin"; if (File.Exists(path)) { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = new FileStream(path, FileMode.Open); SaveSystemData data = (SaveSystemData)bf.Deserialize(fs); localMusicSwitched = data.MusicSwitched; localSoundSwitched = data.SoundSwitched; fs.Close(); } }
/// <summary> /// Method that saves the data in binary formatt and creates a file /// </summary> public static void SaveGame() { // formatts the data BinaryFormatter formatter = new BinaryFormatter(); // sets a file path for storing the save string path = Application.persistentDataPath + "/GameSave.NotASaveFile"; // opens a file stream used to save the file to the choosen path FileStream stream = new FileStream(path, FileMode.Create); // Defines what data is to be saved SaveSystemData data = new SaveSystemData(); // serializes the stream and the data formatter.Serialize(stream, data); // closes the stream stream.Close(); }
// Sorts the high score list and places the new score in the list. public static void CheckScores(SaveSystemData data, int score, string _file) { int scoreIndex = -1; for (int i = 0; i < data.Count; i++) { if (score > data.score[i]) { scoreIndex = i; break; } } if (scoreIndex > -1) { for (int i = data.Count - 1; i > scoreIndex; i--) { data.playerName[i] = data.playerName[i - 1]; data.score[i] = data.score[i - 1]; } data.playerName[scoreIndex] = s_HighScoreInput.PlayerName; data.score[scoreIndex] = score; } SaveToFile(data, _file); }