示例#1
0
    public void OnEnable()
    {
        CheckDownloadedGames();
        List <GameObject> downloadArray = new List <GameObject>(GameObject.FindGameObjectsWithTag(ConstantClass.DOWNLOAD_OBJ_TAG));

        foreach (var item in downloadArray)
        {
            if (item.name == gameCode + ConstantClass.DOWNLOAD_OBJ_NAME)
            {
                downloadHolder = GetComponent <DownloadHolder>();
            }
        }
    }
示例#2
0
    public void CreateDownload()
    {
        GameObject downloadObj = new GameObject
        {
            name = gameCode + ConstantClass.DOWNLOAD_OBJ_NAME,
            tag  = ConstantClass.DOWNLOAD_OBJ_TAG
        };

        DownloadHolder holder = downloadObj.AddComponent <DownloadHolder>();

        downloadHolder = holder;

        StartCoroutine(holder.DownloadBundle(gameCode, bundleUrl));
    }
示例#3
0
 void UpdateProgressBar(int position, long progress)
 {
     queue[position].progress = (int)(progress * 100);
     DownloadQueue.instance?.RunOnUiThread(() =>
     {
         LinearLayoutManager LayoutManager = (LinearLayoutManager)DownloadQueue.instance?.ListView?.GetLayoutManager();
         if (LayoutManager != null && position >= LayoutManager.FindFirstVisibleItemPosition() && position <= LayoutManager.FindLastVisibleItemPosition())
         {
             View view                = DownloadQueue.instance.ListView.GetChildAt(position - LayoutManager.FindFirstVisibleItemPosition());
             DownloadHolder holder    = (DownloadHolder)DownloadQueue.instance.ListView.GetChildViewHolder(view);
             holder.Progress.Progress = (int)(progress * 100);
         }
     });
     if (queue.Count == 1)
     {
         SetNotificationProgress((int)(progress * 100));
     }
 }
示例#4
0
    /// <summary>
    /// Download an image from web
    /// </summary>
    /// <param name="url">http url, must start with http:// or https://</param>
    /// <param name="onComplete">callback when download complete</param>
    /// <param name="timeout">request timeout</param>
    /// <returns></returns>
    public static IEnumerator RequestImage(string url, Action <Texture2D, byte[]> onComplete = null, int timeout = 10)
    {
        var ourl = url;

        url = url.ToLower();

        var cache = m_cached.Find(c => c.url == url);

        if (cache != null)
        {
            onComplete?.Invoke(cache.texture, cache.data);
            yield break;
        }

        var n = m_downloadQueue.Find(d => d.url == url);

        if (n != null)
        {
            n.onComplete += onComplete;
            var wait = new WaitUntil(() => n.isDone);
            yield return(wait);
        }
        else
        {
            var request = UnityWebRequestTexture.GetTexture(url, true);
            request.timeout = timeout;

            n = DownloadHolder.Create(url, request, onComplete);
            m_downloadQueue.Add(n);

            yield return(request.SendWebRequest());

            m_downloadQueue.Remove(n);

            Texture2D t    = null;
            byte[]    data = null;

            if (request.isHttpError || request.isNetworkError)
            {
                Logger.LogError("UIDynamicImage::RequestImage: Failed to download image from [{0}], err: {1}", url, request.error);
            }
            else if (request.responseCode != 200)
            {
                Logger.LogError("UIDynamicImage::RequestImage: Failed to download image from [{0}], invalid response code: {1}", url, request.error);
            }
            else
            {
                t = DownloadHandlerTexture.GetContent(request);
                if (!t)
                {
                    Logger.LogError("UIDynamicImage::RequestImage: Failed to decode image data from [{0}], data length: [{1}]", url, request.downloadedBytes);
                }
                else
                {
                    t.name = ourl;
                    data   = request.downloadHandler.data;
                    Logger.LogInfo("UIDynamicImage::RequestImage: Download complete, url:[{0}]", ourl);
                }
            }

            n.onComplete?.Invoke(t, data);
            n.Destroy();
        }
    }