private void SetLoadedDatas(SaveDatas tempSavedDatas) { GameManager.Instance.GetScoreAndCoinController().SetHighScore(tempSavedDatas.GetSavedHighScore()); GameManager.Instance.GetScoreAndCoinController().SetCoin(tempSavedDatas.GetSavedTotalCoin()); GameManager.Instance.GetLevelBarController().SetCurrentLevel(tempSavedDatas.GetSavedCurrentLevel()); GameManager.Instance.GetLevelBarController().SetCurrentLevelValue(tempSavedDatas.GetSavedCurrentLevelValue()); }
/// <summary> /// Writes the save data to file. /// </summary> public void WriteSaveData(int profileNumber = 0) { if (profileNumber > 0) { currentlyLoadedProfileNumber = profileNumber; } // If for some accidental reason we forgot to assign a profile number, // then check to see if there is any unused profile number (i.e. a file doesn't exist for it). //if (currentlyLoadedProfileNumber <= 0) { // for (int i = 1; i <= MAX_NUMBER_OF_PROFILES; i++) { // if (!File.Exists(GetSaveDataFilePath(i))) { // currentlyLoadedProfileNumber = i; // break; // } // } //} //// If we couldn't find an empty profile then throw an exception because something went very wrong. //if (currentlyLoadedProfileNumber <= 0) { // throw new System.Exception("Cannot WriteSaveData. No available profiles and currentlyLoadedProfile = 0"); // } else { // Otherwise save the SaveData to file. // If the save data doesn't exist yet, // then create a new default save data. if (SaveDatas == null) { SaveDatas = ScriptableObject.CreateInstance <SaveData>(); } // Finally save it to th file using the constructed path + file name SaveDatas.WriteToFile(GetSaveDataFilePath(profileNumber)); }
private SaveDatas CreateSaveGameObject() { SaveDatas saveDatas = new SaveDatas(); saveDatas.SetSavedHighScore(); return(saveDatas); }
public void SaveGame() { SaveDatas saveDatas = CreateSaveGameObject(); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/gamesave"); bf.Serialize(file, saveDatas); file.Close(); }
public void SaveGame() { Debug.Log("game is saved"); SaveDatas saveDatas = CreateSaveGameObject(); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/playerdatas"); bf.Serialize(file, saveDatas); file.Close(); }
private SaveDatas CreateSaveGameObject() { SaveDatas saveDatas = new SaveDatas(); saveDatas.SetSavedHighScore(); saveDatas.SetSavedTotalCoin(); saveDatas.SetSavedCurrentLevel(); saveDatas.SetSavedCurrentLevelValue(); return(saveDatas); }
/// <summary> /// Loads the save data for a specific profile number. /// This will eventually be called from a button. /// </summary> /// <param name="profileNumber">0 is the temporary profile</param> public void LoadSaveData(int profileNumber = 0) { if (isDataLoaded && profileNumber == currentlyLoadedProfileNumber) { return; } // Automatically load the first available profile. if (profileNumber <= 0) { //if no profile specified reload the actual profile (this is the case when the scene is changed) if (currentlyLoadedProfileNumber <= 0) { SaveDatas = ScriptableObject.CreateInstance <SaveData>(); SaveDatas.Reset(); } else { SaveDatas = SaveData.ReadFromFile(GetSaveDataFilePath(currentlyLoadedProfileNumber)); } // We iterate through the possible profile numbers in case one with a lower number // no longer exists. //for (int i = 1; i <= MAX_NUMBER_OF_PROFILES; i++) { // if (File.Exists(GetSaveDataFilePath(i))) { // // Once the file is found, load it from the calculated file name. // SaveData = SaveData.ReadFromFile(GetSaveDataFilePath(i)); // // And set the current profile number for later use when we save. // currentlyLoadedProfileNumber = i; // break; // }} } else { // If the profileNumber parameter is supplied then we'll look to see if that exists. if (File.Exists(GetSaveDataFilePath(profileNumber))) { // If the file exists then load the SaveData from the calculated file name. SaveDatas = SaveData.ReadFromFile(GetSaveDataFilePath(profileNumber)); } else { // Otherwise just return a new SaveDatas = ScriptableObject.CreateInstance <SaveData>(); SaveDatas.Reset(); } WriteSaveData(0); //copy values to temporary profile currentlyLoadedProfileNumber = profileNumber; // And set the current profile number for later use when we save. } }
public void LoadGame() { if (File.Exists(Application.persistentDataPath + "/playerdatas")) { //Debug.Log("wtf bro"); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/playerdatas", FileMode.Open); SaveDatas savedDatas = (SaveDatas)bf.Deserialize(file); file.Close(); SetLoadedDatas(savedDatas); } else { Debug.Log("no game saved"); } }
public void LoadGame() { if (File.Exists(Application.persistentDataPath + "/gamesave")) { //Debug.Log("wtf bro"); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/gamesave", FileMode.Open); SaveDatas savedDatas = (SaveDatas)bf.Deserialize(file); file.Close(); _scoreController.SetHighScore(savedDatas.GetSavedHighScore()); } else { Debug.Log("no game saved"); } }
/// <summary> /// データをロードする /// </summary> private void Load() { try { // 2回目以降のプレイ save_data_ = DataManager.Load <SaveDatas>(SaveDatas.SAVE_DATA_NAME); GetComponent <AudioManager>().audio_volume_ = save_data_.SoundData; Player.HorizontalRotetaSpeed = save_data_.HorizontalRotationSpeed; Player.VerticalRotetaSpeed = save_data_.VerticalRotationSpeed; } catch (System.Exception) { // 初プレイ時はロードするデータが無いため生成 save_data_ = new SaveDatas(); GetComponent <AudioManager>().audio_volume_ = new AudioVolume(); } }