コード例 #1
0
        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);
        }
コード例 #2
0
        public void Load <T>(string path, UnityAction <T, SaveResult, string> LoadCompleteMethod, bool encrypted) where T : class, new()
        {
            byte[] bytes = ReadFromPlayerPrefs <T>(path);

            if (bytes != null)
            {
                if (encrypted)
                {
                    BinarySerializationUtility.DecryptData(ref bytes);
                }
                LoadCompleteMethod(JsonUtility.FromJson <T>(BinarySerializationUtility.GetString(bytes)), SaveResult.Success, "");
                return;
            }
            LoadCompleteMethod(new T(), SaveResult.Success, "File Was Created");
        }