コード例 #1
0
    private IEnumerator GetToken(string username, string password)
    {
        Debug.Log("GetToken called!");
        List <IMultipartFormSection> authenticationFormData = new List <IMultipartFormSection>();

        authenticationFormData.Add(new MultipartFormDataSection("email", username));
        authenticationFormData.Add(new MultipartFormDataSection("password", password));

        UnityWebRequest loginRequest = UnityWebRequest.Post(LOGIN_URL, authenticationFormData);

        yield return(StartCoroutine(RequestCoroutine(loginRequest)));

        Debug.Log("LoginRequest: " + loginRequest.downloadHandler.text);

        UnityWebRequest tokenRequest = UnityWebRequest.Post(API_LOGIN_URL, authenticationFormData);

        yield return(StartCoroutine(RequestCoroutine(tokenRequest)));

        Debug.Log("TokenRequest: " + tokenRequest.downloadHandler.text);



        token = JsonUtility.FromJson <Token>(tokenRequest.downloadHandler.text).token;

        if (loginRequest.result != UnityWebRequest.Result.Success)
        {
            MessageBox messageBox = MessageBoxHandler.boxHandler.DisplayMessage("Failed to get token!",
                                                                                new MessageBoxChoiceBehaviour("Try Again"),
                                                                                new MessageBoxChoiceBehaviour("Quit", () =>
            {
                Application.Quit(-1);
            })
                                                                                );
            yield return(messageBox.BlockUntilClicked());

            Debug.Log(messageBox.GetClickedOptionIndex());
            if (messageBox.GetClickedOptionIndex() == 0)
            {
                Debug.Log("Call GetToken again!");
                yield return(StartCoroutine(GetToken(username, password)));
            }
        }
        Debug.Log("End GetToken");
    }