Exemplo n.º 1
0
    IEnumerator Download(string type, int level, string correct, System.Action <QuestionData> callback = null)
    {
        generating = true;
        string url;

        if (correct != null)
        {
            url = "https://webhooks.mongodb-realm.com/api/client/v2.0/app/covidwarrior-xhivn/service/CovidWarriorInfo/incoming_webhook/getQuestion?select_type=" + type + "&select_level=" + level + "&answered=" + correct;
        }
        else
        {
            url = "https://webhooks.mongodb-realm.com/api/client/v2.0/app/covidwarrior-xhivn/service/CovidWarriorInfo/incoming_webhook/getQuestion?select_type=" + type + "&select_level=" + level;
        }
        using (UnityWebRequest request = UnityWebRequest.Get(url))
        {
            yield return(request.SendWebRequest());

            if (request.isNetworkError || request.isHttpError)
            {
                Debug.Log(request.error);
                if (callback != null)
                {
                    callback.Invoke(null);
                }
            }
            else
            {
                if (request.downloadHandler.text == "null")
                {
                    callback.Invoke(null);
                }
                else if (callback != null)
                {
                    callback.Invoke(QuestionData.Parse(request.downloadHandler.text.Substring(1, request.downloadHandler.text.Length - 2)));
                }
            }
        }
        generating = false;
    }