예제 #1
0
 public void OnComplete(WWWTask task, bool iscomplete)
 {
     Debug.Log("Task complete->" + task.url);
     TaskList.Remove(task.url);
     taskDic.Remove(task.url);
     NextTask();
 }
예제 #2
0
    public void NextTask()
    {
        if (TaskQueue.Count <= 0)
        {
            return;
        }
        WWWTask task = taskDic[TaskQueue.Dequeue()];

        task.StartTask();
    }
예제 #3
0
    private Dictionary <string, WWWTask> taskDic; //下载记录

    public WWWTask NewTask(string url, byte[] postData, Action <WWWTask, bool> callback)
    {
        callback += OnComplete;
        WWWTask task = gameObject.AddComponent <WWWTask>();

        task.SetTask(url, postData, callback);
        if (TaskList.Count > m_maxTasks)
        {
            TaskQueue.Enqueue(url);
            taskDic.Add(url, task);
        }
        else
        {
            TaskList.Add(url);
            taskDic.Add(url, task);
            task.StartTask();
        }

        return(task);
    }
예제 #4
0
    /// <summary>
    /// Add task.
    /// </summary>
    /// <param name="taskToAdd">Task to add.</param>
    public void AddTask(WWWTask taskToAdd)
    {
        if (taskToAdd != null)
        {
            if (_tasks == null)
            {
                _tasks = new Dictionary <string, WWWTask>();
            }

            _tasks.Add(taskToAdd.TaskId, taskToAdd);

            _taskAdded = true;

            taskToAdd.OnTaskAdded();
        }
        else
        {
            Debug.LogError(gameObject.name + " pass in task is null");
        }
    }
예제 #5
0
        // Use this for initialization
        public override void Start()
        {
            base.Start();

            LocalTask serviceTask = new LocalTask("ConfigFile", "Config/ConfigJson");

            serviceTask.OnComplete += OnConfigComplete;
            serviceTask.OnError    += HandleOnError;
            m_taskManager.AddTask(serviceTask);

            WWWTask wwwTask = new WWWTask("LogoImage", Config.LOGO_IMAGE_AT_LOCAL_DISK, true, null);

            wwwTask.OnComplete += OnLogoImageCompleted;
            wwwTask.OnError    += HandleOnErrorImage;
            m_taskManager.AddTask(wwwTask);

            m_taskManager.OnCompleteAllTasks += OnTaskCompleted;
            m_taskManager.StartTaskManager();

            ActiveScene("InitScene");
        }
예제 #6
0
    private void Update()
    {
        lock (task_list)
        {
            if (queue.Count > 0)
            {
                task_list.Add(new WWWTask(queue.Dequeue()));
                nowprogress = 0;
            }
            if (task_list.Count > 0)
            {
                List <WWWTask> Finished = new List <WWWTask>();
                for (int i = 0; i < task_list.Count; i++)
                {
                    WWWTask w = task_list[i];
                    if (w.www.isDone)
                    {
                        Finished.Add(w);
                        w.task.callback(w.www, w.task.udata);
                        w.www.Dispose();
                        DownLoadOkCount++;
                    }
                    else
                    {
                        w.task.progress = w.www.progress;
                        nowprogress     = w.www.progress;
                    }
                }

                foreach (WWWTask task in Finished)
                {
                    task_list.Remove(task);
                }
            }
        }
    }