IEnumerator GetGroups(string url, GameObject buttonPrefab, GroupButtonCallback callback, GameObject panel) { WWWForm form = new WWWForm(); form.AddField("userID", roomID); UnityWebRequest www = UnityWebRequest.Post(url, form); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); } else { string response = www.downloadHandler.text; Debug.Log("zz data : " + response); GroupsData groupsData = JsonUtility.FromJson <GroupsData>(response); foreach (GroupData group in groupsData.data) { GameObject newButton = Instantiate(buttonPrefab) as GameObject; newButton.transform.GetChild(1).GetChild(1).GetComponent <TMPro.TextMeshProUGUI>().text = group.name; newButton.GetComponent <Button>().onClick.AddListener(() => { callback(group.name, group.code, group); }); // add this trigger start to friend buttons though // newButton.GetComponent<FriendTrackingScript>().TriggerStart(); // do this because once in parent it will not run newButton.transform.SetParent(panel.transform); newButton.transform.localScale = new Vector3(1, 1, 1); } yield return(response); } }
IEnumerator JoinGroupRequest(string groupCode, GameObject panel, GameObject buttonPrefab, GroupButtonCallback callback) { WWWForm form = new WWWForm(); form.AddField("userID", roomID); form.AddField("code", groupCode); UnityWebRequest www = UnityWebRequest.Post("https://circles-parellano.herokuapp.com/api/join-group-world", form); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { Debug.Log(www.error); uiManagerScript.ResultGroupJoin(false); } else { string response = www.downloadHandler.text; Debug.Log("zz resp " + response); GroupData group = JsonUtility.FromJson <GroupData>(response); if (group.name == null) { Debug.Log("zz error "); uiManagerScript.ResultGroupJoin(false); } else { GameObject newButton = Instantiate(buttonPrefab) as GameObject; newButton.transform.GetChild(1).GetChild(1).GetComponent <TMPro.TextMeshProUGUI>().text = group.name; newButton.GetComponent <Button>().onClick.AddListener(() => { callback(group.name, group.code, group); }); newButton.transform.SetParent(panel.transform); newButton.transform.localScale = new Vector3(1, 1, 1); uiManagerScript.ResultGroupJoin(true); foreach (GroupMember member in group.members) { if (username != member.world_user.user.username) { SendNotificationAndCoins(member.world_user.user.username); } } } yield return(response); } }