Beispiel #1
0
    public IEnumerator GetImage(GoogleMapPath path, int index, Action <ActionResults> action)
    {
        //Debug.Log("act=" + threadId + " BEGIN");

        var image = new Texture2D(GMapManager.Size, GMapManager.Size);

        ReqAnswer req = null;

        StartCoroutine(_remoteManager.GetUrl(GMapManager.GetUrl(path), true, x => req = x));
        while (req == null)
        {
            yield return(null);
        }

        if (req.Exception == null)
        {
            image.LoadImage(req.Response.Bytes);
        }
        action(new ActionResults(image, index));
    }
Beispiel #2
0
    private IEnumerator Process(IList <string> paths, Action <bool> worked)
    {
        if (GMapManager.BaseTexture == null)
        {
            StartCoroutine(GetImage(null, 0, x => GMapManager.BaseTexture = x.Texture));
            while (GMapManager.BaseTexture == null)
            {
                yield return(null);
            }
        }

        var outTexture = Instantiate(GMapManager.BaseTexture);
        var points     = new List <Point>();

        if (paths != null)
        {
            var pathTextures = new Texture2D[paths.Count];
            //for (var i = 0; i < paths.Count; i++) pathTextures[i] = null;

            for (var i = 0; i < paths.Count; i++)
            {
                StartCoroutine(GetImage(GMapManager.GetPathFromString(paths[i]), i, x => { pathTextures[x.Index] = x.Texture; }));
                if (i % 9 == 0)
                {
                    yield return(new WaitForSeconds(1f));          //не более 9 потоков за сек
                }
            }
            while (pathTextures.Any(p => p == null))
            {
                yield return(null);
            }

            //Debug.Log("all data recieved");

            for (var i = 0; i < paths.Count; i++)
            {
                for (var w = 0; w <= GMapManager.Size; w++)
                {
                    for (var h = 0; h <= GMapManager.Size; h++)
                    {
                        if (GMapManager.BaseTexture.GetPixel(w, h) != pathTextures[i].GetPixel(w, h))
                        {
                            //if (points.Count < 10000)
                            if (!points.Contains(new Point {
                                X = w, Y = h
                            }))
                            {
                                points.Add(new Point {
                                    X = w, Y = h
                                });
                            }
                        }
                    }
                }
            }
        }
        //Debug.Log("points=" + points.Count);
        foreach (var p in points)
        {
            outTexture.SetPixel(p.X, p.Y, Color.red);
        }
        outTexture.Apply();

        ApplyTexture(outTexture);

        worked(true);
        //Debug.Log("process END");
    }