IEnumerator Upload() { //A. Save the results to data.json myData.UserFirstName = myFirstNameText.text; myData.UserLastName = myLastNameText.text; myData.Grade = int.Parse(myGradeText.text); myData.HeadSetNumber = myHeadsetNumberText.text; if (myPassingInformationToggle.isOn == true) { myData.PassorFail = true; } else { myData.PassorFail = false; } if (myCompletionInformationToggle.isOn == true) { myData.CompletedBefore = true; } else { myData.CompletedBefore = false; } String dataAsJson1 = JsonUtility.ToJson(myData); string filePath1; if ((Application.platform == RuntimePlatform.Android) && (devModeAnd)) { filePath1 = m_Path + Path.GetFullPath("data.json"); } else if (!devModeAnd) { filePath1 = pathA + "/data.json"; } else if (!devModeWin) { filePath1 = pathW + "/data.json"; } else { filePath1 = Application.dataPath + gameDataProjectFilePath; } File.WriteAllText(filePath1, dataAsJson1); //1. generate result from the data.json file. string filePath = ""; if ((Application.platform == RuntimePlatform.Android) && devModeAnd) { filePath = m_Path + Path.GetFullPath("data.json"); } else if (!devModeAnd) { filePath = pathA + "/data.json"; } else if (!devModeWin) { filePath = pathW + "/data.json"; } else if ((Application.platform == RuntimePlatform.WindowsPlayer) && devModeWin) { gameDataProjectFilePath = "/data.json"; filePath = Application.dataPath + gameDataProjectFilePath; } else if ((Application.platform == RuntimePlatform.WindowsEditor) && devModeWin) { gameDataProjectFilePath = "/EVR/data.json"; filePath = Application.dataPath + gameDataProjectFilePath; } string dataAsJson = File.ReadAllText(filePath); myDataPost = JsonUtility.FromJson <MyClassData>(dataAsJson); json = JsonUtility.ToJson(myDataPost); //2. generate json from class //myData = new MyClassData(); //json = JsonUtility.ToJson(myData); //3. generate data from received result after GET //json = JsonUtility.ToJson(myData); //creating a from with key value pair. WWWForm form = new WWWForm(); form.AddField("data", json); using (UnityWebRequest www = UnityWebRequest.Post(myPushEndpoint, form)) { yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { Debug.Log("Form upload complete!"); Debug.Log(www.downloadHandler.isDone.ToString()); } } }
IEnumerator GetRequest(string uri) { WebClient webClient = new WebClient(); webClient.DownloadFile("http://evr-demo.herokuapp.com/images/login.png", combine_path); //download the profile image Debug.Log("Profile pic image" + combine_path); WWW www = new WWW(Url); while (!www.isDone) { yield return(null); } GameObject image = GameObject.Find("RawImage"); image.GetComponent <RawImage>().texture = www.texture; //save image as a texture using (UnityWebRequest webRequest = UnityWebRequest.Get(uri)) { Debug.Log("GET END PT" + uri); yield return(webRequest.SendWebRequest()); // Request and wait for the desired page. string[] pages = uri.Split('/'); int page = pages.Length - 1; if (webRequest.isNetworkError) { Debug.Log(pages[page] + ": Error: " + webRequest.error); } else { string dataAsJson = webRequest.downloadHandler.text.ToString(); // Pass the json to JsonUtility, and tell it to create a GameData object from it myData = JsonUtility.FromJson <MyClassData>(dataAsJson); //1. print the results received from GET Debug.Log("Ticket: " + myData.ConfigId + " \nExperience Number: " + myData.ExperienceNumber + " \nHead Set Number: " + myData.HeadSetNumber + " \nUser First Name: " + myData.UserFirstName + " \nUser Last Name: " + myData.UserLastName + " \nPassed? " + myData.PassorFail + " \nGrade: " + myData.Grade + " \nPrevious Date: " + myData.DateLastAttempted + " \nIs it Completed Before: " + myData.CompletedBefore); //Updating the Text fields in UI myFirstNameText.text = myData.UserFirstName; myLastNameText.text = myData.UserLastName; myGradeText.text = myData.Grade.ToString(); myHeadsetNumberText.text = myData.HeadSetNumber; if (myData.PassorFail == true) { myPassingInformationToggle.isOn = true; } else { myPassingInformationToggle.isOn = false; } if (myData.CompletedBefore == true) { myCompletionInformationToggle.isOn = true; } else { myCompletionInformationToggle.isOn = false; } //2. Save the results to data.json dataAsJson = JsonUtility.ToJson(myData); string filePath; if ((Application.platform == RuntimePlatform.Android) && (devModeAnd)) { filePath = m_Path + Path.GetFullPath("data.json"); } else if (!devModeAnd) { filePath = pathA + "/data.json"; } else if ((Application.platform == RuntimePlatform.WindowsPlayer) && (devModeWin)) { gameDataProjectFilePath = "/data.json"; filePath = Application.dataPath + gameDataProjectFilePath; } else if ((Application.platform == RuntimePlatform.WindowsEditor) && (devModeWin)) { gameDataProjectFilePath = "/EVR/data.json"; filePath = Application.dataPath + gameDataProjectFilePath; } else { filePath = pathW + "/data.json"; } File.WriteAllText(filePath, dataAsJson); } } }