public void Save <T>(T dataToSave, string path, UnityAction <SaveResult, string> CompleteMethod, bool encrypted) where T : class, new() { byte[] bytes = BinarySerializationUtility.SerializeProperties(dataToSave); if (encrypted) { BinarySerializationUtility.EncryptData(ref bytes); } File.WriteAllBytes(path, bytes); if (CompleteMethod != null) { CompleteMethod(SaveResult.Success, ""); } }
public void Save <T>(T dataToSave, string path, UnityAction <SaveResult, string> CompleteMethod, bool encrypted) where T : class, new() { byte[] bytes = BinarySerializationUtility.SerializeProperties(dataToSave); if (this.encrypted) { BinarySerializationUtility.EncryptData(ref bytes); } string serializedData = ConvertToString(bytes); PlayerPrefs.SetString(path, serializedData); if (CompleteMethod != null) { CompleteMethod(SaveResult.Success, ""); } }
public void Save <T>(T dataToSave, string path, UnityAction <SaveResult, string> CompleteMethod, bool encrypted) where T : class, new() { byte[] bytes = null; saveStatus = String.Empty; try { bytes = BinarySerializationUtility.GetBytes(JsonUtility.ToJson(dataToSave)); } catch (Exception e) { saveStatus += "Serialization Error: " + e.Message; } if (encrypted) { try { BinarySerializationUtility.EncryptData(ref bytes); } catch (Exception e) { saveStatus += "Encryption Error: " + e.Message; } } try { File.WriteAllBytes(path, bytes); } catch (Exception e) { saveStatus += "File Write Error: " + e.Message; } if (CompleteMethod != null) { if (saveStatus == String.Empty) { CompleteMethod(SaveResult.Success, saveStatus); } else { CompleteMethod(SaveResult.Error, saveStatus); } } }