private static string Serialize(Settings settings) { string preferenceData; try { preferenceData = Json.JsonConvert.SerializeObject(settings); } catch (Exception) { Debug.LogWarning("Failed to serialize settings, your preferences have been reset."); preferenceData = ""; } return(preferenceData); }
private static Settings Deserialize(string data) { try { var settings = Json.JsonConvert.DeserializeObject <Settings>(data); if (settings == null) { throw new NullReferenceException(); } return(settings); } catch (Exception) { Debug.LogWarning("Failed to deserialize settings, your preferences have been reset."); var settings = new Settings(); Serialize(settings); return(settings); } }