public void Load <T>(string path, UnityAction <T, SaveResult, string> LoadCompleteMethod, bool encrypted) where T : class, new()
        {
            loadStatus = String.Empty;
            byte[] bytes = ReadFromFile <T>(path);
            if (bytes != null)
            {
                if (encrypted)
                {
                    try
                    {
                        BinarySerializationUtility.DecryptData(ref bytes);
                    }
                    catch (Exception e)
                    {
                        loadStatus += "Decryption Error: " + e.Message;
                    }
                }
                T deserializedData = new T();
                try
                {
                    deserializedData = JsonUtility.FromJson <T>(BinarySerializationUtility.GetString(bytes));
                }
                catch (Exception e)
                {
                    loadStatus += "Deserialization Error: " + e.Message;
                }

                if (loadStatus == String.Empty)
                {
                    LoadCompleteMethod(deserializedData, SaveResult.Success, loadStatus);
                    return;
                }
            }
            LoadCompleteMethod(null, SaveResult.Error, loadStatus);
        }
 public void Load <T>(string path, UnityAction <T, SaveResult, string> LoadCompleteMethod, bool encrypted) where T : class, new()
 {
     byte[] bytes = ReadFromFile <T>(path);
     if (bytes != null)
     {
         if (encrypted)
         {
             BinarySerializationUtility.DecryptData(ref bytes);
         }
         LoadCompleteMethod(BinarySerializationUtility.DeserializeProperties <T>(bytes), SaveResult.Success, "");
         return;
     }
     LoadCompleteMethod(new T(), SaveResult.Success, "File Was Created");
 }
        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, "");
            }
        }
Example #4
0
        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);
                }
            }
        }