YooAsset/Docs/YooAssetUpdater.md

114 lines
2.4 KiB
Markdown
Raw Normal View History

2022-03-03 18:08:32 +08:00
# 资源更新
**更新补丁清单**
对于联机运行模式,在初始化资源系统之后,需要立刻更新资源清单。
在此之前需要获取更新的资源版本号一般通过HTTP访问游戏服务器来获取。
````c#
private IEnumerator UpdatePatchManifest()
{
2022-03-03 18:40:58 +08:00
int updateResourceVersion = 123;
int timeout = 30;
2022-03-03 18:08:32 +08:00
UpdateManifestOperation operation = YooAssets.UpdateManifestAsync(updateResourceVersion, timeout);
2022-03-03 18:40:58 +08:00
yield return operation;
if (operation.Status == EOperationStatus.Succeed)
2022-03-03 18:08:32 +08:00
{
//更新成功
}
else
{
2022-03-03 18:40:58 +08:00
//更新失败
2022-03-03 18:08:32 +08:00
Debug.LogError(operation.Error);
}
}
````
**补丁包下载**
在补丁清单更新完毕后,就可以更新资源文件了。
根据产品需求,可以选择更新全部资源,或者只更新部分资源。
````c#
private PatchDownloader _downloader;
/// <summary>
/// 创建下载器
/// </summary>
private void CreateDownloader()
{
string[] tags = { "buildin", "config" };
2022-03-03 18:40:58 +08:00
int downloadingMaxNum = 10;
int failedTryAgain = 3;
_downloader = YooAssets.CreateDLCDownloader(tags, 10, 3);
if (_downloader.TotalDownloadCount == 0)
{
//没有需要下载的资源
}
else
{
//需要下载的文件总数和总大小
int totalDownloadCount = _downloader.TotalDownloadCount;
2022-03-03 18:08:32 +08:00
long totalDownloadBytes = _downloader.TotalDownloadBytes;
2022-03-03 18:40:58 +08:00
}
2022-03-03 18:08:32 +08:00
}
/// <summary>
/// 更新下载器
/// </summary>
private void UpdateDownloader()
{
2022-03-03 18:40:58 +08:00
if (_downloader != null)
_downloader.Update();
2022-03-03 18:08:32 +08:00
}
/// <summary>
/// 开启下载
/// </summary>
private IEnumerator Download()
{
//注册下载回调
_downloader.OnPatchFileDownloadFailedCallback = OnPatchFileDownloadFailed;
_downloader.OnDownloadProgressCallback = OnDownloadProgressUpdate;
2022-03-03 18:40:58 +08:00
_downloader.OnDownloadOverCallback = OnDownloadOver;
2022-03-03 18:08:32 +08:00
_downloader.Download();
yield return _downloader;
//检测下载结果
if (_downloader.DownloadStates == EDownloaderStates.Succeed)
2022-03-03 18:40:58 +08:00
{
//下载成功
}
else
{
//下载失败
}
2022-03-03 18:08:32 +08:00
}
/// <summary>
/// 文件下载失败
/// </summary>
private void OnPatchFileDownloadFailed(string fileName)
{
2022-03-03 18:40:58 +08:00
Debug.LogError($"File download failed : {fileName}");
2022-03-03 18:08:32 +08:00
}
/// <summary>
/// 下载进度的更新
/// </summary>
private void OnDownloadProgressUpdate(int totalDownloadCount, int currentDownloadCount, long totalDownloadSizeBytes, long currentDownloadSizeBytes)
{
}
/// <summary>
/// 下载结束,成功或失败
/// </summary>
private void OnDownloadOver(bool isSucceed)
{
}
````