//TERMINAR ESTO
    private IEnumerator GetPartidasJugadas()
    {
        using (UnityWebRequest httpClient = new UnityWebRequest(player.HttpServerAddress + "/api/game/gamelist/" + player.Id, "GET"))
        {
            httpClient.SetRequestHeader("Authorization", "bearer " + player.Token);
            httpClient.SetRequestHeader("Accept", "application/json");

            httpClient.downloadHandler = new DownloadHandlerBuffer();

            yield return(httpClient.SendWebRequest());

            if (httpClient.isNetworkError || httpClient.isHttpError)
            {
                throw new System.Exception("GetPartidasJugadas > Error: " + httpClient.responseCode + ", Info: " + httpClient.error);
            }
            else
            {
                string jsonResponse        = httpClient.downloadHandler.text;
                string response            = "{\"mylist\":" + jsonResponse + "}";
                ListGameSerializable lista = JsonUtility.FromJson <ListGameSerializable>(response);
                foreach (GameSerializable p in lista.mylist)
                {
                    partidas.GetComponent <Text>().text += $"Start: {p.Start}, End: {p.Final}, Difficulty: {p.Difficulty}, Points: {p.Points}\n";
                }
            }
        }
    }
Example #2
0
    private IEnumerator GetGames()
    {
        // Remove the oldest games
        if (content.transform.childCount != 0)
        {
            foreach (GameObject c in content.GetComponent <Transform>().GetComponentsInChildren <GameObject>())
            {
                // Remove game
                Destroy(c.gameObject);
            }
        }
        using (UnityWebRequest httpClient = new UnityWebRequest(player.HttpServer + "/api/Game/GetGames/" + player.Id, "GET"))
        {
            httpClient.SetRequestHeader("Authorization", "bearer " + player.Token);
            httpClient.SetRequestHeader("Accept", "application/json");

            httpClient.downloadHandler = new DownloadHandlerBuffer();

            yield return(httpClient.SendWebRequest());

            if (httpClient.isNetworkError || httpClient.isHttpError)
            {
                throw new System.Exception("GetInfoPlayer > Error: " + httpClient.responseCode + ", Info: " + httpClient.error);
            }
            else
            {
                string jsonResponse       = httpClient.downloadHandler.text;
                string response           = "{\"listOfGames\":" + jsonResponse + "}";
                ListGameSerializable list = JsonUtility.FromJson <ListGameSerializable>(response);

                foreach (GameSerializable gameSerializable in list.listOfGames)
                {
                    var newGame = Instantiate(gameInfo, Vector3.zero, Quaternion.identity) as GameObject;
                    newGame.transform.GetChild(0).GetComponent <Text>().text = "ID: " + gameSerializable.Id;
                    newGame.transform.GetChild(1).GetComponent <Text>().text = "Date Start: " + gameSerializable.DateStart;
                    newGame.transform.GetChild(2).GetComponent <Text>().text = "Date Stop: " + gameSerializable.DateStop;
                    newGame.transform.GetChild(3).GetComponent <Text>().text = "Difficulty: " + gameSerializable.Difficulty;
                    newGame.transform.GetChild(4).GetComponent <Text>().text = "Score: " + gameSerializable.Score;
                    newGame.transform.SetParent(content.transform);
                    newGame.SetActive(true);
                }
            }
        }
    }
    private IEnumerator GetPartidasJugadas()
    {
        using (UnityWebRequest httpClient = new UnityWebRequest(player.HttpServerAddress + "/api/Games/GetGames/" + player.Id, "GET"))
        {
            httpClient.SetRequestHeader("Authorization", "bearer " + player.Token);
            httpClient.SetRequestHeader("Accept", "application/json");

            httpClient.downloadHandler = new DownloadHandlerBuffer();

            yield return(httpClient.SendWebRequest());

            if (httpClient.isNetworkError || httpClient.isHttpError)
            {
                throw new System.Exception("GetPartidasJugadas > Error: " + httpClient.responseCode + ", Info: " + httpClient.error);
            }
            else
            {
                string jsonResponse        = httpClient.downloadHandler.text;
                string response            = "{\"miLista\":" + jsonResponse + "}";
                ListGameSerializable lista = JsonUtility.FromJson <ListGameSerializable>(response);


                foreach (GameSerializable p in lista.miLista)
                {
                    Text textoPartida = Instantiate(text, Vector3.zero, Quaternion.identity);

                    textoPartida.text                 = "Id Player: " + p.IdPlayer + " \n Inicio: " + p.Inicio + " \n Final: " + p.Final + " \n Dificultad: " + p.Difficulty + " \n Puntos: " + p.Points;
                    textoPartida.fontSize             = 30;
                    textoPartida.resizeTextForBestFit = true;
                    textoPartida.color                = Color.white;
                    textoPartida.alignment            = TextAnchor.MiddleCenter;

                    textoPartida.transform.SetParent(content.transform);
                }
            }
        }
    }