Esempio n. 1
0
        public static IEnumerator BeginDownload(string path, EndDownload endDownload, System.Object ud, UpdatePBar upb)
        {
            if (instance == null)
            {
                yield break;
            }

            yield return(instance.StartCoroutine(instance._BeginDownload(path, endDownload, ud, upb, 0)));
        }
Esempio n. 2
0
 private IEnumerator _BeginDownload(string path, EndDownload endDownload, System.Object ud, UpdatePBar upb, int index)
 {
     if (path == null || path == "")
     {
         yield break;
     }
     yield return(StartCoroutine(DoDownload(path, endDownload, ud, upb, index)));
 }
Esempio n. 3
0
        private IEnumerator DoDownload(string path, EndDownload endDownload, System.Object ud, UpdatePBar upb, int index)
        {
            using (UnityWebRequest www = UnityWebRequest.Get(path))
            {
                if (upb != null && updatePBarDic.ContainsKey(www))
                {
                    updatePBarDic.Remove(www);
                }
                updatePBarDic.Add(www, upb);

                yield return(www.Send());

                if (upb != null)
                {
                    upb(1);
                }

                updatePBarDic.Remove(www);

                if ((www.isNetworkError || www.isHttpError) && www.error.Length > 0)
                {
                    Debugger.LogError("Failed to download res: " + path + " Error: " + www.error);
                    www.Dispose();
                    if (index < 5)
                    {
                        StartCoroutine(instance._BeginDownload(path, endDownload, ud, upb, index++));
                    }
                    else
                    {
                        endDownload(www.url, null, ud);
                    }
                    yield break;
                }

                endDownload(www.url, www.downloadHandler.data, ud);
            }
        }