Exemplo n.º 1
0
    public void Load(string playerPrefKey)
    {
        string message = "";

        try
        {
            string tmp = PlayerPrefs.GetString(playerPrefKey, string.Empty);

            if (tmp != string.Empty)
            {
                MemoryStream memoryStream = new MemoryStream(System.Convert.FromBase64String(tmp));

                HappyPlane.GameStateObject gameObject = (HappyPlane.GameStateObject)bf.Deserialize(memoryStream);

                gamestate.Instance.setActiveLevel(activeLevel_default);                                     // Active level
                gamestate.Instance.SetLevelProgress(gameObject.levelProgress);                              //the max level the have achieved
                //gamestate.Instance.SetNumberOfLevels(gameObject.numberOfLevels);						//the number of levels that exist in the game
                gamestate.Instance.SetScore(score_default);                                                 //the current game score
                gamestate.Instance.SetHighScore(gameObject.highScore);                                      //the highScore for the game since install
                gamestate.Instance.SetLives(lives_default);                                                 //the number of lives the player has
                gamestate.Instance.SetHealth(health_default);
                gamestate.Instance.SetGameRunning(gameRunning_default);
            }
        }
        catch (Exception ex)
        {
            message = ex.Message;
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Save this instance to player prefs
    /// </summary>
    public void Save(string playerPrefKey)
    {
        string message = "";

        try
        {
            HappyPlane.GameStateObject serializableObject = new HappyPlane.GameStateObject();
            serializableObject.activeLevel    = getActiveLevel();
            serializableObject.gameRunning    = IsGameRunning();
            serializableObject.health         = GetHealth();
            serializableObject.highScore      = getHighScore();
            serializableObject.lives          = getLives();
            serializableObject.levelProgress  = getLevelProgress();
            serializableObject.numberOfLevels = GetNumberOfLevels();
            serializableObject.score          = getScore();

            System.IO.MemoryStream memoryStream = new MemoryStream();

            bf.Serialize(memoryStream, serializableObject);
            string tmp = System.Convert.ToBase64String(memoryStream.ToArray());
            PlayerPrefs.SetString(playerPrefKey, tmp);
        }
        catch (Exception ex)
        {
            message = ex.Message;
        }
    }