コード例 #1
0
    protected IEnumerator _FetchPhotoList()
    {
        // sanity...
        if (this.isFetchingPhotoList)
        {
            yield break;
        }

        this.loading.gameObject.SetActive(true);
        this.noPhotos.gameObject.SetActive(false);
        this.photos.gameObject.SetActive(false);


        this.isFetchingPhotoList = true;

        var request = WebRequest.CreateApiGetRequest(Endpoints.Endpoint, Endpoints.Get.Images);

        yield return(request.SendWebRequest());

        this.loading.gameObject.SetActive(false);

        if (request.isNetworkError || request.isHttpError)
        {
            this.noPhotos.gameObject.SetActive(true);
            yield break;
        }

        var results = JsonConvert.DeserializeObject <PhotoResult>(request.downloadHandler.text);

        if (results == null || results.images == null || results.images.Length == 0)
        {
            this.noPhotos.gameObject.SetActive(true);

            yield break;
        }

        this.photos.LoadPhotos(results);
    }
コード例 #2
0
    public static UnityWebRequest CreateApiGetRequest(string url, int port, string action, object body = null)
    {
        string endpoint = string.Format("{0}:{1}", url, port);

        return(WebRequest.CreateApiGetRequest(endpoint, action, body));
    }