public void Save <T>(T dataToSave, string path, UnityAction <SaveResult, string> CompleteMethod, bool encrypted) where T : class, new()
        {
            byte[] bytes = BinarySerializationUtility.GetBytes(JsonUtility.ToJson(dataToSave));

            if (encrypted)
            {
                BinarySerializationUtility.EncryptData(ref bytes);
            }
            string serializedData = ConvertToString(bytes);

            PlayerPrefs.SetString(path, serializedData);
            if (CompleteMethod != null)
            {
                CompleteMethod(SaveResult.Success, "");
            }
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }