local MAX_COUNT=5 local TASK_ID=1 local DownloaderHeadManager = { downCount=0, tasks={}, dowloadTasks={}, scheduleId=nil, }--class("DownloaderHeadManager") function DownloaderHeadManager.addTask(node,imageUrl, fileName, updateHeadImage) --如果在队列里面 还没开始下载 则更新数据就行 local isExist,oldTask=DownloaderHeadManager.isExitTask(node) if isExist then oldTask.imageUrl=imageUrl oldTask.fileName=fileName oldTask.updateHeadImage=updateHeadImage return end --如果已经开始下载 local isDownload,oldTask=DownloaderHeadManager.isExitDowloadTask(node) if isDownload then if oldTask.imageUrl==imageUrl then oldTask.updateHeadImage=updateHeadImage return end end local task={ node=node, imageUrl=imageUrl, fileName=fileName, updateHeadImage=updateHeadImage, id=TASK_ID, } dump(task,"DownloaderHeadManager.addTask") -- logD(" DownloaderHeadManager.addTask",tabletostring(task)) table.insert(DownloaderHeadManager.tasks,task) TASK_ID=TASK_ID+1 DownloaderHeadManager.update() -- if not DownloaderHeadManager.scheduleId then -- DownloaderHeadManager.scheduleId=cc.Director:getInstance():getScheduler():scheduleScriptFunc(DownloaderHeadManager.update , 0 , false) -- end end function DownloaderHeadManager.isExitTask(node) for k,v in pairs(DownloaderHeadManager.tasks) do if v.node==node then return true,v end end return false,nil end function DownloaderHeadManager.isExitDowloadTask(node) for k,v in pairs(DownloaderHeadManager.dowloadTasks) do if v.node==node then return true,v end end return false,nil end function DownloaderHeadManager.removeDownloadTask(task) for k,v in pairs(DownloaderHeadManager.dowloadTasks) do if v.id==task.id then table.remove(DownloaderHeadManager.dowloadTasks,k) return end end end function DownloaderHeadManager.update() logD("DownloaderHeadManager.update11111111111") if #DownloaderHeadManager.tasks>0 and DownloaderHeadManager.downCount