public void WriteFile(GameState state) { GameState newState = state.GetClone(); newState.UpdateTimeStampUTC(); this.AddGameState(newState); string json = this.ToJson(); if (encryptSave) { json = SaveFile.Encrypt(json); } string path = string.Format("{0}/{1}.{2}", Application.persistentDataPath, SaveFile.fileName, SaveFile.fileExtension); try { File.WriteAllText(path, json); StringBuilder sb = new StringBuilder(); sb.AppendLine(string.Format("[PROFILE] Successfully saved profile (path: {0}).", path)); Debug.Log(sb.ToString()); } catch (Exception ex) { Debug.LogErrorFormat("[PROFILE] Unable to save GamSave (path: {0}), {1}", path, ex.ToString()); } }
public string ToJson(bool encrypt = false) { string json = JsonUtility.ToJson(this, true); if (encrypt) { json = SaveFile.Encrypt(json); } return(json); }