Example #1
0
    public void deserialize()
    {
        var data     = System.IO.File.ReadAllText(Constants.Paths.SavedGamePath + @"\savedGame.json");
        var settings = new JsonSerializerSettings
        {
            TypeNameHandling = TypeNameHandling.Auto,
        };

        loadedModel = JsonConvert.DeserializeObject <SaveGameModel>(data, settings);
    }
Example #2
0
    public static void _Save(SaveGameModel gmModel, string fileName)
    {
        DateTime start = DateTime.Now;

        using (StreamWriter writer = new StreamWriter(Constants.Paths.SavedGamePath + fileName))
            using (JsonTextWriter jsonWriter = new JsonTextWriter(writer))
            {
                JsonSerializer ser = new JsonSerializer();
                ser.TypeNameHandling = TypeNameHandling.Auto;
                if (Debug.isDebugBuild)
                {
                    ser.Formatting = Formatting.Indented;
                }
                ser.Serialize(jsonWriter, gmModel);
                jsonWriter.Flush();
            }
        DateTime end = DateTime.Now;

        Debug.Log("wrote saved game" + " " + (end - start));
    }
Example #3
0
 public static void Save(SaveGameModel gmModel, string name)
 {
     _Save(gmModel, @"\" + name + @".json");
 }