public bool saveData() { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Create(Application.persistentDataPath + "/playerInfo.dat"); serializablePlayerData data = new serializablePlayerData(); data.time = this.Time; data.cigarettes = this.Cigarettes; data.price = this.Price; data.balance = this.Balance; data.experience = this.Experience; data.experienceneeded = this.experienceNeeded; data.level = this.level; data.maruJumpHighScore = this.maruJumpHighScore; data.snakeHighscore = this.SnakeHighscore; data.bbtanHighscore = this.bbtanHighscore; data.appleColor = this.appleColor; data.BBtanBallColor = this.bbtanBallColor; data.paddleColor = this.paddleColor; data.snakeColor = this.snakeColor; data.achievements = this.achievement; data.inventory = this.shopInventory; bf.Serialize(file, data); file.Close(); return(true); }
public bool loadData() { if (File.Exists(Application.persistentDataPath + "/playerInfo.dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/playerInfo.dat", FileMode.Open); serializablePlayerData data = bf.Deserialize(file) as serializablePlayerData; file.Close(); this.time = data.time; this.cigarettes = data.cigarettes; this.price = data.price; this.balance = data.balance; this.experience = data.experience; this.experienceNeeded = data.experienceneeded; this.level = data.level; if (data.snakeColor != null) { this.snakeColor = data.snakeColor; } if (data.BBtanBallColor != null) { this.bbtanBallColor = data.BBtanBallColor; } if (data.paddleColor != null) { this.paddleColor = data.paddleColor; } if (data.appleColor != null) { this.appleColor = data.appleColor; } this.MaruJumpHighScore = data.maruJumpHighScore; this.SnakeHighscore = data.snakeHighscore; this.achievement = data.achievements; this.shopInventory = data.inventory; this.bbtanHighscore = data.bbtanHighscore; return(true); } return(false); }