Unity - Simple Image Downloader

a simple image downloader, it downloads images via a queue and by UnityWebRequest and Coroutine.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class ImageDownloader : MonoSingleton<ImageDownloader>
{
    private const int MAX_REQUEST = 10;

    public Action<UnityWebRequest, string> OnError;
<!-- more -->

    public Action<UnityWebRequest, Texture2D> OnDone;

    public struct TaskInfo
    {
        public string url;
        public Action<Texture2D> callback;
    }

    private Queue<TaskInfo> mQueue = new Queue<TaskInfo>();
    private int mCurrentCount = 0;

    public void GetOne(string url, Action<Texture2D> callback)
    {
        Enqueue(url, callback);
    }

    public void GetAll(List<string> urls, List<Action<Texture2D>> callbacks)
    {
        for (int i = 0; i < urls.Count; i++)
        {
            var callback = i < callbacks.Count ? callbacks[i] : null;

            Enqueue(urls[i], callback);
        }
    }

    void Enqueue(string url, Action<Texture2D> callback)
    {
        var taskInfo = new TaskInfo()
        {
            url = url,
            callback = callback
        };

        mQueue.Enqueue(taskInfo);
    }

    IEnumerator Dequeue()
    {
        if (mQueue.Count <= 0)
        {
            yield break;
        }

        
        var taskInfo = mQueue.Dequeue();
        Debug.Log("Start: " + taskInfo.url);
        using (UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(taskInfo.url))
        {
            mCurrentCount++;
            yield return uwr.SendWebRequest();

            if (uwr.isNetworkError || uwr.isHttpError)
            {
                Debug.Log(uwr.error);
                if (OnError != null)
                {
                    OnError(uwr, uwr.error);
                }
            }
            else
            {
                var texture = DownloadHandlerTexture.GetContent(uwr);

                if (taskInfo.callback != null)
                {
                    taskInfo.callback(texture);
                }

                if (OnDone != null)
                {
                    OnDone(uwr, texture);
                }
            }

            mCurrentCount--;
        }
    }


    private void Update()
    {
        if (mCurrentCount < MAX_REQUEST)
        {
            StartCoroutine(Dequeue());
        }
    }
}
WRITTEN BY:    Suntabu