IEnumerator RequestProfileIconCoro(string email) { using (UnityWebRequest www = UnityWebRequest.Post(WebReq.serverUrl + "profile/viewAll", new WWWForm())) { byte[] ReqJson = System.Text.Encoding.UTF8.GetBytes(JsonUtility.ToJson(new ProfileReqJson(email))); www.uploadHandler = new UploadHandlerRaw(ReqJson); www.SetRequestHeader("Content-Type", "application/json"); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { ProfileResJson res = JsonUtility.FromJson <ProfileResJson>(www.downloadHandler.text); Sprite[] icons = new Sprite[spriteAtlas.spriteCount]; spriteAtlas.GetSprites(icons); iconButton.GetComponentInChildren <Image>().sprite = icons[res.icon]; iconButton.GetComponent <Button>().enabled = true; } } }
IEnumerator RequestProfileCoro(string email) { using (UnityWebRequest www = UnityWebRequest.Post(WebReq.serverUrl + "profile/viewAll", new WWWForm())) { byte[] ReqJson = System.Text.Encoding.UTF8.GetBytes(JsonUtility.ToJson(new ProfileReqJson(email))); www.uploadHandler = new UploadHandlerRaw(ReqJson); www.SetRequestHeader("Content-Type", "application/json"); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { Debug.Log(www.downloadHandler.text); ProfileResJson res = JsonUtility.FromJson <ProfileResJson>(www.downloadHandler.text); //change the icon, username and description DesText.GetComponentInChildren <Text>().text = res.description; usernameText.text = res.username; iconNumber = res.icon; IconButton.GetComponentInChildren <Image>().sprite = icons[res.icon]; } } }