コード例 #1
0
    public static IEnumerator AsyncFetch(int x, int y, Counter counter = null)
    {
        var www = new WWW(string.Format(API_URL, x, y));

        yield return(www);

        var response = JsonConvert.DeserializeObject <ParcelPublicationsResponse>(www.text);

        var index = DclMap.CoordinatesToIndex(x, y);

        if (DclMap.ParcelInfos[index] == null)
        {
            DclMap.ParcelInfos[index] = new ParcelInfo(index);
        }
        DclMap.ParcelInfos[index].SoldPublications.Clear();

        for (int i = 0; i < response.data.Count; i++)
        {
            var publication = response.data[i];
            if (publication.status == "sold")
            {
                DclMap.ParcelInfos[index].SoldPublications.Add(publication);
            }
        }

        DclMap.ParcelInfos[index].LastFetchPublicationsTime = Time.realtimeSinceStartup;
        if (counter != null)
        {
            counter.responseCount++;
        }
    }
コード例 #2
0
    public static IEnumerator AsyncFetch(int n, int w, int s, int e, Counter counter)
    {
        var www = new WWW(string.Format(API_URL + "?nw={0},{1}&se={2},{3}", w, n, e, s));

        yield return(www);

//        Debug.Log(counter.responseCount + "|"+ www.text);
        if (counter != null)
        {
            counter.responseCount++;
        }
        if (www.error == null)
        {
            var mapResponse = JsonConvert.DeserializeObject <MapResponse>(www.text);

            for (int i = 0; i < mapResponse.data.assets.parcels.Count; i++)
            {
                var parcel = mapResponse.data.assets.parcels[i];

                var index = DclMap.CoordinatesToIndex(parcel.x, parcel.y);
                DclMap.ParcelInfos[index].Update(parcel);
            }
        }
        else
        {
            Debug.LogError(www.error);
        }
    }
コード例 #3
0
    public bool IsRoadside()
    {
        list.Clear();
        if (x > -150)
        {
            list.Add(new Coordinates(x - 1, y));
        }
        if (y < 150)
        {
            list.Add(new Coordinates(x, y + 1));
        }
        if (x < 150)
        {
            list.Add(new Coordinates(x + 1, y));
        }
        if (y > -150)
        {
            list.Add(new Coordinates(x, y - 1));
        }
        foreach (var coord in list)
        {
            var ind = DclMap.CoordinatesToIndex(coord);
            if (DclMap.IsRoad[ind])
            {
                return(true);
            }
        }

        return(false);
    }
コード例 #4
0
    public static IEnumerator AsyncFetch(int x, int y)
    {
        var www = new WWW(string.Format(API_URL + "/{0}/{1}", x, y));

        yield return(www);

        var response = JsonConvert.DeserializeObject <SingleParcelResponse>(www.text);

        var parcel = response.data;

        var index = DclMap.CoordinatesToIndex(parcel.x, parcel.y);

        DclMap.ParcelInfos[index].Update(parcel);
    }
コード例 #5
0
    static IEnumerator AsyncFetchOpen(int limit, int offset)
    {
        var www = new WWW(string.Format(API_URL + "?status=open&limit={0}&offset={1}", limit, offset));

        yield return(www);

        var response = JsonConvert.DeserializeObject <ParcelsResponse>(www.text);

        for (int i = 0; i < response.data.parcels.Count; i++)
        {
            var parcel = response.data.parcels[i];

            var index = DclMap.CoordinatesToIndex(parcel.x, parcel.y);
            DclMap.ParcelInfos[index].Update(parcel);
        }
    }
コード例 #6
0
    static IEnumerator AsyncFetchOpen(int limit, int offset)
    {
        var www = new WWW(string.Format(API_URL + "?status=open&limit={0}&offset={1}", limit, offset));

        yield return(www);

//        Debug.Log(www.text);

        var response = JsonConvert.DeserializeObject <EstatesResponse>(www.text);

        for (int i = 0; i < response.data.estates.Count; i++)
        {
            var estate = response.data.estates[i];

            EstateInfo estateInfo;
            var        findInd = DclMap.EstateInfos.FindIndex(e => e.Estate.id == estate.id);
            if (findInd >= 0)
            {
                estateInfo = DclMap.EstateInfos[findInd];
                estateInfo.Update(estate);
            }
            else
            {
                estateInfo = new EstateInfo(estate);
                DclMap.EstateInfos.Add(estateInfo);
            }

            var data    = estate.data;
            var parcels = data.parcels;
            for (int j = 0; j < parcels.Count; j++)
            {
                var coord = parcels[j];
                var index = DclMap.CoordinatesToIndex(coord.x, coord.y);
                DclMap.ParcelInfos[index].Update(estateInfo);
            }
        }
    }