Pigeon shit

[ Pigeon shit ] Unity data persistence – serialization

After looking at the found options I decided to go with serialization and if feasible google play services. This because serialization basically supports everything and is easy to implement. You just have to make sure all the data that you want to save has the serialize tag like so:

[System.Serializable]
public class GameData { 
//all data goes here
//
}

And then you can save the data with a function like this:

using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

public void Save(GameData data){
   BinaryFormatter bf = new BinaryFormatter();
   FileStream file = File.Create(Application.persistentDataPath + “/gamedata.gd”);
   bf.Serialize(file, data);
   file.Close();
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>