Update patch system

pull/4/head
hevinci 2022-03-07 20:13:39 +08:00
parent 51aeb8b563
commit 050c962587
3 changed files with 107 additions and 2 deletions

View File

@ -15,9 +15,9 @@ namespace YooAsset
private const int MAX_LOADER_COUNT = 64;
public delegate void OnDownloadOver(bool isSucceed);
public delegate void OnDownloadProgress(int totalDownloadCount, int currentDownloadCoun, long totalDownloadBytes, long currentDownloadBytes);
public delegate void OnDownloadProgress(int totalDownloadCount, int currentDownloadCount, long totalDownloadBytes, long currentDownloadBytes);
public delegate void OnDownloadFileFailed(string fileName);
private readonly int _fileLoadingMaxNumber;
private readonly int _failedTryAgain;
private readonly List<AssetBundleInfo> _downloadList;

View File

@ -155,6 +155,47 @@ namespace YooAsset
return ConvertToDownloadList(downloadList);
}
/// <summary>
/// 创建解压器
/// </summary>
public DownloaderOperation CreateUnpackerByTags(string[] tags, int fileUpackingMaxNumber, int failedTryAgain)
{
List<AssetBundleInfo> unpcakList = GetUnpackListByTags(tags);
var operation = new DownloaderOperation(unpcakList, fileUpackingMaxNumber, failedTryAgain);
return operation;
}
private List<AssetBundleInfo> GetUnpackListByTags(string[] tags)
{
List<PatchBundle> downloadList = new List<PatchBundle>(1000);
foreach (var patchBundle in AppPatchManifest.BundleList)
{
// 如果已经在沙盒内
string filePath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
if (System.IO.File.Exists(filePath))
continue;
// 如果不是内置资源
if (patchBundle.IsBuildin == false)
continue;
// 如果是纯内置资源
if (patchBundle.IsPureBuildin())
{
downloadList.Add(patchBundle);
}
else
{
// 查询DLC资源
if (patchBundle.HasTag(tags))
{
downloadList.Add(patchBundle);
}
}
}
return ConvertToUnpackList(downloadList);
}
// WEB相关
internal string GetPatchDownloadMainURL(int resourceVersion, string fileName)
{
@ -192,6 +233,25 @@ namespace YooAsset
return result;
}
// 解压相关
private AssetBundleInfo ConvertToUnpackInfo(PatchBundle patchBundle)
{
string sandboxPath = PatchHelper.MakeSandboxCacheFilePath(patchBundle.Hash);
string streamingLoadPath = AssetPathHelper.MakeStreamingLoadPath(patchBundle.Hash);
AssetBundleInfo bundleInfo = new AssetBundleInfo(patchBundle, sandboxPath, streamingLoadPath, streamingLoadPath);
return bundleInfo;
}
private List<AssetBundleInfo> ConvertToUnpackList(List<PatchBundle> unpackList)
{
List<AssetBundleInfo> result = new List<AssetBundleInfo>(unpackList.Count);
foreach (var patchBundle in unpackList)
{
var bundleInfo = ConvertToUnpackInfo(patchBundle);
result.Add(bundleInfo);
}
return result;
}
#region IBundleServices接口
AssetBundleInfo IBundleServices.GetAssetBundleInfo(string bundleName)
{

View File

@ -455,6 +455,51 @@ namespace YooAsset
}
#endregion
#region 资源解压接口
/// <summary>
/// 创建补丁解压器
/// </summary>
/// <param name="tag">资源标签</param>
/// <param name="unpackingMaxNumber">同时解压的最大文件数</param>
/// <param name="failedTryAgain">解压失败的重试次数</param>
public static DownloaderOperation CreatePatchUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain)
{
return CreatePatchUnpacker(new string[] { tag }, unpackingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建补丁解压器
/// </summary>
/// <param name="tags">资源标签列表</param>
/// <param name="unpackingMaxNumber">同时解压的最大文件数</param>
/// <param name="failedTryAgain">解压失败的重试次数</param>
public static DownloaderOperation CreatePatchUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain)
{
if (_playMode == EPlayMode.EditorPlayMode)
{
List<AssetBundleInfo> downloadList = new List<AssetBundleInfo>();
var operation = new DownloaderOperation(downloadList, unpackingMaxNumber, failedTryAgain);
return operation;
}
else if (_playMode == EPlayMode.OfflinePlayMode)
{
List<AssetBundleInfo> downloadList = new List<AssetBundleInfo>();
var operation = new DownloaderOperation(downloadList, unpackingMaxNumber, failedTryAgain);
return operation;
}
else if (_playMode == EPlayMode.HostPlayMode)
{
if (_hostPlayModeImpl == null)
throw new Exception("YooAsset is not initialized.");
return _hostPlayModeImpl.CreateUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain);
}
else
{
throw new NotImplementedException();
}
}
#endregion
#region 沙盒相关
/// <summary>
/// 清空沙盒目录