Exemple #1
0
    IEnumerator RequestWeb(string url, WWWForm forms, float timeOut, string loadingFeedback, OnRequestEnd onRequestEnd, bool inBackground = false)
    {
        UnityWebRequest webRequest            = UnityWebRequest.Post(url, forms);
        UnityWebRequestAsyncOperation handler = webRequest.SendWebRequest();

        float timeIn = 0f;

        if (!inBackground)
        {
            LoadingScreen.ActiveLoading(loadingFeedback);
        }
        while (!handler.isDone)
        {
            timeIn += Time.deltaTime;
            if (timeIn > timeOut)
            {
                //Security
                webRequest.Abort();
                if (!inBackground)
                {
                    LoadingScreen.ActiveLoading("TIME OUT");
                }
                yield return(new WaitForSeconds(2f));

                break;
            }
            yield return(null);
        }

        //FakeDelay
        float minTime = 1f;

        if (!inBackground && timeIn < minTime)
        {
            yield return(new WaitForSeconds(minTime - timeIn));
        }

        if (webRequest.isNetworkError || webRequest.isHttpError)
        {
            Debug.Log(webRequest.error);
            if (!inBackground)
            {
                LoadingScreen.ActiveLoading(webRequest.error, false, 1f);
            }
        }
        else
        {
            if (!inBackground)
            {
                LoadingScreen.StopLoading();
            }
            //Call end
            string      content = webRequest.downloadHandler.text;
            JsonRequest request = JsonUtility.FromJson <JsonRequest>(content);
            onRequestEnd(request);
        }

        yield break;
    }
Exemple #2
0
 public void OnRequestCreateAccountEnd(JsonRequest requested)
 {
     if (requested.success == "true")
     {
         LoadingScreen.ActiveLoading("New Account Created", false, 1f, new LoadingScreen.OnDurationStop(ActiveMenuConnection));
     }
     else
     {
         inpNewPlayerPassword.DisplayError(requested.error);
     }
 }