Example #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;
    }
Example #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);
                }
            }
        }
Example #3
0
 public void JoinHandler(IconDownloadTask task)
 {
     if (this.joined == null)
     {
         this.joined = new List <IconDownloadTask>();
     }
     this.joined.Add(task);
 }
Example #4
0
 public void DownloadIcon(IconDownloadTask task)
 {
     if (this.iconRequestQueue.Find((IconDownloadTask t) => t.RelativeUrl.Equals(task.RelativeUrl)) == null)
     {
         this.iconRequestQueue.Add(task);
     }
     else
     {
         UnityEngine.Debug.LogError("*******task duplicate");
     }
 }
Example #5
0
 private void UpdateIconConnectionsQueue()
 {
     for (int i = this.iconRequestQueue.Count - 1; i >= 0; i--)
     {
         if (this.iconRequestQueue[i] == null || this.iconRequestQueue[i].IsCanceled)
         {
             this.iconRequestQueue.RemoveAt(i);
         }
     }
     if (this.iconRequestQueue.Count > 0 && this.currentIconConnections < 4)
     {
         IconDownloadTask task = this.iconRequestQueue[0];
         base.StartCoroutine(this.LoadIconAsync(task, true));
         this.currentIconConnections++;
         this.iconRequestQueue.RemoveAt(0);
     }
 }
Example #6
0
 public void DownloadIcon(IconDownloadTask task)
 {
     this.cacher.LoadWeb(task);
 }
Example #7
0
 public WebCImageTask(IconDownloadTask task, string cacheKey) : base(cacheKey)
 {
     this.initial = task;
 }