public bool PostSaves() { if (FileUtility.CheckFile("user")) { // int i = 0; foreach (GameSave save in gameSaves) { string data = JsonUtility.ToJson(save); UnityWebRequest postSavesRequest = UnityWebRequest.Put(String.Format(CloudAPI.SaveUrl + "/{0}", save.id), data); postSavesRequest.SetRequestHeader("Authorization", "Bearer " + userData.access_token); postSavesRequest.SendWebRequest(); while (!postSavesRequest.isDone) { ; } // Handle request result if (postSavesRequest.isNetworkError || postSavesRequest.isHttpError) { Debug.Log("Error while making sign in request: " + postSavesRequest.error); } else { string fetchSavesResult = postSavesRequest.downloadHandler.text; CloudSaveResult result = JsonUtility.FromJson <CloudSaveResult>(fetchSavesResult); if (result.code) { Debug.Log(JsonUtility.ToJson(result.message)); int saveCount = CheckSaves(); for (int i = 0; i < result.message.Length; i++) { FileUtility.SaveFile(JsonUtility.ToJson(result.message[i]), String.Format("save_{0}", saveCount + i)); } return(true); } } } } return(false); }
public bool FetchSaves() { if (FileUtility.CheckFile("user")) { Debug.Log(userData.access_token); // Make request to sign in UnityWebRequest fetchSavesRequest = UnityWebRequest.Get(CloudAPI.SaveUrl); fetchSavesRequest.SetRequestHeader("Authorization", "Bearer " + userData.access_token); fetchSavesRequest.SendWebRequest(); while (!fetchSavesRequest.isDone) { ; } // Handle request result if (fetchSavesRequest.isNetworkError || fetchSavesRequest.isHttpError) { Debug.Log("Error while making sign in request: " + fetchSavesRequest.error); } else { string fetchSavesResult = fetchSavesRequest.downloadHandler.text; CloudSaveResult result = JsonUtility.FromJson <CloudSaveResult>(fetchSavesResult); if (result.code) { Debug.Log(JsonUtility.ToJson(result.message)); int saveCount = CheckSaves(); for (int i = 0; i < result.message.Length; i++) { FileUtility.SaveFile(JsonUtility.ToJson(result.message[i]), String.Format("save_{0}", saveCount + i)); } return(true); } } } return(false); }