2022-03-01 10:44:12 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
|
|
namespace YooAsset
|
|
|
|
|
|
{
|
2022-12-17 22:37:39 +08:00
|
|
|
|
internal class OfflinePlayModeImpl : IPlayModeServices, IBundleServices
|
2022-03-01 10:44:12 +08:00
|
|
|
|
{
|
2023-03-11 00:06:40 +08:00
|
|
|
|
private PackageManifest _activeManifest;
|
2022-03-25 15:02:21 +08:00
|
|
|
|
|
2022-03-01 10:44:12 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 异步初始化
|
|
|
|
|
|
/// </summary>
|
2023-06-26 18:30:29 +08:00
|
|
|
|
public InitializationOperation InitializeAsync(string packageName)
|
2022-03-01 10:44:12 +08:00
|
|
|
|
{
|
2022-10-27 14:20:05 +08:00
|
|
|
|
var operation = new OfflinePlayModeInitializationOperation(this, packageName);
|
2022-08-06 11:23:43 +08:00
|
|
|
|
OperationSystem.StartOperation(operation);
|
2022-03-01 10:44:12 +08:00
|
|
|
|
return operation;
|
|
|
|
|
|
}
|
2022-12-18 21:55:49 +08:00
|
|
|
|
|
2022-12-17 22:37:39 +08:00
|
|
|
|
#region IPlayModeServices接口
|
2023-03-11 00:06:40 +08:00
|
|
|
|
public PackageManifest ActiveManifest
|
2022-12-17 22:37:39 +08:00
|
|
|
|
{
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
2022-12-24 22:09:14 +08:00
|
|
|
|
_activeManifest = value;
|
2022-12-17 22:37:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2022-12-24 22:09:14 +08:00
|
|
|
|
return _activeManifest;
|
2022-12-17 22:37:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-03-22 18:48:52 +08:00
|
|
|
|
public void FlushManifestVersionFile()
|
2022-12-17 22:37:39 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-26 10:25:12 +08:00
|
|
|
|
private bool IsCachedPackageBundle(PackageBundle packageBundle)
|
|
|
|
|
|
{
|
|
|
|
|
|
return CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-12-17 22:37:39 +08:00
|
|
|
|
UpdatePackageVersionOperation IPlayModeServices.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
|
|
|
|
|
|
{
|
|
|
|
|
|
var operation = new OfflinePlayModeUpdatePackageVersionOperation();
|
|
|
|
|
|
OperationSystem.StartOperation(operation);
|
|
|
|
|
|
return operation;
|
|
|
|
|
|
}
|
2023-04-22 17:20:23 +08:00
|
|
|
|
UpdatePackageManifestOperation IPlayModeServices.UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion, int timeout)
|
2022-12-17 22:37:39 +08:00
|
|
|
|
{
|
2022-12-20 16:17:01 +08:00
|
|
|
|
var operation = new OfflinePlayModeUpdatePackageManifestOperation();
|
2022-12-17 22:37:39 +08:00
|
|
|
|
OperationSystem.StartOperation(operation);
|
|
|
|
|
|
return operation;
|
|
|
|
|
|
}
|
2023-03-11 00:06:40 +08:00
|
|
|
|
PreDownloadContentOperation IPlayModeServices.PreDownloadContentAsync(string packageVersion, int timeout)
|
2022-12-17 22:37:39 +08:00
|
|
|
|
{
|
2023-03-11 00:06:40 +08:00
|
|
|
|
var operation = new OfflinePlayModePreDownloadContentOperation();
|
2022-12-26 00:48:56 +08:00
|
|
|
|
OperationSystem.StartOperation(operation);
|
|
|
|
|
|
return operation;
|
|
|
|
|
|
}
|
2022-10-17 16:04:47 +08:00
|
|
|
|
|
2023-03-11 00:06:40 +08:00
|
|
|
|
ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
2022-05-05 23:11:26 +08:00
|
|
|
|
{
|
2023-03-11 00:06:40 +08:00
|
|
|
|
return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
2022-12-18 21:55:49 +08:00
|
|
|
|
}
|
2023-03-11 00:06:40 +08:00
|
|
|
|
ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
2022-12-17 22:37:39 +08:00
|
|
|
|
{
|
2023-03-11 00:06:40 +08:00
|
|
|
|
return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
2022-12-18 21:55:49 +08:00
|
|
|
|
}
|
2023-03-11 00:06:40 +08:00
|
|
|
|
ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
2022-12-17 22:37:39 +08:00
|
|
|
|
{
|
2023-03-11 00:06:40 +08:00
|
|
|
|
return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
|
2022-12-17 22:37:39 +08:00
|
|
|
|
}
|
2022-12-18 21:55:49 +08:00
|
|
|
|
|
2023-03-11 00:06:40 +08:00
|
|
|
|
ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
|
2022-12-17 22:37:39 +08:00
|
|
|
|
{
|
2023-06-26 10:25:12 +08:00
|
|
|
|
List<BundleInfo> unpcakList = GetUnpackListByAll(_activeManifest);
|
|
|
|
|
|
var operation = new ResourceUnpackerOperation(unpcakList, upackingMaxNumber, failedTryAgain, timeout);
|
|
|
|
|
|
return operation;
|
2022-12-18 21:55:49 +08:00
|
|
|
|
}
|
2023-06-26 10:25:12 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-26 10:42:56 +08:00
|
|
|
|
return ManifestTools.ConvertToUnpackInfos(downloadList);
|
2023-06-26 10:25:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-11 00:06:40 +08:00
|
|
|
|
ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
|
2022-12-18 21:55:49 +08:00
|
|
|
|
{
|
2023-06-26 10:25:12 +08:00
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-26 10:42:56 +08:00
|
|
|
|
return ManifestTools.ConvertToUnpackInfos(downloadList);
|
2022-12-17 22:37:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
2022-05-05 23:11:26 +08:00
|
|
|
|
|
2022-03-01 10:44:12 +08:00
|
|
|
|
#region IBundleServices接口
|
2023-03-11 00:06:40 +08:00
|
|
|
|
private BundleInfo CreateBundleInfo(PackageBundle packageBundle)
|
2022-03-01 10:44:12 +08:00
|
|
|
|
{
|
2023-03-11 00:06:40 +08:00
|
|
|
|
if (packageBundle == null)
|
2022-05-11 16:48:17 +08:00
|
|
|
|
throw new Exception("Should never get here !");
|
2022-07-07 19:10:44 +08:00
|
|
|
|
|
2022-08-15 11:55:13 +08:00
|
|
|
|
// 查询沙盒资源
|
2023-03-11 00:06:40 +08:00
|
|
|
|
if (CacheSystem.IsCached(packageBundle.PackageName, packageBundle.CacheGUID))
|
2022-08-15 11:55:13 +08:00
|
|
|
|
{
|
2023-03-11 00:06:40 +08:00
|
|
|
|
BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromCache);
|
2022-08-15 11:55:13 +08:00
|
|
|
|
return bundleInfo;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 查询APP资源
|
|
|
|
|
|
{
|
2023-03-11 00:06:40 +08:00
|
|
|
|
BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.LoadFromStreaming);
|
2022-08-15 11:55:13 +08:00
|
|
|
|
return bundleInfo;
|
|
|
|
|
|
}
|
2022-03-01 10:44:12 +08:00
|
|
|
|
}
|
2022-05-11 16:48:17 +08:00
|
|
|
|
BundleInfo IBundleServices.GetBundleInfo(AssetInfo assetInfo)
|
2022-05-06 23:15:03 +08:00
|
|
|
|
{
|
2022-05-11 16:48:17 +08:00
|
|
|
|
if (assetInfo.IsInvalid)
|
|
|
|
|
|
throw new Exception("Should never get here !");
|
|
|
|
|
|
|
2023-03-11 00:06:40 +08:00
|
|
|
|
// 注意:如果清单里未找到资源包会抛出异常!
|
|
|
|
|
|
var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath);
|
|
|
|
|
|
return CreateBundleInfo(packageBundle);
|
2022-05-06 23:15:03 +08:00
|
|
|
|
}
|
2022-05-11 16:48:17 +08:00
|
|
|
|
BundleInfo[] IBundleServices.GetAllDependBundleInfos(AssetInfo assetInfo)
|
2022-05-03 12:23:08 +08:00
|
|
|
|
{
|
2022-05-11 16:48:17 +08:00
|
|
|
|
if (assetInfo.IsInvalid)
|
|
|
|
|
|
throw new Exception("Should never get here !");
|
|
|
|
|
|
|
2023-03-11 00:06:40 +08:00
|
|
|
|
// 注意:如果清单里未找到资源包会抛出异常!
|
2022-12-24 22:09:14 +08:00
|
|
|
|
var depends = _activeManifest.GetAllDependencies(assetInfo.AssetPath);
|
2022-05-11 16:48:17 +08:00
|
|
|
|
List<BundleInfo> result = new List<BundleInfo>(depends.Length);
|
2023-03-11 00:06:40 +08:00
|
|
|
|
foreach (var packageBundle in depends)
|
2022-05-11 16:48:17 +08:00
|
|
|
|
{
|
2023-03-11 00:06:40 +08:00
|
|
|
|
BundleInfo bundleInfo = CreateBundleInfo(packageBundle);
|
2022-05-11 16:48:17 +08:00
|
|
|
|
result.Add(bundleInfo);
|
|
|
|
|
|
}
|
|
|
|
|
|
return result.ToArray();
|
2022-05-03 12:23:08 +08:00
|
|
|
|
}
|
2023-02-22 15:41:01 +08:00
|
|
|
|
string IBundleServices.GetBundleName(int bundleID)
|
|
|
|
|
|
{
|
|
|
|
|
|
return _activeManifest.GetBundleName(bundleID);
|
|
|
|
|
|
}
|
2022-12-03 19:48:17 +08:00
|
|
|
|
bool IBundleServices.IsServicesValid()
|
|
|
|
|
|
{
|
2022-12-24 22:09:14 +08:00
|
|
|
|
return _activeManifest != null;
|
2022-12-03 19:48:17 +08:00
|
|
|
|
}
|
2022-03-01 10:44:12 +08:00
|
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|