public static void SaveData(DnParent mama) { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/roll.save"; FileStream stream = new FileStream(path, FileMode.Create); DnData data = new DnData(mama); formatter.Serialize(stream, data); stream.Close(); }
public static DnData LoadData() { string path = Application.persistentDataPath + "/roll.save"; if (File.Exists(path)) { BinaryFormatter formatter = new BinaryFormatter(); FileStream stream = new FileStream(path, FileMode.Open); DnData data = formatter.Deserialize(stream) as DnData; stream.Close(); return(data); } else { Debug.LogError("Save file not found in " + path); return(null); } }
public void LoadState() { DnData data = SaveSystem.LoadData(); this.name = data.name; Vector3 position; position.x = data.position[0]; position.y = data.position[1]; position.z = data.position[2]; transform.position = position; GameObject[] babies = new GameObject[data.children.Length]; Vector3[] babyLoc = new Vector3[data.children.Length]; for (int i = 0; i < data.children.Length; i++) { babies[i].name = data.children[i].name; babyLoc[i].x = data.babyPos[i][0]; babyLoc[i].y = data.babyPos[i][1]; babyLoc[i].z = data.babyPos[i][2]; babies[i].transform.position = babyLoc[i]; } }