예제 #1
0
    private IEnumerator GetInfoPlayer()
    {
        //using (UnityWebRequest httpClient = new UnityWebRequest(player.HttpServerAddress + "/api/Player/GetPlayer/" + player.Id, "GET"))
        using (UnityWebRequest httpClient = new UnityWebRequest(playerManager.GetHttpServer() + "api/Player/GetPlayerInfo/" + playerManager.PlayerId, "GET"))
        {
            yield return(GetAuthenticationToken());

            httpClient.SetRequestHeader("Authorization", "bearer " + playerManager.Token);
            httpClient.SetRequestHeader("Accept", "application/json");

            httpClient.downloadHandler = new DownloadHandlerBuffer();

            yield return(httpClient.SendWebRequest());

            if (httpClient.isNetworkError || httpClient.isHttpError)
            {
                Debug.Log(playerManager.GetHttpServer() + "api/Player/GetPlayerInfo/" + playerManager.PlayerId);
                throw new System.Exception("GetInfoPlayer > Error: " + httpClient.responseCode + ", Info: " + httpClient.error);
            }
            else
            {
                string jsonResponse = httpClient.downloadHandler.text;
                Assets.Scripts.Models.Player playerJson = JsonUtility.FromJson <Assets.Scripts.Models.Player>(jsonResponse);

                Debug.Log("GetInfoPlayer > Info: " + playerJson.Email);
                playerManager.PlayerId = playerJson.Id;
                playerManager.Nickname = playerJson.Nickname;
                playerManager.Email    = playerJson.Email;
            }
        }
    }
예제 #2
0
    IEnumerator InsertPlayer()
    {
        if (string.IsNullOrEmpty(emailInputField.text))
        {
            throw new NullReferenceException("Email can't be void");
        }
        else if (string.IsNullOrEmpty(passwordInputField.text))
        {
            throw new NullReferenceException("Password can't be void");
        }
        else if (passwordInputField.text != confirmPasswordInputField.text)
        {
            throw new Exception("Passwords don't match");
        }

        Assets.Scripts.Models.Player newUser = new Assets.Scripts.Models.Player();
        newUser.Email    = emailInputField.text;
        newUser.Nickname = emailInputField.text;
        yield return(GetAspNetUserId());

        newUser.Id = playerManager.PlayerId;

        using (UnityWebRequest httpClient = new UnityWebRequest(playerManager.GetHttpServer() + "api/player/insertnewplayer", "POST"))
        {
            string bodyJson = JsonUtility.ToJson(newUser);

            byte[] bodyRaw = Encoding.UTF8.GetBytes(bodyJson);

            httpClient.uploadHandler = new UploadHandlerRaw(bodyRaw);

            yield return(GetAuthenticationToken());

            httpClient.SetRequestHeader("Content-type", "application/json");
            httpClient.SetRequestHeader("Authorization", "bearer " + playerManager.Token);

            yield return(httpClient.SendWebRequest());

            if (httpClient.isNetworkError || httpClient.isHttpError)
            {
                throw new System.Exception("Insertnewplayer > Error: " + httpClient.responseCode + ", Info: " + httpClient.error);
            }
            else
            {
                Debug.Log("RegistrarAspNetUser > Info: " + httpClient.responseCode);
            }
        }
    }