public void LoadData() { if (File.Exists(Application.persistentDataPath + "/orthgonalData.dat")) { // You must clear ALL objects BinaryFormatter formatter = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/orthgonalData.dat", FileMode.Open); orthogonalDataSaveFormat saveFormat = (orthogonalDataSaveFormat)formatter.Deserialize(file); file.Close(); foreach (GameObject childs in saveFormat.ShapeList) { Instantiate(childs, childs.transform.position, childs.transform.rotation); } Camera.main.transform.position = saveFormat.CurrentObserverPosition; sliderHandler slide = new sliderHandler(); slide.xSlider.value = saveFormat.Xangle; slide.ySlider.value = saveFormat.Yangle; Debug.Log("Data has been loaded successfully."); } else { Debug.LogError("No data found. Is data corrupted or missing?"); } }
public void SaveOrthogonalData() { orthogonalDataSaveFormat saveFormat = CreateDataSaveFormatInstance(); BinaryFormatter formatter = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/orthgonalData.dat"); formatter.Serialize(file, saveFormat); file.Close(); Debug.Log("Data has been saved successfully."); }
private orthogonalDataSaveFormat CreateDataSaveFormatInstance() { orthogonalDataSaveFormat saveFormat = new orthogonalDataSaveFormat(); // saveFormat.ShapeList = GetComponent<GameObject> (); saveFormat.CurrentObserverPosition = Camera.main.transform.position; // saveFormat.Xangle = slide.xSlider.value; // saveFormat.Yangle = slide.ySlider.value; return(saveFormat); }