public GameDataScriptableObject BuildGameData() { GameDataScriptableObject gd = ScriptableObject.CreateInstance <GameDataScriptableObject>(); gd.deathCount = deathCount; gd.maxScore = maxScore; gd.maxWave = maxWave; return(gd); }
/// <summary> /// Load save data from disk or create one if it doesn't exists /// </summary> public void LoadGameData() { Debug.Log("Loading game data..."); if (File.Exists(Application.persistentDataPath + "/gamedata.dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream fs = File.OpenRead(Application.persistentDataPath + "/gamedata.dat"); GameDataSerializableWrapper gdsw = (GameDataSerializableWrapper)bf.Deserialize(fs); currentGameData = gdsw.BuildGameData(); fs.Close(); Debug.Log("Game data loaded!"); return; } Debug.Log("No save file found!"); CreateGameData(); SaveGameData(); }
public GameDataSerializableWrapper(GameDataScriptableObject gameData) { deathCount = gameData.deathCount; maxWave = gameData.maxWave; maxScore = gameData.maxScore; }
/// <summary> /// Create default game data /// </summary> /// <returns>Default game data</returns> public GameDataScriptableObject CreateGameData() { currentGameData = UnityEngine.Object.Instantiate <GameDataScriptableObject>(defaultGameData); return(currentGameData); }