Beispiel #1
0
        /// <summary>
        /// Load the currencies.
        /// </summary>
        private void Load()
        {
            // Get the encrypted json of the Money.
            string currencyJson = PlayerPrefs.GetString("Money");

            // IF the Json string is null or empty
            if (String.IsNullOrEmpty(currencyJson))
            {
                // We leave as there is nothing to load.
                return;
            }
            // Turn the Json to Currency_Data.
            Currency_Data data = JsonUtility.FromJson <Currency_Data> (currencyJson);

            // Load the values of the players currency.
            for (int i = 0; i < currency.Length; i++)
            {
                currency [i].currencyName   = data.currencyName [i];
                currency [i].currencyAmount = data.currencyAmount [i];
            }
        }
Beispiel #2
0
        /// <summary>
        /// Save all the types of currencies.
        /// </summary>
        public void Save()
        {
            // Create a new Currency_Data.
            Currency_Data data = new Currency_Data();

            // Setup the data to be saved.
            string[] currNames  = new string[currency.Length];
            int[]    currAmount = new int[currency.Length];
            // Loop through the currencies.
            for (int i = 0; i < currency.Length; i++)
            {
                // Set the name and the amount.
                currNames [i]  = currency [i].currencyName;
                currAmount [i] = currency [i].currencyAmount;
            }
            // Save the data.
            data.currencyName   = currNames;
            data.currencyAmount = currAmount;
            // Turn the Currency_Data to json.
            string currencyToJson = JsonUtility.ToJson(data);

            // Save the information.
            PlayerPrefs.SetString("Money", currencyToJson);
        }