Exemplo n.º 1
0
    private IEnumerator LoadIconAsync(IconDownloadTask task, bool queued = true)
    {
        for (int i = 0; i < task.BaseUrls.Length; i++)
        {
            using (UnityWebRequest www = UnityWebRequestTexture.GetTexture(task.BaseUrls[i] + task.RelativeUrl))
            {
                //www.timeout = 13;
                yield return(www.Send());

                if (!www.isNetworkError && www.responseCode == 200L)
                {
                    if (task.IsCanceled)
                    {
                        Texture2D content = DownloadHandlerTexture.GetContent(www);
                        if (content != null && content.width > 10 && content.height > 10)
                        {
                            task.FallbackCancelation(content);
                        }
                    }
                    else
                    {
                        Texture2D content2 = DownloadHandlerTexture.GetContent(www);
                        if (content2 != null && content2.width > 10 && content2.height > 10)
                        {
                            content2.wrapMode = TextureWrapMode.Clamp;
                            task.Result(true, content2);
                        }
                        else
                        {
                            task.Result(false, null);
                        }
                        this.SendConnectionResume();
                    }
                    yield return(0);

                    this.currentIconConnections--;
                    yield break;
                }
                FMLogger.Log(string.Concat(new object[]
                {
                    "icon dl error.",
                    i,
                    ". ",
                    task.BaseUrls[i],
                    string.Empty,
                    task.RelativeUrl,
                    " msg:",
                    www.error
                }));
            }
        }
        this.currentIconConnections--;
        this.StepFailedPicture();
        if (!task.IsCanceled)
        {
            FMLogger.Log("*************error task:" + task.RelativeUrl);
            task.Result(false, null);
        }
        yield break;
    }
Exemplo n.º 2
0
        public void LoadWeb(IconDownloadTask task)
        {
            string     cacheKey        = task.CacheKey;
            CacheImage cacheImageByKey = this.GetCacheImageByKey(cacheKey);

            if (cacheImageByKey != null)
            {
                cacheImageByKey.AddRef(1);
                task.Result(true, cacheImageByKey.Tex);
            }
            else
            {
                WebCImageTask webCacheTaskByKey = this.GetWebCacheTaskByKey(cacheKey);
                if (webCacheTaskByKey != null)
                {
                    webCacheTaskByKey.JoinHandler(task);
                }
                else
                {
                    WebCImageTask cacheTask = new WebCImageTask(task, cacheKey);
                    this.webTasks.Add(cacheTask);
                    cacheTask.Complete += delegate(CacheImage image)
                    {
                        if (image != null)
                        {
                            this.cached.Add(image);
                        }
                        this.webTasks.Remove(cacheTask);
                    };
                    cacheTask.Run(this.localRunner);
                }
            }
        }