Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- public static class SaveProfile
- {
- public static void ProfileSave(ProfileData profile)
- {
- List<ProfileData> profileData = LoadProfiles(); //get the current profiles
- Debug.Log(profile.profileName + " " + profile.companyName + " " + profile.profileImage + " " + profile.profileID);
- profileData.Add(profile); //adds profile to the list
- BinaryFormatter formatter = new BinaryFormatter();
- string path = Application.persistentDataPath + "/Profiles/profiles.dat";
- FileStream stream = new FileStream(path, FileMode.Create);
- formatter.Serialize(stream, profileData); //saving the whole list
- stream.Close();
- }
- public static List<ProfileData> LoadProfiles()
- {
- if (File.Exists(Application.persistentDataPath + "/Profiles/profiles.dat"))
- {
- if(new FileInfo(Application.persistentDataPath + "/Profiles/profiles.dat").Length == 0)
- {
- return null;
- }
- else
- {
- BinaryFormatter formatter = new BinaryFormatter();
- FileStream stream = new FileStream(Application.persistentDataPath + "/Profiles/profiles.dat", FileMode.Open);
- List<ProfileData> profileData = (List<ProfileData>)formatter.Deserialize(stream);
- Debug.Log(profileData[0]);
- stream.Close();
- return new List<ProfileData>();
- }
- }
- else
- {
- Debug.LogError("Save file not found in " + Application.persistentDataPath + "/Profiles/profiles.dat");
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement