Пример #1
0
    /// <summary>
    /// Loads the game data from PlayerPrefs. If no game data is found from PlayerPrefs
    /// a new game data will be initiated. This function should only be called once when the
    /// game loads in LoadingScene.
    /// </summary>
    public void LoadGameData()
    {
        //if gameData is not null then the gameData needs to be saved first
        //otherwise loading the new data will erase the current gameData
        if (gameData == null)
        {
            PetGameData newGameData = null;
            string      jsonString  = PlayerPrefs.GetString("GameData", "");

            //Check if json string is actually loaded and not empty
            if (!String.IsNullOrEmpty(jsonString))
            {
                newGameData = JSON.Instance.ToObject <PetGameData>(jsonString);

                                #if UNITY_EDITOR
                Debug.Log("Deserialized: " + jsonString);
                                #endif

                gameData = newGameData;

                if (Constants.GetConstant <bool>("ForceSecondPlayPeriod"))
                {
                    Debug.Log("Setting dummy data for second play period");
                    SetDummyDataForSecondPlayPeriod();
                }

                LoadDataVersion();

                Deserialized();
            }
            else
            {
                //initiate game data here because none is found in the PlayerPrefs
                gameData = new PetGameData();

                if (Constants.GetConstant <bool>("ForceSecondPlayPeriod"))
                {
                    Debug.Log("Setting dummy data for second play period");
                    SetDummyDataForSecondPlayPeriod();
                }

                Deserialized();
            }
        }
    }
Пример #2
0
 public void InitGameDataForDebug()
 {
     gameData = new PetGameData();
 }