public void SaveGameSlotSelected(SaveGameSlotMenu slot) { Core.GameState.SavedOn = DateTime.Now; var gameStateString = UnityEngine.JsonUtility.ToJson(Core.GameState, true); var directoryPath = Path.Combine(Application.persistentDataPath, "Savegames"); if (!Directory.Exists(directoryPath)) { Directory.CreateDirectory(directoryPath); } var slotIndex = SavegameSlots.IndexOf(slot); var fileName = Path.Combine(directoryPath, String.Format("Save{0}.nerds", slotIndex)); if (File.Exists(fileName)) { File.Delete(fileName); } File.WriteAllText(fileName, gameStateString); Core.Savegames[slotIndex] = new Savegame() { PlanetsVisited = Core.GameState.PlanetsVisited, SavedOn = Core.GameState.SavedOn, RawSource = gameStateString }; SetVisible(pauseMenu: true); }
public void LoadGameState(SaveGameSlotMenu saveGameSlotMenu) { if (saveGameSlotMenu.Savegame != default) { var gameState = UnityEngine.JsonUtility.FromJson <GameState>(saveGameSlotMenu.Savegame.RawSource); Core.StartGame(gameState); } }