public void Save() { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = File.Create(Application.persistentDataPath + "/" + saveFile); CoreDataO cdO = new CoreDataO(this.hp, this.xp, this.lvl); bf.Serialize(fs, cdO); fs.Close(); }
public void Load(string fileName) { string path = Application.persistentDataPath + "/" + fileName; saveFile = fileName; if (File.Exists(path)) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(path, FileMode.Open); CoreDataO cd = (CoreDataO)bf.Deserialize(file); file.Close(); SetFields(cd); lvl = cd.lvl; Application.LoadLevel(lvl); } else { Debug.LogError("No File found of name: " + fileName); } }
private void SetFields(CoreDataO cd) { this.hp = cd.health; this.xp = cd.xp; }