/// <summary> /// Load the keys. /// </summary> private void Load() { // Get the saved encrypted information. string keyJson = PlayerPrefs.GetString("Key"); // If we have a null or empty string. if (String.IsNullOrEmpty(keyJson)) { // We do nothing. return; } // Cast our Json data to Key_Data. Key_Data data = JsonUtility.FromJson <Key_Data> (keyJson); // Load the values of the players currency. for (int i = 0; i < key.Length; i++) { key [i].currencyName = data.keyName [i]; key [i].currencyAmount = data.keyAmount [i]; } }
/// <summary> /// Save all the types of keys. /// </summary> public void Save() { // Create a new Key_Data. Key_Data data = new Key_Data(); // Setup the data to be saved. string[] currNames = new string[key.Length]; int[] currAmount = new int[key.Length]; // Loop through the keys. for (int i = 0; i < key.Length; i++) { // Set the name and the amount. currNames [i] = key [i].currencyName; currAmount [i] = key [i].currencyAmount; } // Save the data. data.keyName = currNames; data.keyAmount = currAmount; // Turn the Key_Data to Json data. string keyToJson = JsonUtility.ToJson(data); // Save the encrypted information. PlayerPrefs.SetString("Key", keyToJson); }