yoo2.2,9
This commit is contained in:
Alex-Rachel
2025-01-25 13:46:17 +08:00
parent 634a392a1f
commit 6166fd24c6
584 changed files with 15684 additions and 11714 deletions

View File

@@ -6,25 +6,9 @@ namespace YooAsset
{
internal class WebPlayModeImpl : IPlayMode, IBundleQuery
{
private PackageManifest _activeManifest;
private ResourceAssist _assist;
private IBuildinQueryServices _buildinQueryServices;
private IRemoteServices _remoteServices;
private IWechatQueryServices _wechatQueryServices;
public readonly string PackageName;
public DownloadManager Download
{
get { return _assist.Download; }
}
public PersistentManager Persistent
{
get { return _assist.Persistent; }
}
public IRemoteServices RemoteServices
{
get { return _remoteServices; }
}
public IFileSystem WebServerFileSystem { set; get; } //可以为空!
public IFileSystem WebRemoteFileSystem { set; get; } //可以为空!
public WebPlayModeImpl(string packageName)
@@ -35,77 +19,54 @@ namespace YooAsset
/// <summary>
/// 异步初始化
/// </summary>
public InitializationOperation InitializeAsync(ResourceAssist assist, IBuildinQueryServices buildinQueryServices, IRemoteServices remoteServices, IWechatQueryServices wechatQueryServices)
public InitializationOperation InitializeAsync(WebPlayModeParameters initParameters)
{
_assist = assist;
_buildinQueryServices = buildinQueryServices;
_remoteServices = remoteServices;
_wechatQueryServices = wechatQueryServices;
var operation = new WebPlayModeInitializationOperation(this);
var operation = new WebPlayModeInitializationOperation(this, initParameters);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
// 下载相关
private BundleInfo ConvertToDownloadInfo(PackageBundle packageBundle)
{
string remoteMainURL = _remoteServices.GetRemoteMainURL(packageBundle.FileName);
string remoteFallbackURL = _remoteServices.GetRemoteFallbackURL(packageBundle.FileName);
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromRemote, remoteMainURL, remoteFallbackURL);
return bundleInfo;
}
private List<BundleInfo> ConvertToDownloadList(List<PackageBundle> downloadList)
{
List<BundleInfo> result = new List<BundleInfo>(downloadList.Count);
foreach (var packageBundle in downloadList)
{
var bundleInfo = ConvertToDownloadInfo(packageBundle);
result.Add(bundleInfo);
}
return result;
}
// 查询相关
private bool IsCachedPackageBundle(PackageBundle packageBundle)
{
if (_wechatQueryServices != null)
return _wechatQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
else
return false;
}
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
{
return _buildinQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
}
#region IPlayMode接口
public PackageManifest ActiveManifest
{
set
{
_activeManifest = value;
}
get
{
return _activeManifest;
}
}
public void FlushManifestVersionFile()
public PackageManifest ActiveManifest { set; get; }
void IPlayMode.UpdatePlayMode()
{
if (WebServerFileSystem != null)
WebServerFileSystem.OnUpdate();
if (WebRemoteFileSystem != null)
WebRemoteFileSystem.OnUpdate();
}
UpdatePackageVersionOperation IPlayMode.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
{
var operation = new WebPlayModeUpdatePackageVersionOperation(this, appendTimeTicks, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
if (WebRemoteFileSystem != null)
{
var operation = new RequestPackageVersionImplOperation(WebRemoteFileSystem, appendTimeTicks, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
else
{
var operation = new RequestPackageVersionImplOperation(WebServerFileSystem, appendTimeTicks, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
}
UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion, int timeout)
UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, int timeout)
{
var operation = new WebPlayModeUpdatePackageManifestOperation(this, packageVersion, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
if (WebRemoteFileSystem != null)
{
var operation = new UpdatePackageManifestImplOperation(this, WebRemoteFileSystem, packageVersion, timeout); ;
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
else
{
var operation = new UpdatePackageManifestImplOperation(this, WebServerFileSystem, packageVersion, timeout); ;
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
}
PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout)
{
@@ -113,148 +74,70 @@ namespace YooAsset
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(string clearMode, object clearParam)
{
var operation = new ClearCacheFilesImplOperation(this, WebServerFileSystem, WebRemoteFileSystem, null, clearMode, clearParam);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = GetDownloadListByAll(_activeManifest);
var operation = new ResourceDownloaderOperation(Download, PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByAll(ActiveManifest, WebServerFileSystem, WebRemoteFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
public List<BundleInfo> GetDownloadListByAll(PackageManifest manifest)
{
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
foreach (var packageBundle in manifest.BundleList)
{
// 忽略缓存文件
if (IsCachedPackageBundle(packageBundle))
continue;
// 忽略APP资源
if (IsBuildinPackageBundle(packageBundle))
continue;
downloadList.Add(packageBundle);
}
return ConvertToDownloadList(downloadList);
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = GetDownloadListByTags(_activeManifest, tags);
var operation = new ResourceDownloaderOperation(Download, PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByTags(ActiveManifest, tags, WebServerFileSystem, WebRemoteFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
public List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags)
{
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
foreach (var packageBundle in manifest.BundleList)
{
// 忽略缓存文件
if (IsCachedPackageBundle(packageBundle))
continue;
// 忽略APP资源
if (IsBuildinPackageBundle(packageBundle))
continue;
// 如果未带任何标记,则统一下载
if (packageBundle.HasAnyTags() == false)
{
downloadList.Add(packageBundle);
}
else
{
// 查询DLC资源
if (packageBundle.HasTag(tags))
{
downloadList.Add(packageBundle);
}
}
}
return ConvertToDownloadList(downloadList);
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = GetDownloadListByPaths(_activeManifest, assetInfos);
var operation = new ResourceDownloaderOperation(Download, PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByPaths(ActiveManifest, assetInfos, WebServerFileSystem, WebRemoteFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
public List<BundleInfo> GetDownloadListByPaths(PackageManifest manifest, AssetInfo[] assetInfos)
{
// 获取资源对象的资源包和所有依赖资源包
List<PackageBundle> checkList = new List<PackageBundle>();
foreach (var assetInfo in assetInfos)
{
if (assetInfo.IsInvalid)
{
YooLogger.Warning(assetInfo.Error);
continue;
}
// 注意:如果清单里未找到资源包会抛出异常!
PackageBundle mainBundle = manifest.GetMainPackageBundle(assetInfo.AssetPath);
if (checkList.Contains(mainBundle) == false)
checkList.Add(mainBundle);
// 注意:如果清单里未找到资源包会抛出异常!
PackageBundle[] dependBundles = manifest.GetAllDependencies(assetInfo.AssetPath);
foreach (var dependBundle in dependBundles)
{
if (checkList.Contains(dependBundle) == false)
checkList.Add(dependBundle);
}
}
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
foreach (var packageBundle in checkList)
{
// 忽略缓存文件
if (IsCachedPackageBundle(packageBundle))
continue;
// 忽略APP资源
if (IsBuildinPackageBundle(packageBundle))
continue;
downloadList.Add(packageBundle);
}
return ConvertToDownloadList(downloadList);
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
{
return ResourceUnpackerOperation.CreateEmptyUnpacker(Download, PackageName, upackingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> unpcakList = PlayModeHelper.GetUnpackListByAll(ActiveManifest, WebServerFileSystem, WebRemoteFileSystem);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
{
return ResourceUnpackerOperation.CreateEmptyUnpacker(Download, PackageName, upackingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> unpcakList = PlayModeHelper.GetUnpackListByTags(ActiveManifest, tags, WebServerFileSystem, WebRemoteFileSystem);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
{
return ResourceImporterOperation.CreateEmptyImporter(Download, PackageName, importerMaxNumber, failedTryAgain, timeout);
List<BundleInfo> importerList = PlayModeHelper.GetImporterListByFilePaths(ActiveManifest, filePaths, WebServerFileSystem, WebRemoteFileSystem);
var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
return operation;
}
#endregion
#region IBundleQuery接口
private BundleInfo CreateBundleInfo(PackageBundle packageBundle)
private BundleInfo CreateBundleInfo(PackageBundle packageBundle, AssetInfo assetInfo)
{
if (packageBundle == null)
throw new Exception("Should never get here !");
// 查询APP资源
if (IsBuildinPackageBundle(packageBundle))
if (WebServerFileSystem != null && WebServerFileSystem.Belong(packageBundle))
{
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromStreaming);
BundleInfo bundleInfo = new BundleInfo(WebServerFileSystem, packageBundle);
return bundleInfo;
}
// 从服务端下载
return ConvertToDownloadInfo(packageBundle);
if (WebRemoteFileSystem != null && WebRemoteFileSystem.Belong(packageBundle))
{
BundleInfo bundleInfo = new BundleInfo(WebRemoteFileSystem, packageBundle);
return bundleInfo;
}
throw new Exception($"Can not found belong file system : {packageBundle.BundleName}");
}
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
{
@@ -262,8 +145,8 @@ namespace YooAsset
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath);
return CreateBundleInfo(packageBundle);
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath);
return CreateBundleInfo(packageBundle, assetInfo);
}
BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo)
{
@@ -271,11 +154,11 @@ namespace YooAsset
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath);
var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath);
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
foreach (var packageBundle in depends)
{
BundleInfo bundleInfo = CreateBundleInfo(packageBundle);
BundleInfo bundleInfo = CreateBundleInfo(packageBundle, assetInfo);
result.Add(bundleInfo);
}
return result.ToArray();
@@ -286,7 +169,7 @@ namespace YooAsset
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath);
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath);
return packageBundle.BundleName;
}
string[] IBundleQuery.GetDependBundleNames(AssetInfo assetInfo)
@@ -295,7 +178,7 @@ namespace YooAsset
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath);
var depends = ActiveManifest.GetAllDependencies(assetInfo.AssetPath);
List<string> result = new List<string>(depends.Length);
foreach (var packageBundle in depends)
{
@@ -305,7 +188,7 @@ namespace YooAsset
}
bool IBundleQuery.ManifestValid()
{
return _activeManifest != null;
return ActiveManifest != null;
}
#endregion
}