GameFramework下载器Download

类图

#mermaid-svg-nH5p8Mj8QxrZ3boL {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-nH5p8Mj8QxrZ3boL .error-icon{fill:#552222;}#mermaid-svg-nH5p8Mj8QxrZ3boL .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-nH5p8Mj8QxrZ3boL .edge-thickness-normal{stroke-width:2px;}#mermaid-svg-nH5p8Mj8QxrZ3boL .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-nH5p8Mj8QxrZ3boL .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-nH5p8Mj8QxrZ3boL .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-nH5p8Mj8QxrZ3boL .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-nH5p8Mj8QxrZ3boL .marker{fill:#333333;stroke:#333333;}#mermaid-svg-nH5p8Mj8QxrZ3boL .marker.cross{stroke:#333333;}#mermaid-svg-nH5p8Mj8QxrZ3boL svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-nH5p8Mj8QxrZ3boL g.classGroup text{fill:#9370DB;fill:#131300;stroke:none;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:10px;}#mermaid-svg-nH5p8Mj8QxrZ3boL g.classGroup text .title{font-weight:bolder;}#mermaid-svg-nH5p8Mj8QxrZ3boL .nodeLabel,#mermaid-svg-nH5p8Mj8QxrZ3boL .edgeLabel{color:#131300;}#mermaid-svg-nH5p8Mj8QxrZ3boL .edgeLabel .label rect{fill:#ECECFF;}#mermaid-svg-nH5p8Mj8QxrZ3boL .label text{fill:#131300;}#mermaid-svg-nH5p8Mj8QxrZ3boL .edgeLabel .label span{background:#ECECFF;}#mermaid-svg-nH5p8Mj8QxrZ3boL .classTitle{font-weight:bolder;}#mermaid-svg-nH5p8Mj8QxrZ3boL .node rect,#mermaid-svg-nH5p8Mj8QxrZ3boL .node circle,#mermaid-svg-nH5p8Mj8QxrZ3boL .node ellipse,#mermaid-svg-nH5p8Mj8QxrZ3boL .node polygon,#mermaid-svg-nH5p8Mj8QxrZ3boL .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-nH5p8Mj8QxrZ3boL .divider{stroke:#9370DB;stroke:1;}#mermaid-svg-nH5p8Mj8QxrZ3boL g.clickable{cursor:pointer;}#mermaid-svg-nH5p8Mj8QxrZ3boL g.classGroup rect{fill:#ECECFF;stroke:#9370DB;}#mermaid-svg-nH5p8Mj8QxrZ3boL g.classGroup line{stroke:#9370DB;stroke-width:1;}#mermaid-svg-nH5p8Mj8QxrZ3boL .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5;}#mermaid-svg-nH5p8Mj8QxrZ3boL .classLabel .label{fill:#9370DB;font-size:10px;}#mermaid-svg-nH5p8Mj8QxrZ3boL .relation{stroke:#333333;stroke-width:1;fill:none;}#mermaid-svg-nH5p8Mj8QxrZ3boL .dashed-line{stroke-dasharray:3;}#mermaid-svg-nH5p8Mj8QxrZ3boL #compositionStart,#mermaid-svg-nH5p8Mj8QxrZ3boL .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-nH5p8Mj8QxrZ3boL #compositionEnd,#mermaid-svg-nH5p8Mj8QxrZ3boL .composition{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-nH5p8Mj8QxrZ3boL #dependencyStart,#mermaid-svg-nH5p8Mj8QxrZ3boL .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-nH5p8Mj8QxrZ3boL #dependencyStart,#mermaid-svg-nH5p8Mj8QxrZ3boL .dependency{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-nH5p8Mj8QxrZ3boL #extensionStart,#mermaid-svg-nH5p8Mj8QxrZ3boL .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-nH5p8Mj8QxrZ3boL #extensionEnd,#mermaid-svg-nH5p8Mj8QxrZ3boL .extension{fill:#333333!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-nH5p8Mj8QxrZ3boL #aggregationStart,#mermaid-svg-nH5p8Mj8QxrZ3boL .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-nH5p8Mj8QxrZ3boL #aggregationEnd,#mermaid-svg-nH5p8Mj8QxrZ3boL .aggregation{fill:#ECECFF!important;stroke:#333333!important;stroke-width:1;}#mermaid-svg-nH5p8Mj8QxrZ3boL .edgeTerminals{font-size:11px;}#mermaid-svg-nH5p8Mj8QxrZ3boL :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;}

DownloadComponent
入口
DownloadManager
下载管理器
TaskPool<DownloadTask>
下载任务池,对任务进行调度
一开始会初始化固定数量的任务执行器
DownloadTask
下载任务,封装任务数据
ITaskAgent<DownloadTask>
下载任务执行器接口
用来执行 DownloadTask
DownloadAgent
下载任务执行器
用来执行 DownloadTask
把执行功能委托给 DownloadAgentHelperBase
DownloadAgentHelperBase
下载器基类
UnityWebRequestDownloadAgentHelper
UnityWebRequest实现的下载器
具体功能委托给 UnityWebRequest
YourDownloadAgentHelper
有需要可以实现你自己的下载器

使用

先在 DownloadComponent 中配置:

  • Download Agent Helper Count 下载器数量
    public class TestDownload{static int s_downloadId;public static void Test(){Game.Event.Subscribe(DownloadStartEventArgs.EventId, OnDownloadStart);Game.Event.Subscribe(DownloadUpdateEventArgs.EventId, OnDownloadUpdate);Game.Event.Subscribe(DownloadSuccessEventArgs.EventId, OnDownloadSuccess);Game.Event.Subscribe(DownloadFailureEventArgs.EventId, OnDownloadFailure);DownloadComponent downloadComponent = GameEntry.GetComponent<DownloadComponent>();s_downloadId = downloadComponent.AddDownload(Path.Combine(Application.persistentDataPath,"1.txt"), "http://myname.com/data/1.txt", userData: "mydown");  //  userData 可以关联你自己的数据}private static void OnDownloadSuccess(object sender, GameEventArgs e){//  下载成功DownloadSuccessEventArgs args = (DownloadSuccessEventArgs)e;//  有2种方式判断这个下载是不是你要的下载//  1. GameFramework内置方式,通过 SerialId 判断if ( args.SerialId != s_downloadId )return ;//  2. 你在用户数据中传递一个唯一的索引进行判断if ( !(args.UserData is string name && name == "mydown") )return ;}private static void OnDownloadFailure(object sender, GameEventArgs e){DownloadFailureEventArgs args = (DownloadFailureEventArgs)e;//  判断是否你的下载,同 OnDownloadSuccessDebug.Log(args.ErrorMessage);}private static void OnDownloadStart(object sender, GameEventArgs e){DownloadStartEventArgs args = (DownloadStartEventArgs)e;}private static void OnDownloadUpdate(object sender, GameEventArgs e){DownloadUpdateEventArgs args = (DownloadUpdateEventArgs)e;//  一般用来更新进度条,可是 args 只提供 CurrentLength 表示当前大小,没有总大小}}

流程分析

DownloadManager 管理下载,往 TaskPool<DownloadTask> 中添加下载任务 DownloadTask
TaskPool<DownloadTask> 负责找到空闲的下载器 DownloadAgent 来下载 DownloadTask
DownloadAgent 把具体的下载任务委托给  DownloadAgentHelperBase 去下载
UnityWebRequestDownloadAgentHelper 是 DownloadAgentHelperBase 的一个默认实现,把下载任务委托给 UnityWebRequest

下载代码分析

    //  初始化下载器DownlaodComponent.Start(){for (int i = 0; i < m_DownloadAgentHelperCount; i++){AddDownloadAgentHelper(i){//  这里创建的是 UnityWebRequestDownloadAgentHelperDownloadAgentHelperBase downloadAgentHelper = Helper.CreateHelper(m_DownloadAgentHelperTypeName, m_CustomDownloadAgentHelper, index);m_DownloadManager.AddDownloadAgentHelper(downloadAgentHelper)   //  DownloadManager.AddDownloadAgentHelper{DownloadAgent agent = new DownloadAgent(downloadAgentHelper);agent.DownloadAgentStart += OnDownloadAgentStart;agent.DownloadAgentUpdate += OnDownloadAgentUpdate;agent.DownloadAgentSuccess += OnDownloadAgentSuccess;agent.DownloadAgentFailure += OnDownloadAgentFailure;m_TaskPool.AddAgent(agent){agent.Initialize();m_FreeAgents.Push(agent);   //  加入空闲队列中}}}}}//  添加下载任务DownlaodComponent.AddDownload(string downloadPath, string downloadUri){return m_DownloadManager.AddDownload(downloadPath, downloadUri, tag, priority, userData)    //  DownloadManager.AddDownload{DownloadTask downloadTask = DownloadTask.Create(downloadPath, downloadUri, tag, priority, m_FlushSize, m_Timeout, userData);m_TaskPool.AddTask(downloadTask)    //  TaskPool<DownloadTask>.AddTask{m_WaitingTasks.AddAfter(current, task);     //  任务加入等待队列}return downloadTask.SerialId;}}//  执行下载任务DownloadManager.Update(float elapseSeconds, float realElapseSeconds){m_TaskPool.Update(elapseSeconds, realElapseSeconds)     //  TaskPool<DownloadTask>.Update{ProcessRunningTasks(elapseSeconds, realElapseSeconds){DownloadAgent taskAgent = m_WorkingAgents.First;taskAgent.Update(elapseSeconds, realElapseSeconds){//   判断正在下载的任务是否超时}}ProcessWaitingTasks(elapseSeconds, realElapseSeconds)   //  TaskPool<DownloadTask>.ProcessWaitingTasks{LinkedListNode<DownloadTask> current = m_WaitingTasks.First;    //  从等待列表中取出第1个任务DownloadTask task = current.Value; ITaskAgent<DownloadTask> agent = m_FreeAgents.Pop();            //  获得空闲下载任务执行器LinkedListNode<ITaskAgent<DownloadTask>> agentNode = m_WorkingAgents.AddLast(agent);    //  加入执行器列表中StartTaskStatus status = agent.Start(task); //  用执行器下载任务}}}

5.下载器-Download相关推荐

  1. Internet Download Manager2023稳定版下载器

    Internet Download Manager(简称IDM) 是Windows平台老牌而功能强大的下载工具,一种将下载速度提高多达5倍.那如果想要使用这款软件,那就需要安装这款软件,如何正确的下载 ...

  2. idm下载器(Internet Download Manager)

    idm下载器(Internet Download Manager) 1. 下载 到官网https://www.internetdownloadmanager.com/上下载即可 2. 安装 下载之后, ...

  3. persepolis download manager中文版(pdm下载器)

    如今,迅雷已经大不如前了,多了许多的广告弹窗不说,还关停了远程下载功能,并且很多资源还因为版权无法下载,使用体验非常不好.所以小编此次带来了一款能够替代迅雷的不限速的免费下载神器:pdm下载器,英文全 ...

  4. Internet Download Manager6.41加速器最快的电脑工具下载器

    IDM下载器,全称是Internet Download Manager,中文是互联网下载管理器可以说是最好用下载速度最快的下载器,可以利用全部带宽多线程下载,让你的下载速度起飞! 提到下载工具,大多数 ...

  5. IDM(Internet Download Manager)下载器使用

    作者需要下载国外网站上的一个深度学习数据集,总大小超过300GB.使用Chrome浏览器能够下载但是速度极慢,且浏览器必须始终打开不能退出,一旦退出就需要重新开始.而将下载链接复制到迅雷进行下载时,总 ...

  6. 一款性能比IDM(Internet Download Manager)下载器强大,且免费的下载器NDM(Neat Download Manager)

    1.最近发现一款新的免费下载器NDM,性能优于IDM,大家可以尝试用一下,下载链接如下: Neat Download Manager for Mac and Windows (Free Interne ...

  7. IDM(Internet Download Manager)最新一款 功能最全/电脑必备的下载器激活序列号版

    近些年移动互联网兴起,人手一部智能手机.人们花在PC上的时间越来越短,关注手机的时间越来越长. 4G.5G移动网络和云服务的飞速发展,网速越来越快,人们更愿意在线刷剧,在线存储.很多资源再也不需要存在 ...

  8. SkyDrive Easy Download (SkyDrive 批量下载器)

                             SkyDrive Easy Download (SkyDrive 批量下载器)                                     ...

  9. internet download manager(IDM下载器) 6.40

    软件下载 internet download manager(IDM下载器)是一款很不错的下载工具.有了internet download manager软件,可以提高你下载文件的速度,如果您在下载文 ...

最新文章

  1. 华为自研编程语言「仓颉」火上热搜,已正式开启内测,成员辟谣:不是中文编程...
  2. jQuery遇到问题的小记
  3. net-snmp交叉编译出现 undefined reference to dlopen,dlsym,dlclose错误
  4. 算法解读--递归(二)
  5. Apache-Guacamole windows11 远程控制
  6. string和wstring相互转换
  7. MyBatis学习总结(2)——使用MyBatis对表执行CRUD操作
  8. sqlserver的存储过程
  9. Linux---高级IO
  10. 如何枚举String类型的枚举?
  11. Contains的使用,一点经验
  12. LaTeX 在线编辑器(LaTeX online editors)
  13. matplotlib:plot 3d ,plot_surface
  14. Fedora 10安装Compiz-fusion 3D效果方法
  15. 如何停用计算机服务,如何彻底禁用电脑中的迅雷服务XLservicePlatform
  16. 失物招领系统软件测试,失物招领系统(原创)
  17. [TVB]百余部经典剧集海报
  18. 元宇宙赛道火热已是共识!上市公司正加码布局,基础设施支撑待完善
  19. 牛客客似云来(大数算法)
  20. 指纹识别键盘软件测试,防水键盘指纹识别_笔记本评测-中关村在线

热门文章

  1. c++ value categories
  2. object mapping for [details] tried to parse field [details] as object, but found concrete value
  3. 进入BeOS的花花世界 系列三
  4. Linux操作系统~什么是虚拟地址?深度剖析进程地址空间
  5. C#中DataGridView移除选中行
  6. php创建多级栏目_PHP 实现无限极栏目分类
  7. 2021移动端图片点击放大,插件swiper使用
  8. SQLiteOpenHelper 崩溃Couldnt read row 0, col -1 from CursorWindow.
  9. 研究google搜索框代码
  10. 机制检验、异质性检验、调节效应