官方说明:提供下载文件的功能,支持断点续传,并可指定允许几个下载器进行同时下载。更新资源时会主动调用此模块。
DownloadComponent中可获取:下载代理总数、可用下载代理数量、工作中下载代理数量、等待下载任务数量、下载速度等,也可设置是否暂停、下载超时时长、断点续传临界大小
具体用法如下代码:
using System;
using UnityGameFramework.Runtime;
using GameFramework.Event;
using ProcedureOwner = GameFramework.Fsm.IFsm<GameFramework.Procedure.IProcedureManager>;
namespace StarForce
{
public class ProcedureDownLoad : ProcedureBase
{
public override bool UseNativeDialog => throw new NotImplementedException();
public override void OnEnter(ProcedureOwner procedureOwner)
{
base.OnEnter(procedureOwner);
GameEntry.Event.Subscribe(DownloadStartEventArgs.EventId, OnDownLoadStart);
GameEntry.Event.Subscribe(DownloadUpdateEventArgs.EventId, OnDownLoadUpdate);
GameEntry.Event.Subscribe(DownloadSuccessEventArgs.EventId, OnDownLoadSuccess);
GameEntry.Event.Subscribe(DownloadFailureEventArgs.EventId, OnDownLoadFailure);
string url = "https://c.xiaomai24h.com/u3d/2ddb350218588b04.webgl.data.unityweb.bin.txt";
GameEntry.Download.AddDownload(@"D:\bin.txt", url, this);
}
public override void OnLeave(ProcedureOwner procedureOwner, bool isShutdown)
{
base.OnLeave(procedureOwner, isShutdown);
GameEntry.Event.Unsubscribe(DownloadStartEventArgs.EventId, OnDownLoadStart);
GameEntry.Event.Unsubscribe(DownloadUpdateEventArgs.EventId, OnDownLoadUpdate);
GameEntry.Event.Unsubscribe(DownloadSuccessEventArgs.EventId, OnDownLoadSuccess);
GameEntry.Event.Unsubscribe(DownloadFailureEventArgs.EventId, OnDownLoadFailure);
}
private void OnDownLoadStart(object sender, GameEventArgs e)
{
DownloadStartEventArgs ne = (DownloadStartEventArgs)e;
if (ne.UserData != this) return;
Log.Error("开始下载:" + ne.DownloadUri);
}
private void OnDownLoadUpdate(object sender, GameEventArgs e)
{
DownloadUpdateEventArgs ne = (DownloadUpdateEventArgs)e;
if (ne.UserData != this) return;
Log.Error("下载更新01:" + ne.CurrentLength);
Log.Error("下载更新02:" + (GameEntry.Download.CurrentSpeed / 1024) + "kb/s");
}
private void OnDownLoadSuccess(object sender, GameEventArgs e)
{
DownloadSuccessEventArgs ne = (DownloadSuccessEventArgs)e;
if (ne.UserData != this) return;
Log.Error("下载成功:" + ne.DownloadPath);
}
private void OnDownLoadFailure(object sender, GameEventArgs e)
{
DownloadFailureEventArgs ne = (DownloadFailureEventArgs)e;
if (ne.UserData != this) return;
Log.Error("请求失败:" + ne.ErrorMessage);
}
}
}