Пример #1
0
        public void ResetGameAndJson()
        {
            IncomeData = new SaveIncomeData
            {
                numberOfOwnedProducts        = 1,
                totalNumberOfProductsCanSell = 3,
                productIncomeData            = new ProductIncomeData[1]
            };

            PlayerData = new SavePlayerData
            {
                playerLevelData = new PlayerLevelData(1, 0, 200),
                characterData   = new CharacterData(0, 7),
            };

            MultiplierData = new SaveMultiplierData
            {
            };

            IncomeData.productIncomeData[0] = new ProductIncomeData(0, 1, 15, 0, 0, 0.10f);

            //Shoves all the SaveData information into one long ass string.
            string incomeContents     = JsonUtility.ToJson(IncomeData, true);
            string playerContents     = JsonUtility.ToJson(PlayerData, true);
            string multiplierContents = JsonUtility.ToJson(MultiplierData, true);

            //Writes it all to the dataFileName (data.json) and stores that file into the dataPath (Application.persistentDataPath, or the folder that the phone or computers allows us to store.)
            File.WriteAllText(incomeDataPath, incomeContents);
            File.WriteAllText(playerDataPath, playerContents);
            File.WriteAllText(multiplierDataPath, multiplierContents);

            UnityEngine.SceneManagement.SceneManager.LoadScene(0);
        }
Пример #2
0
        public void SaveToJson()
        {
            //Creates a new SaveData class, which resets everything to default values of 0.
            IncomeData     = new SaveIncomeData();
            PlayerData     = new SavePlayerData();
            MultiplierData = new SaveMultiplierData();

            //Grabs all the necessary information and shoves it into the SaveData class.
            SavePlayerData();
            SaveIncomeData();
            SaveMultiplierData();

            //Shoves all the SaveData information into one long ass string.
            string incomeContents     = JsonUtility.ToJson(IncomeData, true);
            string playerContents     = JsonUtility.ToJson(PlayerData, true);
            string multiplierContents = JsonUtility.ToJson(MultiplierData, true);

            //Writes it all to the dataFileName (data.json) and stores that file into the dataPath (Application.persistentDataPath, or the folder that the phone or computers allows us to store.)
            File.WriteAllText(incomeDataPath, incomeContents);
            File.WriteAllText(playerDataPath, playerContents);
            File.WriteAllText(multiplierDataPath, multiplierContents);
        }