Compare commits

...

2 Commits

Author SHA1 Message Date
hevinci 1d5663d93a update runtime code 2023-06-26 10:42:56 +08:00
hevinci b98d4cb091 update package system
离线模式支持内置资源解压到沙盒
2023-06-26 10:25:12 +08:00
6 changed files with 65 additions and 26 deletions

View File

@ -111,7 +111,7 @@ namespace YooAsset
if (_steps == ESteps.Unpack)
{
int failedTryAgain = Impl.DownloadFailedTryAgain;
var bundleInfo = ManifestTools.GetUnpackInfo(MainBundleInfo.Bundle);
var bundleInfo = ManifestTools.ConvertToUnpackInfo(MainBundleInfo.Bundle);
_unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
_steps = ESteps.CheckUnpack;
}

View File

@ -92,7 +92,7 @@ namespace YooAsset
if (_steps == ESteps.Unpack)
{
int failedTryAgain = Impl.DownloadFailedTryAgain;
var bundleInfo = ManifestTools.GetUnpackInfo(MainBundleInfo.Bundle);
var bundleInfo = ManifestTools.ConvertToUnpackInfo(MainBundleInfo.Bundle);
_unpacker = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
_steps = ESteps.CheckUnpack;
}

View File

@ -90,7 +90,7 @@ namespace YooAsset
if (_steps == ESteps.Website)
{
int failedTryAgain = Impl.DownloadFailedTryAgain;
var bundleInfo = ManifestTools.GetUnpackInfo(MainBundleInfo.Bundle);
var bundleInfo = ManifestTools.ConvertToUnpackInfo(MainBundleInfo.Bundle);
_website = DownloadSystem.BeginDownload(bundleInfo, failedTryAgain);
_steps = ESteps.CheckWebsite;
}

View File

@ -8,7 +8,6 @@ namespace YooAsset
{
internal static class ManifestTools
{
#if UNITY_EDITOR
/// <summary>
/// 序列化JSON文件
@ -188,14 +187,28 @@ namespace YooAsset
}
/// <summary>
/// 获取解压BundleInfo
/// 转换为解压BundleInfo
/// </summary>
public static BundleInfo GetUnpackInfo(PackageBundle packageBundle)
public static BundleInfo ConvertToUnpackInfo(PackageBundle packageBundle)
{
// 注意:我们把流加载路径指定为远端下载地址
string streamingPath = PersistentTools.ConvertToWWWPath(packageBundle.StreamingFilePath);
BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromStreaming, streamingPath, streamingPath);
return bundleInfo;
}
/// <summary>
/// 批量转换解压为BundleInfo
/// </summary>
public static List<BundleInfo> ConvertToUnpackInfos(List<PackageBundle> unpackList)
{
List<BundleInfo> result = new List<BundleInfo>(unpackList.Count);
foreach (var packageBundle in unpackList)
{
var bundleInfo = ConvertToUnpackInfo(packageBundle);
result.Add(bundleInfo);
}
return result;
}
}
}

View File

@ -50,22 +50,6 @@ namespace YooAsset
return bundleInfo;
}
// 解压相关
private List<BundleInfo> ConvertToUnpackList(List<PackageBundle> unpackList)
{
List<BundleInfo> result = new List<BundleInfo>(unpackList.Count);
foreach (var packageBundle in unpackList)
{
var bundleInfo = ConvertToUnpackInfo(packageBundle);
result.Add(bundleInfo);
}
return result;
}
private BundleInfo ConvertToUnpackInfo(PackageBundle packageBundle)
{
return ManifestTools.GetUnpackInfo(packageBundle);
}
#region IRemoteServices接口
public string GetRemoteMainURL(string fileName)
{
@ -256,7 +240,7 @@ namespace YooAsset
}
}
return ConvertToUnpackList(downloadList);
return ManifestTools.ConvertToUnpackInfos(downloadList);
}
ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
@ -284,7 +268,7 @@ namespace YooAsset
}
}
return ConvertToUnpackList(downloadList);
return ManifestTools.ConvertToUnpackInfos(downloadList);
}
#endregion

View File

@ -37,6 +37,11 @@ namespace YooAsset
{
}
private bool IsCachedPackageBundle(PackageBundle packageBundle)
{
return CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID);
}
UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
{
var operation = new OfflinePlayModeUpdatePackageVersionOperation();
@ -71,11 +76,48 @@ namespace YooAsset
ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
{
return ResourceUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> unpcakList = GetUnpackListByAll(_activeManifest);
var operation = new ResourceUnpackerOperation(unpcakList, upackingMaxNumber, failedTryAgain, timeout);
return operation;
}
private List<BundleInfo> GetUnpackListByAll(PackageManifest manifest)
{
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
foreach (var packageBundle in manifest.BundleList)
{
// 忽略缓存文件
if (IsCachedPackageBundle(packageBundle))
continue;
downloadList.Add(packageBundle);
}
return ManifestTools.ConvertToUnpackInfos(downloadList);
}
ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
{
return ResourceUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> unpcakList = GetUnpackListByTags(_activeManifest, tags);
var operation = new ResourceUnpackerOperation(unpcakList, upackingMaxNumber, failedTryAgain, timeout);
return operation;
}
private List<BundleInfo> GetUnpackListByTags(PackageManifest manifest, string[] tags)
{
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
foreach (var packageBundle in manifest.BundleList)
{
// 忽略缓存文件
if (IsCachedPackageBundle(packageBundle))
continue;
// 查询DLC资源
if (packageBundle.HasTag(tags))
{
downloadList.Add(packageBundle);
}
}
return ManifestTools.ConvertToUnpackInfos(downloadList);
}
#endregion