- Home /
Question by
$$anonymous$$ · Jun 05, 2014 at 06:46 PM ·
androidiosserializationsavingwindows phone 8
Issue saving data accross multiple platforms
Hi, im creating a game that is intended to run on Windows Phone 8, Android and iOS. So far I have used a file storage method using binary serialization.
Below is my code for saving and loading:
public void Save()
{
//saves data out to a file.
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Create (Application.persistentDataPath + "/playerinfo.dat");
PlayerData data = new PlayerData ();
data._highscore = _highscore;
bf.Serialize (file, data);
file.Close ();
}
public void Load()
{
if(File.Exists (Application.persistentDataPath + "/playerinfo.dat"))
{
BinaryFormatter bf = new BinaryFormatter ();
FileStream file = File.Open (Application.persistentDataPath + "/playerinfo.dat", FileMode.Open);
PlayerData data = (PlayerData)bf.Deserialize (file);
file.Close ();
_highscore = data._highscore;
}
}
This seems to work fine on the PC but when I tried to export it to Windows phone 8, I got an error:
Error building Player: Exception: Error: type System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
doesn't exist in target framework. It is referenced from Assembly-CSharp.dll at System.Void dataManager::Save().
I looked into this and it seems that the serialisation function is not compatible with WP8, so my question is: How would I got about saving game data accross all of the platforms? Thanks for any help!
Comment