/// <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)); }