public static void SaveData(score Score) { BinaryFormatter bf = new BinaryFormatter(); FileStream stream = new FileStream(Application.persistentDataPath + "/data.sav", FileMode.Create); scoreData data = new scoreData(Score); bf.Serialize(stream, data); stream.Close(); }
public static float[] LoadData() { if (File.Exists(Application.persistentDataPath + "/data.sav")) { BinaryFormatter bf = new BinaryFormatter(); FileStream stream = new FileStream(Application.persistentDataPath + "/Data.sav", FileMode.Open); scoreData Data = bf.Deserialize(stream) as scoreData; Debug.Log("u svaed us!"); stream.Close(); return(Data.stats); } return(null); }
public static void Load() { if (File.Exists(Application.persistentDataPath + "/highscore.dat")) { BinaryFormatter bF = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/highscore.dat", FileMode.Open); scoreData data = (scoreData)bF.Deserialize(file); highScore = data.highScore; } else { return; } }
public void LoadMeilleurScore() { BinaryFormatter bf = new BinaryFormatter(); if (!File.Exists(Application.persistentDataPath + "gameInfoHighRecs.dat")) { throw new Exception("Game file doesnt exist"); } FileStream file = File.Open(Application.persistentDataPath + "gameInfoHighRecs.dat", FileMode.Open); scoreData scoreDataToLoad = (scoreData)bf.Deserialize(file); bestTimeToFinish = scoreDataToLoad.gameHighscore.Where(s => s.mapIndex == mapIndex).FirstOrDefault().bestTimeToFinish; DataHighScore = scoreDataToLoad.gameHighscore; file.Close(); }
public static void Save() { BinaryFormatter bF = new BinaryFormatter(); scoreData data = new scoreData(); data.highScore = ScoreManager.currentScore; if (!File.Exists(Application.persistentDataPath + "/highscore.dat")) { FileStream file = File.Create(Application.persistentDataPath + "/highscore.dat"); bF.Serialize(file, data); } else { FileStream file = File.Open(Application.persistentDataPath + "/highscore.dat", FileMode.Open); bF.Serialize(file, data); } }
public void SaveFirstScore() { FileStream file = File.Open(Application.persistentDataPath + "gameInfoHighRecs.dat", FileMode.Create); try { BinaryFormatter bf = new BinaryFormatter(); scoreData scoreDataToSave = new scoreData(); scoreDataToSave.gameHighscore = DataHighScore; bf.Serialize(file, scoreDataToSave); file.Close(); } catch (Exception e) { file.Close(); throw new Exception(e.ToString()); } }
public void SaveHasHighScore() { FileStream file = File.Open(Application.persistentDataPath + "gameInfoHighRecs.dat", FileMode.Create); try { BinaryFormatter bf = new BinaryFormatter(); scoreData scoreDataToSave = new scoreData(); DataHighScore.Where(s => s.mapIndex == mapIndex).FirstOrDefault().bestTimeToFinish = newTimeToFinish; scoreDataToSave.gameHighscore = DataHighScore; bf.Serialize(file, scoreDataToSave); file.Close(); } catch (Exception e) { file.Close(); throw new Exception(e.ToString()); } }
//save last score and high score public void saveScore() { //data file definitions BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(path); scoreData data = new scoreData(); //set new highscore if(points > highScore){ highScore = points; } data.highScore = highScore; //set new lastscore lastScore = points; data.lastScore = lastScore; //save data and close file bf.Serialize(file, data); file.Close(); }
IEnumerator uploadDataToRaspi(int miss, float time) { scoreData postData = new scoreData(); postData.name = "None"; postData.time = ((int)time).ToString(); postData.miss = miss.ToString(); postData.score = ((int)time + miss * PenaByMiss).ToString(); postData.difficulty = "1"; scoreJson scorejson = new scoreJson(); scorejson.score = postData; string postJson = JsonUtility.ToJson(scorejson); byte[] postByte = System.Text.Encoding.UTF8.GetBytes(postJson); var request = new UnityWebRequest("http://192.168.100.25:5000", "POST"); request.uploadHandler = (UploadHandler) new UploadHandlerRaw(postByte); request.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer(); request.SetRequestHeader("Content-Type", "application/json"); yield return(request.Send()); /* * WWWForm form = new WWWForm(); * form.AddField("miss", miss.ToString()); * form.AddField("time", ((int)time).ToString()); * form.AddField("name", "None"); * form.AddField("score", ((int)time + miss * PenaByMiss).ToString()); * form.AddField("", ((int)time + miss * PenaByMiss).ToString()); * using (UnityWebRequest www = UnityWebRequest.Post("http://192.168.4.1/", form)) { * yield return www.SendWebRequest(); * if (www.isNetworkError) { * Debug.Log(www.error); * } else { * Debug.Log("Form upload complete!"); * } * } */ }
public string temp; // Refactored output (sent in fileOutput method) public void execute(string file, string tmpFile) { // https://docs.microsoft.com/en-us/dotnet/standard/io/how-to-read-text-from-a-file using (StreamReader input = new StreamReader(tmpFile)) { string content; // Make global above?? while ((content = input.ReadLine()) != null) { temp = temp + content + "\n"; } if (content != null) { temp = temp.Trim(); } } using (StreamReader input = new StreamReader(file)) { String content = input.ReadLine(); columns = new List <string>(content.Split('\t')); // https://stackoverflow.com/questions/3575029/c-sharp-liststring-to-string-with-delimiter while ((content = input.ReadLine()) != null) { List <string> columnData; columnData = new List <string>(content.Split('\t')); scoreData scores = new scoreData(); int count = columns.Count; for (int i = 0; i < count; i++) { scores.records.Add(columns[i], columnData[i]); } data.Add(scores); } } foreach (scoreData score in data) { score.fileOutput(temp); } }
void CheckHighScores(int score) { if (HighScores.ScoreList.Count == 0) { Debug.Log("highscore first set"); scoreData record = new scoreData(); record.score = score; if (name_to_record.text == null) { record.name = "Miner"; } else { record.name = name_to_record.text; } HighScores.ScoreList.Insert(0, record); high_score_pos = 0; //SaveHighScores(); } else { for (int i = 0; i < HighScores.ScoreList.Count; i++) { if (score >= HighScores.ScoreList[i].score) { Debug.Log("highscore beaten"); scoreData record = new scoreData(); record.score = score; if (name_to_record.text == null) { record.name = "Miner"; } else { record.name = name_to_record.text; } HighScores.ScoreList.Insert(i, record); high_score_pos = i; //SaveHighScores(); break; } else { high_score_pos = 100; } } } Debug.Log(high_score_pos); if (high_score_pos > 2) { name_to_record.gameObject.SetActive(false); save_button.gameObject.SetActive(false); new_high_score.gameObject.SetActive(false); } else { new_high_score.text = "New High Score of " + score; } //foreach (scoreData saved_score in HighScores.ScoreList) //{ // if (saved_score.score <= score) // { // } //} }