IEnumerator RequestCommentsCoro() { using (UnityWebRequest www = UnityWebRequest.Post(WebReq.serverUrl + "comment/showComment", new WWWForm())) { byte[] ReqJson = System.Text.Encoding.UTF8.GetBytes( JsonUtility.ToJson(new CommentsReqJson(DownloadKey)) ); www.uploadHandler = new UploadHandlerRaw(ReqJson); www.SetRequestHeader("Content-Type", "application/json"); if (WebReq.email != null) { www.SetRequestHeader("Authorization", WebReq.bearerToken); } yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { Debug.Log(www.downloadHandler.text); CommentsResJson res = JsonUtility.FromJson <CommentsResJson>(www.downloadHandler.text); CreateComments(res); } } }
void CreateComments(CommentsResJson res) { foreach (Transform transform in commentScrollContentTrans) { if (transform.GetComponent <Comment>() != null) { Destroy(transform.gameObject); } } foreach (CommentJson commentJson in res.comments) { GameObject comment = Instantiate(commentPrefab, commentScrollContentTrans); comment.GetComponent <Comment>().Init(commentJson); if (WebReq.isAdmin && WebReq.email != null) { comment.GetComponent <Comment>().EnableDelete(); } } }