Exemplo n.º 1
0
        private void Awake()
        {
            if (!GameSettings.NewGame && DoesSaveGameExist(DEFAULT_SAVE_GAME_NAME))
            {
                currentSaveGame = LoadGame(DEFAULT_SAVE_GAME_NAME);

                if (currentSaveGame == null)
                {
                    GameSettings.NewGame = true;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Restore tilemap data from a savegame to the gameobjects.
        /// </summary>
        /// <param name="saveGame"></param>
        private static void RestoreTileMapData(MainSaveGame saveGame)
        {
            var go   = GameObject.FindWithTag("Pathfinding");
            var grid = go.GetComponent <AGrid>();

            for (int x = 0; x < AGrid.GridSizeX; x++)
            {
                for (int y = 0; y < AGrid.GridSizeY; y++)
                {
                    var node = grid.getNode(new Vector2Int(x, y));
                    node.SetData(saveGame.Tilemap[x, y]);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a new savegame object.
        /// This method gathers all data and prepares the object
        /// for storage.
        /// </summary>
        /// <param name="saveGameName"></param>
        /// <returns></returns>
        private MainSaveGame CreateNewSaveGame(string saveGameName, string modName)
        {
            MainSaveGame saveGame = new MainSaveGame();

            saveGame.name                    = saveGameName;
            saveGame.saveDate                = DateTime.Now;
            saveGame.employeeManagerData     = EmployeeManager.GetData();
            saveGame.missionManagerData      = MissionManager.GetData();
            saveGame.teamManagerData         = TeamManager.Instance.GetData();
            saveGame.gameTime                = GameTime.GameTime.Instance.GetData();
            saveGame.NotificationManagerData = NotificationManager.GetData();
            FillTileMapData(saveGame);
            saveGame.balance       = bank.Balance;
            saveGame.Difficulty    = GameSettings.Difficulty;
            saveGame.TutorialStage = TutorialStage;
            saveGame.modId         = modName;
            return(saveGame);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Save a saveGame to disk.
        /// </summary>
        /// <param name="saveGame">SaveGame Object to save.</param>
        /// <returns>Successfully saved?</returns>
        public static bool SaveGameToFile(MainSaveGame saveGame)
        {
            BinaryFormatter formatter = CreateBinaryFormatter();

            using (var stream = new FileStream(GetSavePath(saveGame.name), FileMode.Create))
            {
                try
                {
                    formatter.Serialize(stream, saveGame);
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                    return(false);
                }

                return(true);
            }
        }