Пример #1
0
    public void LoadGame()
    {
        SaveableGame game = SaveLoad.instance.Load();

        GameManager.instance.LoadGame(game);
        Application.LoadLevel(game.level);
    }
 private void OnDestroy()
 {
     ///if the object was destroyed while the game was not in loading phase,
     ///its removed from the object saving list
     if (!GamePersistence.IsLoading)
     {
         SaveableGame.removeObjectFromSavedList(this);
     }
 }
Пример #3
0
 protected override void Awake()
 {
     base.Awake();
     if (!SaveableGame.KeepObjects)
     {
         ///if the object is not gonna be kept, it is added to the garbage heap so it can be deleted later
         SaveableGame.addObjectToGarbageHeap(gameObject);
     }
 }
Пример #4
0
 /// <summary>
 /// loads all saved games slots, to show the load choices
 /// </summary>
 public void LoadSaveSlots()
 {
     foreach (string s in FolderSystem.getAllSaveSlotNames())
     {
         SaveableGame game = LoadSaveable <SaveableGame>
                                 (FolderSystem.getGameSavePath(Path.GetFileName(s)));
         allSavedGames.Add(game);
     }
 }
Пример #5
0
 public SaveableGame Load()
 {
     if(File.Exists(Application.persistentDataPath + "/savedGames.gd")) {
         BinaryFormatter bf = new BinaryFormatter();
         FileStream file = File.Open(Application.persistentDataPath + "/savedGames.gd", FileMode.Open);
         loadedGame = (SaveableGame)bf.Deserialize(file);
         file.Close();
     }
     return loadedGame;
 }
Пример #6
0
 public SaveableGame Load()
 {
     if (File.Exists(Application.persistentDataPath + "/savedGames.gd"))
     {
         BinaryFormatter bf   = new BinaryFormatter();
         FileStream      file = File.Open(Application.persistentDataPath + "/savedGames.gd", FileMode.Open);
         loadedGame = (SaveableGame)bf.Deserialize(file);
         file.Close();
     }
     return(loadedGame);
 }
Пример #7
0
    protected override void Awake()
    {
        initialize();

        SaveableGame.addObjectToCurrentScene(this);

        if (SaveableGame.FirstTimeSceneLoaded)
        {
            pathFromRoot = buildRootPath();
        }
    }
Пример #8
0
    private void EnterRunningGame_()
    {
        lock (SyncRoot)
        {
            IsLoading   = true;
            currentGame = new SaveableGame(this);
            string currentSceneName = SceneManager.GetActiveScene().name;

            currentGame.prepareNextScene(currentSceneName, null, false);
        }
    }
Пример #9
0
    // Use this for initialization
    void Start()
    {
        game = GameManager.instance.game;
        GameManager.instance.levelOver = false;

        Text levelText = GameObject.Find ("LevelText").GetComponent<Text> ();
        levelText.text = "Level = " + game.level;

        UpdatePointDisplay ();
        UpdateShotDelayDisplay ();
    }
Пример #10
0
    // Use this for initialization
    void Start()
    {
        game = GameManager.instance.game;
        GameManager.instance.levelOver = false;

        Text levelText = GameObject.Find("LevelText").GetComponent <Text> ();

        levelText.text = "Level = " + game.level;

        UpdatePointDisplay();
        UpdateShotDelayDisplay();
    }
    protected virtual void Awake()
    {
        initialize();

        ///if the object was not created during loading phase or the
        ///load phase is creating all saved objects, or the scene is loaded in default state, add this object to saving list
        ///otherwise destroy it
        if (SaveableGame.KeepObjects)
        {
            SaveableGame.addObjectToCurrentScene(this);
        }
    }
Пример #12
0
    public void LoadGame_(int index)
    {
        timer.start("started loading");
        lock (SyncRoot)
        {
            IsDataRestored = true;

            IsLoading = true;

            internIsLoading = true;

            ///reload game out of file (in case a reference changed something)
            allSavedGames[index] = LoadSaveable <SaveableGame>
                                       (FolderSystem.getGameSavePath(allSavedGames[index].GameName));

            timer.addCheckPoint("read data out of file");

            ///clones the save slot, so it can be edited without altering the save slot
            currentGame = allSavedGames[index];

            currentGame.loadGame(this);
        }
    }
Пример #13
0
    public static void DeleteGame(SaveableGame game)
    {
        string path = getGameDirectory(game.GameName);

        Directory.Delete(path, true);
    }
Пример #14
0
 public static string getSceneSavePath(SaveableGame game, string sceneName)
 {
     return(getSceneSavePath(game.GameName, sceneName));
 }
Пример #15
0
 public static string getGameSavePath(SaveableGame game)
 {
     return(getGameSavePath(game.GameName));
 }
Пример #16
0
 public void LoadGame(SaveableGame loadedGame)
 {
     game = loadedGame;
 }
Пример #17
0
 public void LoadGame(SaveableGame loadedGame)
 {
     game = loadedGame;
 }
Пример #18
0
 static StaticGameData()
 {
     SaveableGame.AddStaticGameData(typeof(T));
 }
Пример #19
0
    private bool SaveGame_(string saveName, out string resultMessage)
    {
        timer.start("Save Game");
        bool result = true;
        // try
        // {
        SaveableGame overwriteThis =
            allSavedGames.Where(game => game.GameName == saveName).FirstOrDefault();

        ///if a game is overwritten, and its not the current game,
        ///or a new save slot is created the current
        ///game has to be reloaded from file, to avoid two games
        ///in the game list have the same reference
        bool overwriteCurrent = saveName == currentGame.GameName;

        ///the current game index is used, to destroy the reference between the
        ///original loaded game and the new save slot.
        int currentGameIndex = -1;

        ///this is only needed, when a different save slot than the current
        ///is used or no save slot is overwritten (new one or other)
        if (!overwriteCurrent || overwriteThis == null)
        {
            currentGameIndex = allSavedGames.IndexOf(currentGame);
        }

        string oldGameName = currentGame.GameName;

        ///converts all objects into saveable objects
        currentGame.saveCurrentScene(PersistentGameDataController.SaveType.Game);

        timer.addCheckPoint("current scene saved");

        currentGame.GameName = saveName;

        if (overwriteThis != null && !overwriteCurrent)
        {
            allSavedGames.Remove(overwriteThis);
            FolderSystem.DeleteGame(overwriteThis);
            overwriteThis = null;
        }

        ///store game and loaded scenes in file
        SaveGameAndScenesToFile(saveName);

        ///if a new save slot is created, all not loaded scenes must be copied
        ///in the new director, so all data is transfered
        if (overwriteThis == null)
        {
            ///only copy if the current game exists in the savedGameList
            if (currentGameIndex >= 0)
            {
                CopyAllNotLoadedScenesToDirectory
                    (FolderSystem.getDefaulScenePath(saveName));
            }
            allSavedGames.Add(currentGame);
        }

        ///if the index is bigger equals zero the old game should/will be reloaded
        ///to avoid two saved games reference to the same saveableGame
        if (currentGameIndex >= 0)
        {
            ///load old game and set it in the savedgame list
            allSavedGames[currentGameIndex] = LoadSaveable <SaveableGame>
                                                  (FolderSystem.getGameSavePath(oldGameName));
        }

        resultMessage = "Game saved.";
        result        = true;

        /*  }
         * catch (System.Exception ex)
         * {
         *    ///if an error occured, the first attempt to fix it, is to
         *    ///reload the existing games out of the files
         *    loadSaveSlots();
         *    resultMessage = "An error occured while saving the game: " +
         *        ex.ToString() + ", StackTrace:" + ex.StackTrace;
         *    result = false;
         *    Debug.LogWarning(resultMessage);
         * }*/
        timer.finish("finished saving");
        return(result);
    }
Пример #20
0
    public static void test()
    {
        SaveableGame.AddStaticGameData(typeof(TestStaticData));

        //StaticGameData<TestStaticData>.Instance.i = 4;
    }
Пример #21
0
 private void ExitGame_(string menueSceneName)
 {
     currentGame = null;
     LoadScene(menueSceneName);
 }
Пример #22
0
 private void exitGame(string menueSceneName)
 {
     currentGame = null;
     loadScene(menueSceneName);
 }