Example #1
0
    public override void UpdateContents()
    {
        ImageResult data = cellData as ImageResult;

        cellTransform.sizeDelta = new Vector2(data.tbWidth, data.tbHeight);

        PURawImage image = new PURawImage();

        image.color = Color.gray;
        image.SetFrame(0, 0, 0, 0, 0, 0, "stretch,stretch");
        image.LoadIntoPUGameObject(puGameObject);
        image.SetStretchStretch(2, 2, 2, 2);

        // Ensure we have our four downloader queues ready
        ImageDownloader downloader1 = scrollRect.gameObject.GetComponent <ImageDownloader> ();

        if (downloader1 == null)
        {
            downloader1 = scrollRect.gameObject.AddComponent <ImageDownloader> ();
        }
        ImageDownloader downloader2 = scrollRect.gameObject.GetComponent <ImageDownloader2> ();

        if (downloader2 == null)
        {
            downloader2 = scrollRect.gameObject.AddComponent <ImageDownloader2> ();
        }
        ImageDownloader downloader3 = scrollRect.gameObject.GetComponent <ImageDownloader3> ();

        if (downloader3 == null)
        {
            downloader3 = scrollRect.gameObject.AddComponent <ImageDownloader3> ();
        }
        ImageDownloader downloader4 = scrollRect.gameObject.GetComponent <ImageDownloader4> ();

        if (downloader4 == null)
        {
            downloader4 = scrollRect.gameObject.AddComponent <ImageDownloader4> ();
        }
        ImageDownloader downloader5 = scrollRect.gameObject.GetComponent <ImageDownloader4> ();

        if (downloader5 == null)
        {
            downloader5 = scrollRect.gameObject.AddComponent <ImageDownloader5> ();
        }

        // Find the downloader queue with the least items queued
        ImageDownloader minDownloader = downloader1;

        if (downloader2.Count < minDownloader.Count)
        {
            minDownloader = downloader2;
        }
        if (downloader3.Count < minDownloader.Count)
        {
            minDownloader = downloader3;
        }
        if (downloader4.Count < minDownloader.Count)
        {
            minDownloader = downloader4;
        }
        if (downloader5.Count < minDownloader.Count)
        {
            minDownloader = downloader5;
        }

        minDownloader.DownloadImageFromURL(data.tbUrl, image);
    }