public SaveData() { Score = Game.Score.OnSave() as ScoreData; Player = Game.Player.OnSave() as PlayerGameData; Asteroids = Game.Asteroids.OnSave() as AsteroidsData; Bullets = Game.Bullets.OnSave() as BulletsData; }
private void SetEmptyAsteroidsData() { AsteroidsData = new AsteroidsData(); AsteroidsData.AsteroidXDirection = new float[FieldSize, FieldSize]; AsteroidsData.AsteroidYDirection = new float[FieldSize, FieldSize]; AsteroidsData.AsteroidSpeed = new float[FieldSize, FieldSize]; SaveExists = false; }
private void TryLoadingAsteroidsDataFromFile() { if (File.Exists(Application.persistentDataPath + "/AsteroidsData.dat")) { if (new FileInfo(Application.persistentDataPath + "/AsteroidsData.dat").Length == 0) { BinaryFormatter binaryFormatter = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/AsteroidsData.dat", FileMode.Open); AsteroidsData = (AsteroidsData)binaryFormatter.Deserialize(file); file.Close(); SaveExists = true; } else { SetEmptyAsteroidsData(); } } else { SetEmptyAsteroidsData(); } }