コード例 #1
0
    IEnumerator GetALLCards()
    {
        for (int i = 0; i < expansionNumbers.Length; i++)
        {
            WWWForm form = new WWWForm();
            form.AddField("expansion", expansionNumbers[i]);
            UnityWebRequest request = UnityWebRequest.Post(URLs.GET_CARDS, form);
            yield return(request.SendWebRequest());

            if (request.isNetworkError || request.isHttpError)
            {
                Debug.Log("Error: " + request.error);
            }
            else
            {
                Debug.Log("Cards Recieved");
                Debug.Log(request.downloadHandler.text);
                CardsData.LoadFromJson(request.downloadHandler.text);
                CardsData.expansion = expansionNumbers[i];

                for (int h = 0; h < CardsData.instance.cardsArray.Length; h++)
                {
                    CardData card = CardsData.instance.cardsArray[h];
                    request = UnityWebRequestTexture.GetTexture(card.front_image);
                    yield return(request.SendWebRequest());

                    if (request.isNetworkError || request.isHttpError)
                    {
                        Debug.Log(request.error);
                    }
                    else
                    {
                        if (request.downloadHandler.data != null)
                        {
                            CacheData(request.downloadHandler.data, GetCachedFileName(card));
                        }
                    }
                }
            }
        }
    }
コード例 #2
0
ファイル: CardDownloader.cs プロジェクト: poeticmatter/sinder
    public static IEnumerator GetCards(int expansionNumber, Action onFinish)
    {
        WWWForm form = new WWWForm();

        form.AddField("expansion", expansionNumber);
        UnityWebRequest request = UnityWebRequest.Post(URLs.GET_CARDS, form);

        yield return(request.SendWebRequest());

        if (request.isNetworkError || request.isHttpError)
        {
            Debug.Log("Error: " + request.error);
        }
        else
        {
            Debug.Log("Cards Recieved");
            CardsData.LoadFromJson(request.downloadHandler.text);
            CardsData.expansion = expansionNumber;
            onFinish?.Invoke();
        }
    }