Exemplo n.º 1
0
        public static Town LoadTown(string townID)
        {
            string loc = Application.persistentDataPath + "/" + townID + "/townData.soe";

            if (File.Exists(loc))
            {
                BinaryFormatter bf     = new BinaryFormatter();
                FileStream      stream = new FileStream(loc, FileMode.Open);
                TownData        T      = bf.Deserialize(stream) as TownData;
                stream.Close();
                return(new Town(T));
            }
            Debug.LogError("Error! Save file does not exist");
            return(null);
        }
Exemplo n.º 2
0
 public static void SaveTown(Town town)
 {
     try
     {
         BinaryFormatter formatter = new BinaryFormatter();
         string          loc       = Application.persistentDataPath + "/" + town.ID + "/townData.soe";
         FileStream      stream    = new FileStream(loc, FileMode.Create);
         TownData        T         = new TownData(town);
         formatter.Serialize(stream, T);
         stream.Close();
     }
     catch (Exception e)
     {
         Debug.Log("An error occurred while trying to serialize an object");
     }
 }