public static ScoreboardData LoadScoreboard() { string path = Application.persistentDataPath + "/scoreboard.xssoftware"; if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); if (stream.Length != 0) { ScoreboardData data = formatter.Deserialize(stream) as ScoreboardData; stream.Close(); return(data); } else { Debug.Log("Save file not found " + path); return(null); } } else { Debug.Log("Save file not found " + path); return(null); } }
public static void SaveScoreboard(GameManager gameManager) { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/scoreboard.xssoftware"; FileStream stream = new FileStream(path, FileMode.Create); ScoreboardData data = new ScoreboardData(gameManager); formatter.Serialize(stream, data); stream.Close(); }
public async Task SetScoreboard(ScoreboardData scoreboardData) { RaiseEvent(new ScoreboardChanged { CurrentTime = scoreboardData.CurrentTime, CurrentScore = scoreboardData.CurrentScore, ScoresByPeriod = scoreboardData.ScoresByPeriod }); await ConfirmEvents(); }
public void LoadScoreboard() { ScoreboardData data = SaveSystem.LoadScoreboard(); if (data != null) { for (int i = 0; i < scoreboardSize; i++) { scoreboard[i] = data.scoreboard[i]; } } }
void WriteData() { IFormatter binFormatter = new BinaryFormatter(); try{ Stream wFile = new FileStream(filepath, FileMode.OpenOrCreate, FileAccess.Write); binFormatter.Serialize(wFile, myData); Debug.Log("Writing to filepath '" + filepath + "'"); wFile.Close(); } catch (IOException exc) { Debug.Log("Error writing file"); Debug.LogException(exc); } catch (SerializationException exc) { Debug.Log("Error serializing data"); Debug.LogException(exc); myData = new ScoreboardData(); } }
void ReadData() { IFormatter binFormatter = new BinaryFormatter(); try{ Stream rFile = new FileStream(filepath, FileMode.Open, FileAccess.Read); myData = binFormatter.Deserialize(rFile) as ScoreboardData; Debug.Log("Reading from filepath '" + filepath + "'"); rFile.Close(); } catch (IOException exc) { Debug.Log("Error writing file"); Debug.LogException(exc); myData = new ScoreboardData(); } catch (SerializationException exc) { Debug.Log("Error serializing data"); Debug.LogException(exc); myData = new ScoreboardData(); } }