Example #1
0
    /// <summary>
    /// Don't use! Old way of saving
    /// </summary>
    /// <returns></returns>
    //private IEnumerator SaveRoutine()
    //{
    //    UIManager.Singleton.SetSaveGameIcon(true);

    //    yield return new WaitForEndOfFrame();
    //    GameSaveData.GetAllData();

    //    Directory.CreateDirectory(Application.persistentDataPath + @"\SaveGames\");

    //    var serializer = new XmlSerializer(typeof(GameSaveData));
    //    //var stream = new FileStream(Path.Combine(Application.persistentDataPath + @"\SaveGames\", "SaveData.xml"), FileMode.Create);
    //    var stream = new FileStream(Path.Combine(Application.persistentDataPath + @"\SaveGames\", StoreManager.StoreName + ".xml"), FileMode.Create);
    //    serializer.Serialize(stream, GameSaveData);
    //    stream.Close();

    //    //Debug.Log("Game Saved: " + Path.Combine(Application.persistentDataPath + @"\SaveGames\", "SaveData.xml"));
    //    Debug.Log("Game Saved: " + Path.Combine(Application.persistentDataPath + @"\SaveGames\", StoreManager.StoreName + ".xml"));

    //    yield return new WaitForEndOfFrame();

    //    UIManager.Singleton.SetSaveGameIcon(false);

    //}

    public void LoadGame(string fileName)
    {
        var serializer = new XmlSerializer(typeof(GameSaveData));
        //var stream = new FileStream(Path.Combine(Application.persistentDataPath + @"\SaveGames\", "SaveData.xml"), FileMode.Open);
        var stream = new FileStream(Path.Combine(Application.persistentDataPath + @"\SaveGames\", fileName), FileMode.Open);

        GameSaveData = serializer.Deserialize(stream) as GameSaveData;
        stream.Close();

        if (GameSaveData != null)
        {
            GameSaveData.ApplyDataToGame();

            MusicEnabled = PlayerPrefsX.GetBool(SettingsMusic, true);
            SoundEnabled = PlayerPrefsX.GetBool(SettingsSound, true);

            //UIManager.Singleton.SetSound(SoundEnabled);
            //UIManager.Singleton.SetMusic(MusicEnabled);

            UIManager.Singleton.SetOptionsToggles(MusicEnabled, SoundEnabled);
            EconomyManager.Singleton.JustLoadedSavedGame = true;
        }
        else
        {
            UIManager.Singleton.ShowMessage("No Saves", "No savegames found!");
        }
    }
Example #2
0
 public void ApplySaveData(GameSaveData gameSaveData)
 {
     GameSaveData = gameSaveData;
     gameSaveData.ApplyDataToGame();
 }