private void LoadData(string _dateName, SaveDataObject _dataObj) { if (File.Exists(Application.persistentDataPath + "/" + _dateName + ".save")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/" + _dateName + ".save", FileMode.Open); Save save = (Save)bf.Deserialize(file); file.Close(); // for (int i = 0; i < save.lowlevelPlayed.Count; i++) { _dataObj.lowlevelPlayed[i] += save.lowlevelPlayed[i]; _dataObj.medlevelPlayed[i] += save.medlevelPlayed[i]; _dataObj.highlevelPlayed[i] += save.highlevelPlayed[i]; // _dataObj.lowlevelMiss[i] += save.lowlevelMiss[i]; _dataObj.medlevelMiss[i] += save.medlevelMiss[i]; _dataObj.highlevelMiss[i] += save.highlevelMiss[i]; // _dataObj.lowlevelTime[i] += save.lowlevelTime[i]; _dataObj.medlevelTime[i] += save.medlevelTime[i]; _dataObj.highlevelTime[i] += save.highlevelTime[i]; } } else { Debug.Log("No Save Data"); } }
private int SaveObject(SaveDataObject o) { // TODO: padding not applied int count = Serializer.Write(o, FileFormat, out byte[] data); int written = SaveDataToWorkBuffer(data, count); Debug.Assert(written == count); return(written); }
private void LoadMonthData() { string loadDateString; monthDataObj = new SaveDataObject(); monthDataObj.Init(); monthDataObj.InitSum(); for (int i = 0; i < 30; i++) { loadDateString = CreateFilename(-i); LoadData(loadDateString, monthDataObj); } }
private void LoadWeekData() { string loadDateString; weekDataObj = new SaveDataObject(); weekDataObj.Init(); weekDataObj.InitSum(); for (int i = 0; i < 7; i++) { loadDateString = CreateFilename(-i); LoadData(loadDateString, weekDataObj); } }
public void JsonSerialization() { TestObject x0 = GenerateTestObject(); string json = x0.ToJsonString(); TestObject x1 = SaveDataObject.FromJsonString <TestObject>(json); Assert.Equal(x0.Value, x1.Value); Assert.Equal(x0.Object, x1.Object); Assert.Equal(x0.ValueArray, x1.ValueArray); Assert.Equal(x0.ObjectArray, x1.ObjectArray); Assert.Equal(x0, x1); }
// Start is called before the first frame update void Start() { gameState = "StartGame"; currentGridClick = -1; // Load Previous Data todayDateString = CreateFilename(0); Debug.Log(todayDateString); saveDataObj = new SaveDataObject(); saveDataObj.Init(); saveDataObj.InitSum(); LoadData(todayDateString, saveDataObj); // for (int i = 0; i < 26; i++) { Debug.Log("LP" + saveDataObj.medlevelPlayed[i]); } // LoadWeekData(); LoadMonthData(); // playVOAudio("title_new"); // toggleMusicOn(); }
void ParseDisplayData(int _letterSelect, SaveDataObject _dataObj) { if (_letterSelect == -1) { _dataObj.InitSum(); _dataObj.TotalSum(); // LevelsText[0].text = _dataObj.lowlevelSum.ToString(); LevelsText[1].text = _dataObj.medlevelSum.ToString(); LevelsText[2].text = _dataObj.highlevelSum.ToString(); // float lowPercent = 0; float medPercent = 0; float highPercent = 0; float totalPercent = 0; if (_dataObj.lowlevelSum != 0) { lowPercent = 100f - (100f * (_dataObj.lowmissSum / (_dataObj.lowlevelSum * 3f + _dataObj.lowmissSum))); Debug.Log(lowPercent); } if (saveDataObj.medlevelSum != 0) { medPercent = 100f - (100f * (_dataObj.medmissSum / (_dataObj.medlevelSum * 3f + _dataObj.medmissSum))); } if (saveDataObj.highlevelSum != 0) { highPercent = 100f - (100f * (_dataObj.highmissSum / (_dataObj.highlevelSum * 3f + _dataObj.highmissSum))); } // PercentText[0].text = lowPercent.ToString("F1"); PercentText[1].text = medPercent.ToString("F1"); PercentText[2].text = highPercent.ToString("F1"); // float lowMinutes = _dataObj.lowtimeSum / 60f; float medMinutes = _dataObj.medtimeSum / 60f; float highMinutes = _dataObj.hightimeSum / 60f; // TimeSpentText[0].text = lowMinutes.ToString("F1"); TimeSpentText[1].text = medMinutes.ToString("F1"); TimeSpentText[2].text = highMinutes.ToString("F1"); // if (_dataObj.levelSum != 0) { totalPercent = 100f - (100f * (_dataObj.missSum / (_dataObj.levelSum * 3f + _dataObj.missSum))); } float totalMinutes = _dataObj.timeSum / 60f; LevelsText[3].text = _dataObj.levelSum.ToString(); PercentText[3].text = totalPercent.ToString("F1"); TimeSpentText[3].text = totalMinutes.ToString("F1"); } else { _dataObj.InitSum(); _dataObj.LevelSum(_letterSelect); // LevelsText[0].text = _dataObj.lowlevelPlayed[_letterSelect].ToString(); LevelsText[1].text = _dataObj.medlevelPlayed[_letterSelect].ToString(); LevelsText[2].text = _dataObj.highlevelPlayed[_letterSelect].ToString(); // float lowPercent = 0; float medPercent = 0; float highPercent = 0; float totalPercent = 0; if (_dataObj.lowlevelPlayed[_letterSelect] != 0) { lowPercent = 100f - (100f * (_dataObj.lowlevelMiss[_letterSelect] / (_dataObj.lowlevelPlayed[_letterSelect] * 3f + _dataObj.lowlevelMiss[_letterSelect]))); } if (saveDataObj.medlevelPlayed[_letterSelect] != 0) { medPercent = 100f - (100f * (_dataObj.medlevelMiss[_letterSelect] / (_dataObj.medlevelPlayed[_letterSelect] * 3f + _dataObj.medlevelMiss[_letterSelect]))); } if (saveDataObj.highlevelPlayed[_letterSelect] != 0) { highPercent = 100f - (100f * (_dataObj.highlevelMiss[_letterSelect] / (_dataObj.highlevelPlayed[_letterSelect] * 3f + _dataObj.highlevelMiss[_letterSelect]))); } // PercentText[0].text = lowPercent.ToString("F1"); PercentText[1].text = medPercent.ToString("F1"); PercentText[2].text = highPercent.ToString("F1"); // float lowMinutes = _dataObj.lowlevelTime[_letterSelect] / 60f; float medMinutes = _dataObj.medlevelTime[_letterSelect] / 60f; float highMinutes = _dataObj.highlevelTime[_letterSelect] / 60f; // TimeSpentText[0].text = lowMinutes.ToString("F1"); TimeSpentText[1].text = medMinutes.ToString("F1"); TimeSpentText[2].text = highMinutes.ToString("F1"); // if (_dataObj.levelSum != 0) { totalPercent = 100f - (100f * (_dataObj.missSum / (_dataObj.levelSum * 3f + _dataObj.missSum))); } float totalMinutes = _dataObj.timeSum / 60f; LevelsText[3].text = _dataObj.levelSum.ToString(); PercentText[3].text = totalPercent.ToString("F1"); TimeSpentText[3].text = totalMinutes.ToString("F1"); } }