/// <summary> /// Loads the save data for a specific profile number. /// This will eventually be called from a button. /// </summary> /// <param name="profileNumber">0 is the temporary profile</param> public void LoadSaveData(int profileNumber = 0) { if (isDataLoaded && profileNumber == currentlyLoadedProfileNumber) { return; } // Automatically load the first available profile. if (profileNumber <= 0) { //if no profile specified reload the actual profile (this is the case when the scene is changed) if (currentlyLoadedProfileNumber <= 0) { SaveDatas = ScriptableObject.CreateInstance <SaveData>(); SaveDatas.Reset(); } else { SaveDatas = SaveData.ReadFromFile(GetSaveDataFilePath(currentlyLoadedProfileNumber)); } // We iterate through the possible profile numbers in case one with a lower number // no longer exists. //for (int i = 1; i <= MAX_NUMBER_OF_PROFILES; i++) { // if (File.Exists(GetSaveDataFilePath(i))) { // // Once the file is found, load it from the calculated file name. // SaveData = SaveData.ReadFromFile(GetSaveDataFilePath(i)); // // And set the current profile number for later use when we save. // currentlyLoadedProfileNumber = i; // break; // }} } else { // If the profileNumber parameter is supplied then we'll look to see if that exists. if (File.Exists(GetSaveDataFilePath(profileNumber))) { // If the file exists then load the SaveData from the calculated file name. SaveDatas = SaveData.ReadFromFile(GetSaveDataFilePath(profileNumber)); } else { // Otherwise just return a new SaveDatas = ScriptableObject.CreateInstance <SaveData>(); SaveDatas.Reset(); } WriteSaveData(0); //copy values to temporary profile currentlyLoadedProfileNumber = profileNumber; // And set the current profile number for later use when we save. } }