refactor the runtime code

重构了运行时代码,支持全新的文件系统。
This commit is contained in:
何冠峰
2024-07-04 20:36:26 +08:00
parent 2987d356b6
commit ff02da5c54
313 changed files with 9889 additions and 7234 deletions

View File

@@ -43,7 +43,7 @@ namespace YooAsset
/// <summary>
/// 身份是否无效
/// </summary>
internal bool IsInvalid
public bool IsInvalid
{
get
{
@@ -77,11 +77,6 @@ namespace YooAsset
}
}
private AssetInfo()
{
// 注意:禁止从外部创建该类
}
internal AssetInfo(string packageName, PackageAsset packageAsset, System.Type assetType)
{
if (packageAsset == null)

View File

@@ -6,204 +6,71 @@ namespace YooAsset
{
internal class BundleInfo
{
public enum ELoadMode
{
None,
LoadFromDelivery,
LoadFromStreaming,
LoadFromCache,
LoadFromRemote,
LoadFromEditor,
}
private readonly ResourceAssist _assist;
private readonly string _importFilePath;
private readonly IFileSystem _fileSystem;
/// <summary>
/// 资源包对象
/// </summary>
public readonly PackageBundle Bundle;
/// <summary>
/// 资源包加载模式
/// </summary>
public readonly ELoadMode LoadMode;
/// <summary>
/// 远端下载地址
/// </summary>
public string RemoteMainURL { private set; get; }
/// <summary>
/// 远端下载备用地址
/// </summary>
public string RemoteFallbackURL { private set; get; }
/// <summary>
/// 分发资源文件路径
/// </summary>
public string DeliveryFilePath { private set; get; }
/// <summary>
/// 注意:该字段只用于帮助编辑器下的模拟模式。
/// </summary>
public string[] IncludeAssetsInEditor;
private BundleInfo()
public BundleInfo(IFileSystem fileSystem, PackageBundle bundle)
{
}
public BundleInfo(ResourceAssist assist, PackageBundle bundle, ELoadMode loadMode, string mainURL, string fallbackURL)
{
_assist = assist;
_fileSystem = fileSystem;
Bundle = bundle;
LoadMode = loadMode;
RemoteMainURL = mainURL;
RemoteFallbackURL = fallbackURL;
DeliveryFilePath = string.Empty;
_importFilePath = null;
}
public BundleInfo(ResourceAssist assist, PackageBundle bundle, ELoadMode loadMode, string deliveryFilePath)
public BundleInfo(IFileSystem fileSystem, PackageBundle bundle, string importFilePath)
{
_assist = assist;
_fileSystem = fileSystem;
Bundle = bundle;
LoadMode = loadMode;
RemoteMainURL = string.Empty;
RemoteFallbackURL = string.Empty;
DeliveryFilePath = deliveryFilePath;
}
public BundleInfo(ResourceAssist assist, PackageBundle bundle, ELoadMode loadMode)
{
_assist = assist;
Bundle = bundle;
LoadMode = loadMode;
RemoteMainURL = string.Empty;
RemoteFallbackURL = string.Empty;
DeliveryFilePath = string.Empty;
}
#region Cache
public bool IsCached()
{
return _assist.Cache.IsCached(Bundle.CacheGUID);
}
public void CacheRecord()
{
string infoFilePath = CachedInfoFilePath;
string dataFilePath = CachedDataFilePath;
string dataFileCRC = Bundle.FileCRC;
long dataFileSize = Bundle.FileSize;
var wrapper = new CacheManager.RecordWrapper(infoFilePath, dataFilePath, dataFileCRC, dataFileSize);
_assist.Cache.Record(Bundle.CacheGUID, wrapper);
}
public void CacheDiscard()
{
_assist.Cache.Discard(Bundle.CacheGUID);
}
public EVerifyResult VerifySelf()
{
return CacheHelper.VerifyingRecordFile(_assist.Cache, Bundle.CacheGUID);
}
#endregion
#region Persistent
public string CachedDataFilePath
{
get
{
return _assist.Persistent.GetCachedDataFilePath(Bundle);
}
}
public string CachedInfoFilePath
{
get
{
return _assist.Persistent.GetCachedInfoFilePath(Bundle);
}
}
public string TempDataFilePath
{
get
{
return _assist.Persistent.GetTempDataFilePath(Bundle);
}
}
public string BuildinFilePath
{
get
{
return _assist.Persistent.GetBuildinFilePath(Bundle);
}
}
#endregion
#region Download
public DownloaderBase CreateDownloader(int failedTryAgain, int timeout = 60)
{
return _assist.Download.CreateDownload(this, failedTryAgain, timeout);
}
public DownloaderBase CreateUnpacker(int failedTryAgain, int timeout = 60)
{
var unpackBundleInfo = ConvertToUnpackInfo();
return _assist.Download.CreateDownload(unpackBundleInfo, failedTryAgain, timeout);
}
#endregion
#region AssetBundle
internal AssetBundle LoadAssetBundle(string fileLoadPath, out Stream managedStream)
{
return _assist.Loader.LoadAssetBundle(this, fileLoadPath, out managedStream);
}
internal AssetBundleCreateRequest LoadAssetBundleAsync(string fileLoadPath, out Stream managedStream)
{
return _assist.Loader.LoadAssetBundleAsync(this, fileLoadPath, out managedStream);
}
internal AssetBundle LoadDeliveryAssetBundle(string fileLoadPath)
{
return _assist.Loader.LoadDeliveryAssetBundle(this, fileLoadPath);
}
internal AssetBundleCreateRequest LoadDeliveryAssetBundleAsync(string fileLoadPath)
{
return _assist.Loader.LoadDeliveryAssetBundleAsync(this, fileLoadPath);
}
#endregion
/// <summary>
/// 转换为解压BundleInfo
/// </summary>
private BundleInfo ConvertToUnpackInfo()
{
string streamingPath = PersistentHelper.ConvertToWWWPath(BuildinFilePath);
BundleInfo newBundleInfo = new BundleInfo(_assist, Bundle, ELoadMode.LoadFromStreaming, streamingPath, streamingPath);
return newBundleInfo;
_importFilePath = importFilePath;
}
/// <summary>
/// 批量创建解压BundleInfo
/// 加载资源文件
/// </summary>
public static List<BundleInfo> CreateUnpackInfos(ResourceAssist assist, List<PackageBundle> unpackList)
public FSLoadBundleOperation LoadBundleFile()
{
List<BundleInfo> result = new List<BundleInfo>(unpackList.Count);
foreach (var packageBundle in unpackList)
{
var bundleInfo = CreateUnpackInfo(assist, packageBundle);
result.Add(bundleInfo);
}
return result;
}
private static BundleInfo CreateUnpackInfo(ResourceAssist assist, PackageBundle packageBundle)
{
string streamingPath = PersistentHelper.ConvertToWWWPath(assist.Persistent.GetBuildinFilePath(packageBundle));
BundleInfo newBundleInfo = new BundleInfo(assist, packageBundle, ELoadMode.LoadFromStreaming, streamingPath, streamingPath);
return newBundleInfo;
return _fileSystem.LoadBundleFile(Bundle);
}
/// <summary>
/// 创建导入BundleInfo
/// 卸载资源文件
/// </summary>
public static BundleInfo CreateImportInfo(ResourceAssist assist, PackageBundle packageBundle, string filePath)
public void UnloadBundleFile(object result)
{
// 注意:我们把本地文件路径指定为远端下载地址
string persistentPath = PersistentHelper.ConvertToWWWPath(filePath);
BundleInfo bundleInfo = new BundleInfo(assist, packageBundle, BundleInfo.ELoadMode.None, persistentPath, persistentPath);
return bundleInfo;
_fileSystem.UnloadBundleFile(Bundle, result);
}
/// <summary>
/// 创建下载器
/// </summary>
public FSDownloadFileOperation CreateDownloader(int failedTryAgain, int timeout)
{
return _fileSystem.DownloadFileAsync(Bundle, _importFilePath, failedTryAgain, timeout);
}
/// <summary>
/// 是否需要从远端下载
/// </summary>
public bool IsNeedDownloadFromRemote()
{
return _fileSystem.CheckNeedDownload(Bundle);
}
/// <summary>
/// 下载器合并识别码
/// </summary>
public string GetDownloadCombineGUID()
{
return $"{_fileSystem.GetHashCode()}_{Bundle.BundleGUID}";
}
}
}

View File

@@ -4,30 +4,40 @@ namespace YooAsset
internal interface IPlayMode
{
/// <summary>
/// 激活的清单
/// 当前激活的清单
/// </summary>
PackageManifest ActiveManifest { set; get; }
/// <summary>
/// 保存清单版本文件到沙盒
/// 更新游戏模式
/// </summary>
void FlushManifestVersionFile();
void UpdatePlayMode();
/// <summary>
/// 向网络端请求最新的资源版本
/// </summary>
UpdatePackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks, int timeout);
RequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout);
/// <summary>
/// 向网络端请求并更新清单
/// </summary>
UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion, int timeout);
UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout);
/// <summary>
/// 预下载指定版本的包裹内容
/// </summary>
PreDownloadContentOperation PreDownloadContentAsync(string packageVersion, int timeout);
/// <summary>
/// 清空所有文件
/// </summary>
ClearAllBundleFilesOperation ClearAllBundleFilesAsync();
/// <summary>
/// 清空未使用的文件
/// </summary>
ClearUnusedBundleFilesOperation ClearUnusedBundleFilesAsync();
// 下载相关
ResourceDownloaderOperation CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout);
ResourceDownloaderOperation CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout);

View File

@@ -0,0 +1,286 @@

namespace YooAsset
{
/// <summary>
/// 清理所有文件
/// </summary>
public abstract class ClearAllBundleFilesOperation : AsyncOperationBase
{
}
/// <summary>
/// 编辑器下模拟模式
/// </summary>
internal sealed class EditorSimulateModeClearAllBundleFilesOperation : ClearAllBundleFilesOperation
{
private enum ESteps
{
None,
ClearAllBundleFiles,
Done,
}
private readonly EditorSimulateModeImpl _impl;
private FSClearAllBundleFilesOperation _clearAllBundleFilesOp;
private ESteps _steps = ESteps.None;
internal EditorSimulateModeClearAllBundleFilesOperation(EditorSimulateModeImpl impl)
{
_impl = impl;
}
internal override void InternalOnStart()
{
_steps = ESteps.ClearAllBundleFiles;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.ClearAllBundleFiles)
{
if (_clearAllBundleFilesOp == null)
{
_clearAllBundleFilesOp = _impl.EditorFileSystem.ClearAllBundleFilesAsync();
}
Progress = _clearAllBundleFilesOp.Progress;
if (_clearAllBundleFilesOp.IsDone == false)
return;
if (_clearAllBundleFilesOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearAllBundleFilesOp.Error;
}
}
}
}
/// <summary>
/// 离线运行模式
/// </summary>
internal sealed class OfflinePlayModeClearAllBundleFilesOperation : ClearAllBundleFilesOperation
{
private enum ESteps
{
None,
ClearAllBundleFiles,
Done,
}
private readonly OfflinePlayModeImpl _impl;
private FSClearAllBundleFilesOperation _clearAllBundleFilesOp;
private ESteps _steps = ESteps.None;
internal OfflinePlayModeClearAllBundleFilesOperation(OfflinePlayModeImpl impl)
{
_impl = impl;
}
internal override void InternalOnStart()
{
_steps = ESteps.ClearAllBundleFiles;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.ClearAllBundleFiles)
{
if (_clearAllBundleFilesOp == null)
{
_clearAllBundleFilesOp = _impl.BuildinFileSystem.ClearAllBundleFilesAsync();
}
Progress = _clearAllBundleFilesOp.Progress;
if (_clearAllBundleFilesOp.IsDone == false)
return;
if (_clearAllBundleFilesOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearAllBundleFilesOp.Error;
}
}
}
}
/// <summary>
/// 联机运行模式
/// </summary>
internal sealed class HostPlayModeClearAllBundleFilesOperation : ClearAllBundleFilesOperation
{
private enum ESteps
{
None,
ClearBuildinAllBundleFiles,
ClearDeliveryAllBundleFiles,
ClearCacheAllBundleFiles,
Done,
}
private readonly HostPlayModeImpl _impl;
private FSClearAllBundleFilesOperation _clearBuildinAllBundleFilesOp;
private FSClearAllBundleFilesOperation _clearDeliveryAllBundleFilesOp;
private FSClearAllBundleFilesOperation _clearCacheAllBundleFilesOp;
private ESteps _steps = ESteps.None;
internal HostPlayModeClearAllBundleFilesOperation(HostPlayModeImpl impl)
{
_impl = impl;
}
internal override void InternalOnStart()
{
_steps = ESteps.ClearBuildinAllBundleFiles;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.ClearBuildinAllBundleFiles)
{
if (_clearBuildinAllBundleFilesOp == null)
{
_clearBuildinAllBundleFilesOp = _impl.BuildinFileSystem.ClearAllBundleFilesAsync();
}
Progress = _clearBuildinAllBundleFilesOp.Progress;
if (_clearBuildinAllBundleFilesOp.IsDone == false)
return;
if (_clearBuildinAllBundleFilesOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.ClearDeliveryAllBundleFiles;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearBuildinAllBundleFilesOp.Error;
}
}
if (_steps == ESteps.ClearDeliveryAllBundleFiles)
{
if (_impl.DeliveryFileSystem == null)
{
_steps = ESteps.ClearCacheAllBundleFiles;
return;
}
if (_clearDeliveryAllBundleFilesOp == null)
{
_clearDeliveryAllBundleFilesOp = _impl.DeliveryFileSystem.ClearAllBundleFilesAsync();
}
Progress = _clearDeliveryAllBundleFilesOp.Progress;
if (_clearDeliveryAllBundleFilesOp.IsDone == false)
return;
if (_clearDeliveryAllBundleFilesOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.ClearCacheAllBundleFiles;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearDeliveryAllBundleFilesOp.Error;
}
}
if (_steps == ESteps.ClearCacheAllBundleFiles)
{
if (_clearCacheAllBundleFilesOp == null)
{
_clearCacheAllBundleFilesOp = _impl.CacheFileSystem.ClearAllBundleFilesAsync();
}
Progress = _clearCacheAllBundleFilesOp.Progress;
if (_clearCacheAllBundleFilesOp.IsDone == false)
return;
if (_clearCacheAllBundleFilesOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearCacheAllBundleFilesOp.Error;
}
}
}
}
/// <summary>
/// WebGL运行模式
/// </summary>
internal sealed class WebPlayModeClearAllBundleFilesOperation : ClearAllBundleFilesOperation
{
private enum ESteps
{
None,
ClearAllBundleFiles,
Done,
}
private readonly WebPlayModeImpl _impl;
private FSClearAllBundleFilesOperation _clearAllBundleFilesOp;
private ESteps _steps = ESteps.None;
internal WebPlayModeClearAllBundleFilesOperation(WebPlayModeImpl impl)
{
_impl = impl;
}
internal override void InternalOnStart()
{
_steps = ESteps.ClearAllBundleFiles;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.ClearAllBundleFiles)
{
if (_clearAllBundleFilesOp == null)
{
_clearAllBundleFilesOp = _impl.WebFileSystem.ClearAllBundleFilesAsync();
}
Progress = _clearAllBundleFilesOp.Progress;
if (_clearAllBundleFilesOp.IsDone == false)
return;
if (_clearAllBundleFilesOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearAllBundleFilesOp.Error;
}
}
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 5067db2d5b2aa1240aef2f9a952a2e0c
guid: 4f25029d71d0d8c4dad70987bda364bf
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,287 @@

namespace YooAsset
{
/// <summary>
/// 清理未使用的文件
/// </summary>
public abstract class ClearUnusedBundleFilesOperation : AsyncOperationBase
{
}
/// <summary>
/// 编辑器下模拟模式
/// </summary>
internal sealed class EditorSimulateModeClearUnusedBundleFilesOperation : ClearUnusedBundleFilesOperation
{
private enum ESteps
{
None,
ClearUnusedBundleFiles,
Done,
}
private readonly EditorSimulateModeImpl _impl;
private FSClearUnusedBundleFilesOperation _clearUnusedBundleFilesOp;
private ESteps _steps = ESteps.None;
internal EditorSimulateModeClearUnusedBundleFilesOperation(EditorSimulateModeImpl impl)
{
_impl = impl;
}
internal override void InternalOnStart()
{
_steps = ESteps.ClearUnusedBundleFiles;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.ClearUnusedBundleFiles)
{
if (_clearUnusedBundleFilesOp == null)
{
_clearUnusedBundleFilesOp = _impl.EditorFileSystem.ClearUnusedBundleFilesAsync(_impl.ActiveManifest);
}
Progress = _clearUnusedBundleFilesOp.Progress;
if (_clearUnusedBundleFilesOp.IsDone == false)
return;
if (_clearUnusedBundleFilesOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearUnusedBundleFilesOp.Error;
}
}
}
}
/// <summary>
/// 离线运行模式
/// </summary>
internal sealed class OfflinePlayModeClearUnusedBundleFilesOperation : ClearUnusedBundleFilesOperation
{
private enum ESteps
{
None,
ClearUnusedBundleFiles,
Done,
}
private readonly OfflinePlayModeImpl _impl;
private FSClearUnusedBundleFilesOperation _clearUnusedBundleFilesOp;
private ESteps _steps = ESteps.None;
internal OfflinePlayModeClearUnusedBundleFilesOperation(OfflinePlayModeImpl impl)
{
_impl = impl;
}
internal override void InternalOnStart()
{
_steps = ESteps.ClearUnusedBundleFiles;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.ClearUnusedBundleFiles)
{
if (_clearUnusedBundleFilesOp == null)
{
_clearUnusedBundleFilesOp = _impl.BuildinFileSystem.ClearUnusedBundleFilesAsync(_impl.ActiveManifest);
}
Progress = _clearUnusedBundleFilesOp.Progress;
if (_clearUnusedBundleFilesOp.IsDone == false)
return;
if (_clearUnusedBundleFilesOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearUnusedBundleFilesOp.Error;
}
}
}
}
/// <summary>
/// 联机运行模式
/// </summary>
internal sealed class HostPlayModeClearUnusedBundleFilesOperation : ClearUnusedBundleFilesOperation
{
private enum ESteps
{
None,
ClearBuildinUnusedBundleFiles,
ClearDeliveryUnusedBundleFiles,
ClearCacheUnusedBundleFiles,
Done,
}
private readonly HostPlayModeImpl _impl;
private FSClearUnusedBundleFilesOperation _clearBuildinUnusedBundleFilesOp;
private FSClearUnusedBundleFilesOperation _clearDeliveryUnusedBundleFilesOp;
private FSClearUnusedBundleFilesOperation _clearCacheUnusedBundleFilesOp;
private ESteps _steps = ESteps.None;
internal HostPlayModeClearUnusedBundleFilesOperation(HostPlayModeImpl impl)
{
_impl = impl;
}
internal override void InternalOnStart()
{
_steps = ESteps.ClearBuildinUnusedBundleFiles;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.ClearBuildinUnusedBundleFiles)
{
if (_clearBuildinUnusedBundleFilesOp == null)
{
_clearBuildinUnusedBundleFilesOp = _impl.BuildinFileSystem.ClearUnusedBundleFilesAsync(_impl.ActiveManifest);
}
Progress = _clearBuildinUnusedBundleFilesOp.Progress;
if (_clearBuildinUnusedBundleFilesOp.IsDone == false)
return;
if (_clearBuildinUnusedBundleFilesOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.ClearDeliveryUnusedBundleFiles;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearBuildinUnusedBundleFilesOp.Error;
}
}
if (_steps == ESteps.ClearDeliveryUnusedBundleFiles)
{
if (_impl.DeliveryFileSystem == null)
{
_steps = ESteps.ClearCacheUnusedBundleFiles;
return;
}
if (_clearDeliveryUnusedBundleFilesOp == null)
{
_clearDeliveryUnusedBundleFilesOp = _impl.DeliveryFileSystem.ClearUnusedBundleFilesAsync(_impl.ActiveManifest);
}
Progress = _clearDeliveryUnusedBundleFilesOp.Progress;
if (_clearDeliveryUnusedBundleFilesOp.IsDone == false)
return;
if (_clearDeliveryUnusedBundleFilesOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.ClearCacheUnusedBundleFiles;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearDeliveryUnusedBundleFilesOp.Error;
}
}
if (_steps == ESteps.ClearCacheUnusedBundleFiles)
{
if (_clearCacheUnusedBundleFilesOp == null)
{
_clearCacheUnusedBundleFilesOp = _impl.CacheFileSystem.ClearUnusedBundleFilesAsync(_impl.ActiveManifest);
}
Progress = _clearCacheUnusedBundleFilesOp.Progress;
if (_clearCacheUnusedBundleFilesOp.IsDone == false)
return;
if (_clearCacheUnusedBundleFilesOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearCacheUnusedBundleFilesOp.Error;
}
}
}
}
/// <summary>
/// WebGL运行模式
/// </summary>
internal sealed class WebPlayModeClearUnusedBundleFilesOperation : ClearUnusedBundleFilesOperation
{
private enum ESteps
{
None,
ClearUnusedBundleFiles,
Done,
}
private readonly WebPlayModeImpl _impl;
private FSClearUnusedBundleFilesOperation _clearUnusedBundleFilesOp;
private ESteps _steps = ESteps.None;
internal WebPlayModeClearUnusedBundleFilesOperation(WebPlayModeImpl impl)
{
_impl = impl;
}
internal override void InternalOnStart()
{
_steps = ESteps.ClearUnusedBundleFiles;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.ClearUnusedBundleFiles)
{
if (_clearUnusedBundleFilesOp == null)
{
_clearUnusedBundleFilesOp = _impl.WebFileSystem.ClearUnusedBundleFilesAsync(_impl.ActiveManifest);
}
Progress = _clearUnusedBundleFilesOp.Progress;
if (_clearUnusedBundleFilesOp.IsDone == false)
return;
if (_clearUnusedBundleFilesOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _clearUnusedBundleFilesOp.Error;
}
}
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: fccaa9437207a174d858ce44f14f5a03
guid: 39028a4006030f1469b636b0c8b3805a
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -0,0 +1,67 @@

namespace YooAsset
{
public class DestroyOperation : AsyncOperationBase
{
private enum ESteps
{
None,
UnloadAllAssets,
DestroyPackage,
Done,
}
private readonly ResourcePackage _resourcePackage;
private UnloadAllAssetsOperation _unloadAllAssetsOp;
private ESteps _steps = ESteps.None;
public DestroyOperation(ResourcePackage resourcePackage)
{
_resourcePackage = resourcePackage;
}
internal override void InternalOnStart()
{
_steps = ESteps.UnloadAllAssets;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.UnloadAllAssets)
{
if (_unloadAllAssetsOp == null)
_unloadAllAssetsOp = _resourcePackage.UnloadAllAssetsAsync();
if (_unloadAllAssetsOp.IsDone == false)
return;
if (_unloadAllAssetsOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.DestroyPackage;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _unloadAllAssetsOp.Error;
}
}
if (_steps == ESteps.DestroyPackage)
{
// 销毁包裹
_resourcePackage.DestroyPackage();
// 最后清理该包裹的异步任务
// 注意:对于有线程操作的异步任务,需要保证线程安全释放。
OperationSystem.ClearPackageOperation(_resourcePackage.PackageName);
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 246df4d20b431c648a0821231a805e6b
guid: 61a8757fa3c6b5c42a45e97198a645a4
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -20,15 +20,14 @@ namespace YooAsset
public delegate void OnDownloadError(string fileName, string error);
public delegate void OnStartDownloadFile(string fileName, long sizeBytes);
private readonly DownloadManager _downloadMgr;
private readonly string _packageName;
private readonly int _downloadingMaxNumber;
private readonly int _failedTryAgain;
private readonly int _timeout;
private readonly List<BundleInfo> _bundleInfoList;
private readonly List<DownloaderBase> _downloaders = new List<DownloaderBase>(MAX_LOADER_COUNT);
private readonly List<DownloaderBase> _removeList = new List<DownloaderBase>(MAX_LOADER_COUNT);
private readonly List<DownloaderBase> _failedList = new List<DownloaderBase>(MAX_LOADER_COUNT);
private readonly List<FSDownloadFileOperation> _downloaders = new List<FSDownloadFileOperation>(MAX_LOADER_COUNT);
private readonly List<FSDownloadFileOperation> _removeList = new List<FSDownloadFileOperation>(MAX_LOADER_COUNT);
private readonly List<FSDownloadFileOperation> _failedList = new List<FSDownloadFileOperation>(MAX_LOADER_COUNT);
// 数据相关
private bool _isPause = false;
@@ -86,9 +85,8 @@ namespace YooAsset
public OnStartDownloadFile OnStartDownloadFileCallback { set; get; }
internal DownloaderOperation(DownloadManager downloadMgr, string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
internal DownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
_downloadMgr = downloadMgr;
_packageName = packageName;
_bundleInfoList = downloadList;
_downloadingMaxNumber = UnityEngine.Mathf.Clamp(downloadingMaxNumber, 1, MAX_LOADER_COUNT); ;
@@ -103,7 +101,7 @@ namespace YooAsset
}
internal override void InternalOnStart()
{
YooLogger.Log($"Begine to download : {TotalDownloadCount} files and {TotalDownloadBytes} bytes");
YooLogger.Log($"Begine to download {TotalDownloadCount} files and {TotalDownloadBytes} bytes");
_steps = ESteps.Check;
}
internal override void InternalOnUpdate()
@@ -133,11 +131,11 @@ namespace YooAsset
foreach (var downloader in _downloaders)
{
downloadBytes += (long)downloader.DownloadedBytes;
if (downloader.IsDone() == false)
if (downloader.IsDone == false)
continue;
// 检测是否下载失败
if (downloader.HasError())
if (downloader.Status != EOperationStatus.Succeed)
{
_removeList.Add(downloader);
_failedList.Add(downloader);
@@ -147,13 +145,13 @@ namespace YooAsset
// 下载成功
_removeList.Add(downloader);
_cachedDownloadCount++;
_cachedDownloadBytes += downloader.GetDownloadFileSize();
_cachedDownloadBytes += (long)downloader.DownloadedBytes;
}
// 移除已经完成的下载器(无论成功或失败)
foreach (var loader in _removeList)
foreach (var downloader in _removeList)
{
_downloaders.Remove(loader);
_downloaders.Remove(downloader);
}
// 如果下载进度发生变化
@@ -177,7 +175,6 @@ namespace YooAsset
int index = _bundleInfoList.Count - 1;
var bundleInfo = _bundleInfoList[index];
var downloader = bundleInfo.CreateDownloader(_failedTryAgain, _timeout);
downloader.SendRequest();
_downloaders.Add(downloader);
_bundleInfoList.RemoveAt(index);
OnStartDownloadFileCallback?.Invoke(bundleInfo.Bundle.BundleName, bundleInfo.Bundle.FileSize);
@@ -190,11 +187,11 @@ namespace YooAsset
if (_failedList.Count > 0)
{
var failedDownloader = _failedList[0];
string bundleName = failedDownloader.GetDownloadBundleName();
string bundleName = failedDownloader.Bundle.BundleName;
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Failed to download file : {bundleName}";
OnDownloadErrorCallback?.Invoke(bundleName, failedDownloader.GetLastError());
OnDownloadErrorCallback?.Invoke(bundleName, failedDownloader.Error);
OnDownloadOverCallback?.Invoke(false);
}
else
@@ -246,16 +243,18 @@ namespace YooAsset
HashSet<string> temper = new HashSet<string>();
foreach (var bundleInfo in _bundleInfoList)
{
if (temper.Contains(bundleInfo.CachedDataFilePath) == false)
string combineGUID = bundleInfo.GetDownloadCombineGUID();
if (temper.Contains(combineGUID) == false)
{
temper.Add(bundleInfo.CachedDataFilePath);
temper.Add(combineGUID);
}
}
// 合并下载列表
foreach (var bundleInfo in downloader._bundleInfoList)
{
if (temper.Contains(bundleInfo.CachedDataFilePath) == false)
string combineGUID = bundleInfo.GetDownloadCombineGUID();
if (temper.Contains(combineGUID) == false)
{
_bundleInfoList.Add(bundleInfo);
}
@@ -272,7 +271,7 @@ namespace YooAsset
{
if (_steps == ESteps.None)
{
OperationSystem.StartOperation(this);
OperationSystem.StartOperation(_packageName, this);
}
}
@@ -302,69 +301,63 @@ namespace YooAsset
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "User cancel.";
ReleaseAllDownloader();
}
}
private void ReleaseAllDownloader()
{
foreach (var downloader in _downloaders)
{
downloader.Release();
}
// 注意:停止不再使用的下载器
_downloadMgr.AbortUnusedDownloader();
foreach (var downloader in _downloaders)
{
downloader.Release();
}
}
}
}
public sealed class ResourceDownloaderOperation : DownloaderOperation
{
internal ResourceDownloaderOperation(DownloadManager downloadMgr, string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
: base(downloadMgr, packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
internal ResourceDownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
{
}
/// <summary>
/// 创建空的下载器
/// </summary>
internal static ResourceDownloaderOperation CreateEmptyDownloader(DownloadManager downloadMgr, string packageName, int downloadingMaxNumber, int failedTryAgain, int timeout)
internal static ResourceDownloaderOperation CreateEmptyDownloader(string packageName, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = new List<BundleInfo>();
var operation = new ResourceDownloaderOperation(downloadMgr, packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
var operation = new ResourceDownloaderOperation(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
}
public sealed class ResourceUnpackerOperation : DownloaderOperation
{
internal ResourceUnpackerOperation(DownloadManager downloadMgr, string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
: base(downloadMgr, packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
internal ResourceUnpackerOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
{
}
/// <summary>
/// 创建空的解压器
/// </summary>
internal static ResourceUnpackerOperation CreateEmptyUnpacker(DownloadManager downloadMgr, string packageName, int upackingMaxNumber, int failedTryAgain, int timeout)
internal static ResourceUnpackerOperation CreateEmptyUnpacker(string packageName, int upackingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = new List<BundleInfo>();
var operation = new ResourceUnpackerOperation(downloadMgr, packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue);
var operation = new ResourceUnpackerOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue);
return operation;
}
}
public sealed class ResourceImporterOperation : DownloaderOperation
{
internal ResourceImporterOperation(DownloadManager downloadMgr, string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
: base(downloadMgr, packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
internal ResourceImporterOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
{
}
/// <summary>
/// 创建空的导入器
/// </summary>
internal static ResourceImporterOperation CreateEmptyImporter(DownloadManager downloadMgr, string packageName, int upackingMaxNumber, int failedTryAgain, int timeout)
internal static ResourceImporterOperation CreateEmptyImporter(string packageName, int upackingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> downloadList = new List<BundleInfo>();
var operation = new ResourceImporterOperation(downloadMgr, packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue);
var operation = new ResourceImporterOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue);
return operation;
}
}

View File

@@ -1,8 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

namespace YooAsset
{
/// <summary>
@@ -10,429 +6,434 @@ namespace YooAsset
/// </summary>
public abstract class InitializationOperation : AsyncOperationBase
{
public string PackageVersion { protected set; get; }
}
/// <summary>
/// 编辑器下模拟模式的初始化操作
/// 编辑器下模拟模式
/// </summary>
internal sealed class EditorSimulateModeInitializationOperation : InitializationOperation
{
private enum ESteps
{
None,
LoadEditorManifest,
CreateFileSystem,
InitFileSystem,
LoadManifestFile,
Done,
}
private readonly EditorSimulateModeImpl _impl;
private readonly string _simulateManifestFilePath;
private LoadEditorManifestOperation _loadEditorManifestOp;
private readonly EditorSimulateModeParameters _parameters;
private FSInitializeFileSystemOperation _initFileSystemOp;
private FSLoadPackageManifestOperation _loadPackageManifestOp;
private ESteps _steps = ESteps.None;
internal EditorSimulateModeInitializationOperation(EditorSimulateModeImpl impl, string simulateManifestFilePath)
internal EditorSimulateModeInitializationOperation(EditorSimulateModeImpl impl, EditorSimulateModeParameters parameters)
{
_impl = impl;
_simulateManifestFilePath = simulateManifestFilePath;
_parameters = parameters;
}
internal override void InternalOnStart()
{
_steps = ESteps.LoadEditorManifest;
_steps = ESteps.CreateFileSystem;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.LoadEditorManifest)
if (_steps == ESteps.CreateFileSystem)
{
if (_loadEditorManifestOp == null)
if (_parameters.EditorFileSystemParameters == null)
{
_loadEditorManifestOp = new LoadEditorManifestOperation(_impl.PackageName, _simulateManifestFilePath);
OperationSystem.StartOperation(_impl.PackageName, _loadEditorManifestOp);
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Editor file system parameters is null";
return;
}
if (_loadEditorManifestOp.IsDone == false)
_impl.EditorFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.EditorFileSystemParameters);
if (_impl.EditorFileSystem == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to create editor file system";
return;
}
_steps = ESteps.InitFileSystem;
}
if (_steps == ESteps.InitFileSystem)
{
if (_initFileSystemOp == null)
_initFileSystemOp = _impl.EditorFileSystem.InitializeFileSystemAsync();
Progress = _initFileSystemOp.Progress;
if (_initFileSystemOp.IsDone == false)
return;
if (_loadEditorManifestOp.Status == EOperationStatus.Succeed)
if (_initFileSystemOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.LoadManifestFile;
}
else
{
PackageVersion = _loadEditorManifestOp.Manifest.PackageVersion;
_impl.ActiveManifest = _loadEditorManifestOp.Manifest;
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _initFileSystemOp.Error;
}
}
if (_steps == ESteps.LoadManifestFile)
{
if (_loadPackageManifestOp == null)
_loadPackageManifestOp = _impl.EditorFileSystem.LoadPackageManifestAsync(null);
Progress = _loadPackageManifestOp.Progress;
if (_loadPackageManifestOp.IsDone == false)
return;
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
_impl.ActiveManifest = _loadPackageManifestOp.Result;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadEditorManifestOp.Error;
Error = _loadPackageManifestOp.Error;
}
}
}
}
/// <summary>
/// 离线运行模式的初始化操作
/// 离线运行模式
/// </summary>
internal sealed class OfflinePlayModeInitializationOperation : InitializationOperation
{
private enum ESteps
{
None,
QueryBuildinPackageVersion,
LoadBuildinManifest,
PackageCaching,
CreateFileSystem,
InitFileSystem,
LoadManifestFile,
Done,
}
private readonly OfflinePlayModeImpl _impl;
private QueryBuildinPackageVersionOperation _queryBuildinPackageVersionOp;
private LoadBuildinManifestOperation _loadBuildinManifestOp;
private PackageCachingOperation _cachingOperation;
private readonly OfflinePlayModeParameters _parameters;
private FSInitializeFileSystemOperation _initFileSystemOp;
private FSLoadPackageManifestOperation _loadPackageManifestOp;
private ESteps _steps = ESteps.None;
internal OfflinePlayModeInitializationOperation(OfflinePlayModeImpl impl)
internal OfflinePlayModeInitializationOperation(OfflinePlayModeImpl impl, OfflinePlayModeParameters parameters)
{
_impl = impl;
_parameters = parameters;
}
internal override void InternalOnStart()
{
_steps = ESteps.QueryBuildinPackageVersion;
_steps = ESteps.CreateFileSystem;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.QueryBuildinPackageVersion)
if (_steps == ESteps.CreateFileSystem)
{
if (_queryBuildinPackageVersionOp == null)
if (_parameters.BuildinFileSystemParameters == null)
{
_queryBuildinPackageVersionOp = new QueryBuildinPackageVersionOperation(_impl.Persistent);
OperationSystem.StartOperation(_impl.PackageName, _queryBuildinPackageVersionOp);
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Buildin file system parameters is null";
return;
}
if (_queryBuildinPackageVersionOp.IsDone == false)
_impl.BuildinFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.BuildinFileSystemParameters);
if (_impl.BuildinFileSystem == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to create buildin file system";
return;
}
_steps = ESteps.InitFileSystem;
}
if (_steps == ESteps.InitFileSystem)
{
if (_initFileSystemOp == null)
_initFileSystemOp = _impl.BuildinFileSystem.InitializeFileSystemAsync();
Progress = _initFileSystemOp.Progress;
if (_initFileSystemOp.IsDone == false)
return;
if (_queryBuildinPackageVersionOp.Status == EOperationStatus.Succeed)
if (_initFileSystemOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.LoadBuildinManifest;
_steps = ESteps.LoadManifestFile;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _queryBuildinPackageVersionOp.Error;
Error = _initFileSystemOp.Error;
}
}
if (_steps == ESteps.LoadBuildinManifest)
if (_steps == ESteps.LoadManifestFile)
{
if (_loadBuildinManifestOp == null)
{
_loadBuildinManifestOp = new LoadBuildinManifestOperation(_impl.Persistent, _queryBuildinPackageVersionOp.PackageVersion);
OperationSystem.StartOperation(_impl.PackageName, _loadBuildinManifestOp);
}
if (_loadPackageManifestOp == null)
_loadPackageManifestOp = _impl.BuildinFileSystem.LoadPackageManifestAsync(null);
Progress = _loadBuildinManifestOp.Progress;
if (_loadBuildinManifestOp.IsDone == false)
Progress = _loadPackageManifestOp.Progress;
if (_loadPackageManifestOp.IsDone == false)
return;
if (_loadBuildinManifestOp.Status == EOperationStatus.Succeed)
{
PackageVersion = _loadBuildinManifestOp.Manifest.PackageVersion;
_impl.ActiveManifest = _loadBuildinManifestOp.Manifest;
_steps = ESteps.PackageCaching;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadBuildinManifestOp.Error;
}
}
if (_steps == ESteps.PackageCaching)
{
if (_cachingOperation == null)
{
_cachingOperation = new PackageCachingOperation(_impl.Persistent, _impl.Cache);
OperationSystem.StartOperation(_impl.PackageName, _cachingOperation);
}
Progress = _cachingOperation.Progress;
if (_cachingOperation.IsDone)
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
_impl.ActiveManifest = _loadPackageManifestOp.Result;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadPackageManifestOp.Error;
}
}
}
}
/// <summary>
/// 联机运行模式的初始化操作
/// 注意:优先从沙盒里加载清单,如果沙盒里不存在就尝试把内置清单拷贝到沙盒并加载该清单。
/// 联机运行模式
/// </summary>
internal sealed class HostPlayModeInitializationOperation : InitializationOperation
{
private enum ESteps
{
None,
CheckAppFootPrint,
QueryCachePackageVersion,
TryLoadCacheManifest,
QueryBuildinPackageVersion,
UnpackBuildinManifest,
LoadBuildinManifest,
PackageCaching,
CreateFileSystem,
InitBuildinFileSystem,
InitDeliveryFileSystem,
InitCacheFileSystem,
Done,
}
private readonly HostPlayModeImpl _impl;
private QueryBuildinPackageVersionOperation _queryBuildinPackageVersionOp;
private QueryCachePackageVersionOperation _queryCachePackageVersionOp;
private UnpackBuildinManifestOperation _unpackBuildinManifestOp;
private LoadBuildinManifestOperation _loadBuildinManifestOp;
private LoadCacheManifestOperation _loadCacheManifestOp;
private PackageCachingOperation _cachingOperation;
private readonly HostPlayModeParameters _parameters;
private FSInitializeFileSystemOperation _initBuildinFileSystemOp;
private FSInitializeFileSystemOperation _initDeliveryFileSystemOp;
private FSInitializeFileSystemOperation _initCacheFileSystemOp;
private ESteps _steps = ESteps.None;
internal HostPlayModeInitializationOperation(HostPlayModeImpl impl)
internal HostPlayModeInitializationOperation(HostPlayModeImpl impl, HostPlayModeParameters parameters)
{
_impl = impl;
_parameters = parameters;
}
internal override void InternalOnStart()
{
_steps = ESteps.CheckAppFootPrint;
_steps = ESteps.CreateFileSystem;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CheckAppFootPrint)
if (_steps == ESteps.CreateFileSystem)
{
var appFootPrint = new AppFootPrint(_impl.Persistent);
appFootPrint.Load(_impl.PackageName);
// 如果水印发生变化,则说明覆盖安装后首次打开游戏
if (appFootPrint.IsDirty())
if (_parameters.BuildinFileSystemParameters == null)
{
_impl.Persistent.DeleteSandboxManifestFilesFolder();
appFootPrint.Coverage(_impl.PackageName);
YooLogger.Log("Delete manifest files when application foot print dirty !");
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Buildin file system parameters is null";
return;
}
_steps = ESteps.QueryCachePackageVersion;
if (_parameters.CacheFileSystemParameters == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Cache file system parameters is null";
return;
}
if (_parameters.DeliveryFileSystemParameters != null)
{
_impl.DeliveryFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.DeliveryFileSystemParameters);
if (_impl.DeliveryFileSystem == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to create delivery file system";
return;
}
}
_impl.BuildinFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.BuildinFileSystemParameters);
if (_impl.BuildinFileSystem == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to create buildin file system";
return;
}
_impl.CacheFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.CacheFileSystemParameters);
if (_impl.CacheFileSystem == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to create cache file system";
return;
}
_steps = ESteps.InitBuildinFileSystem;
}
if (_steps == ESteps.QueryCachePackageVersion)
if (_steps == ESteps.InitBuildinFileSystem)
{
if (_queryCachePackageVersionOp == null)
{
_queryCachePackageVersionOp = new QueryCachePackageVersionOperation(_impl.Persistent);
OperationSystem.StartOperation(_impl.PackageName, _queryCachePackageVersionOp);
}
if (_initBuildinFileSystemOp == null)
_initBuildinFileSystemOp = _impl.BuildinFileSystem.InitializeFileSystemAsync();
if (_queryCachePackageVersionOp.IsDone == false)
Progress = _initBuildinFileSystemOp.Progress;
if (_initBuildinFileSystemOp.IsDone == false)
return;
if (_queryCachePackageVersionOp.Status == EOperationStatus.Succeed)
if (_initBuildinFileSystemOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.TryLoadCacheManifest;
}
else
{
_steps = ESteps.QueryBuildinPackageVersion;
}
}
if (_steps == ESteps.TryLoadCacheManifest)
{
if (_loadCacheManifestOp == null)
{
_loadCacheManifestOp = new LoadCacheManifestOperation(_impl.Persistent, _queryCachePackageVersionOp.PackageVersion);
OperationSystem.StartOperation(_impl.PackageName, _loadCacheManifestOp);
}
if (_loadCacheManifestOp.IsDone == false)
return;
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
{
PackageVersion = _loadCacheManifestOp.Manifest.PackageVersion;
_impl.ActiveManifest = _loadCacheManifestOp.Manifest;
_steps = ESteps.PackageCaching;
}
else
{
_steps = ESteps.QueryBuildinPackageVersion;
}
}
if (_steps == ESteps.QueryBuildinPackageVersion)
{
if (_queryBuildinPackageVersionOp == null)
{
_queryBuildinPackageVersionOp = new QueryBuildinPackageVersionOperation(_impl.Persistent);
OperationSystem.StartOperation(_impl.PackageName, _queryBuildinPackageVersionOp);
}
if (_queryBuildinPackageVersionOp.IsDone == false)
return;
if (_queryBuildinPackageVersionOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.UnpackBuildinManifest;
}
else
{
// 注意为了兼容MOD模式初始化动态新增的包裹的时候如果内置清单不存在也不需要报错
_steps = ESteps.PackageCaching;
string error = _queryBuildinPackageVersionOp.Error;
YooLogger.Log($"Failed to load buildin package version file : {error}");
}
}
if (_steps == ESteps.UnpackBuildinManifest)
{
if (_unpackBuildinManifestOp == null)
{
_unpackBuildinManifestOp = new UnpackBuildinManifestOperation(_impl.Persistent, _queryBuildinPackageVersionOp.PackageVersion);
OperationSystem.StartOperation(_impl.PackageName, _unpackBuildinManifestOp);
}
if (_unpackBuildinManifestOp.IsDone == false)
return;
if (_unpackBuildinManifestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.LoadBuildinManifest;
_steps = ESteps.InitDeliveryFileSystem;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _unpackBuildinManifestOp.Error;
Error = _initBuildinFileSystemOp.Error;
}
}
if (_steps == ESteps.LoadBuildinManifest)
if (_steps == ESteps.InitDeliveryFileSystem)
{
if (_loadBuildinManifestOp == null)
// 注意:分发文件系统可以为空
if (_impl.DeliveryFileSystem == null)
{
_loadBuildinManifestOp = new LoadBuildinManifestOperation(_impl.Persistent, _queryBuildinPackageVersionOp.PackageVersion);
OperationSystem.StartOperation(_impl.PackageName, _loadBuildinManifestOp);
_steps = ESteps.InitCacheFileSystem;
return;
}
Progress = _loadBuildinManifestOp.Progress;
if (_loadBuildinManifestOp.IsDone == false)
Progress = _initDeliveryFileSystemOp.Progress;
if (_initDeliveryFileSystemOp == null)
_initDeliveryFileSystemOp = _impl.DeliveryFileSystem.InitializeFileSystemAsync();
if (_initDeliveryFileSystemOp.IsDone == false)
return;
if (_loadBuildinManifestOp.Status == EOperationStatus.Succeed)
if (_initDeliveryFileSystemOp.Status == EOperationStatus.Succeed)
{
PackageVersion = _loadBuildinManifestOp.Manifest.PackageVersion;
_impl.ActiveManifest = _loadBuildinManifestOp.Manifest;
_impl.FlushManifestVersionFile(); //注意:解压内置清单并加载成功后保存该清单版本。
_steps = ESteps.PackageCaching;
_steps = ESteps.InitCacheFileSystem;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadBuildinManifestOp.Error;
Error = _initDeliveryFileSystemOp.Error;
}
}
if (_steps == ESteps.PackageCaching)
if (_steps == ESteps.InitCacheFileSystem)
{
if (_cachingOperation == null)
{
_cachingOperation = new PackageCachingOperation(_impl.Persistent, _impl.Cache);
OperationSystem.StartOperation(_impl.PackageName, _cachingOperation);
}
if (_initCacheFileSystemOp == null)
_initCacheFileSystemOp = _impl.CacheFileSystem.InitializeFileSystemAsync();
Progress = _cachingOperation.Progress;
if (_cachingOperation.IsDone)
Progress = _initCacheFileSystemOp.Progress;
if (_initCacheFileSystemOp.IsDone == false)
return;
if (_initCacheFileSystemOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _initCacheFileSystemOp.Error;
}
}
}
}
/// <summary>
/// WebGL运行模式的初始化操作
/// WebGL运行模式
/// </summary>
internal sealed class WebPlayModeInitializationOperation : InitializationOperation
{
private enum ESteps
{
None,
QueryWebPackageVersion,
LoadWebManifest,
CreateFileSystem,
InitWebFileSystem,
Done,
}
private readonly WebPlayModeImpl _impl;
private QueryBuildinPackageVersionOperation _queryWebPackageVersionOp;
private LoadBuildinManifestOperation _loadWebManifestOp;
private readonly WebPlayModeParameters _parameters;
private FSInitializeFileSystemOperation _initWebFileSystemOp;
private ESteps _steps = ESteps.None;
internal WebPlayModeInitializationOperation(WebPlayModeImpl impl)
internal WebPlayModeInitializationOperation(WebPlayModeImpl impl, WebPlayModeParameters parameters)
{
_impl = impl;
_parameters = parameters;
}
internal override void InternalOnStart()
{
_steps = ESteps.QueryWebPackageVersion;
_steps = ESteps.CreateFileSystem;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.QueryWebPackageVersion)
if (_steps == ESteps.CreateFileSystem)
{
if (_queryWebPackageVersionOp == null)
if (_parameters.WebFileSystemParameters == null)
{
_queryWebPackageVersionOp = new QueryBuildinPackageVersionOperation(_impl.Persistent);
OperationSystem.StartOperation(_impl.PackageName, _queryWebPackageVersionOp);
}
if (_queryWebPackageVersionOp.IsDone == false)
return;
if (_queryWebPackageVersionOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.LoadWebManifest;
}
else
{
// 注意WebGL平台可能因为网络的原因会导致请求失败。如果内置清单不存在或者超时也不需要报错
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
string error = _queryWebPackageVersionOp.Error;
YooLogger.Log($"Failed to load web package version file : {error}");
Status = EOperationStatus.Failed;
Error = "Web file system parameters is null";
return;
}
_impl.WebFileSystem = PlayModeHelper.CreateFileSystem(_impl.PackageName, _parameters.WebFileSystemParameters);
if (_impl.WebFileSystem == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to create web file system";
return;
}
_steps = ESteps.InitWebFileSystem;
}
if (_steps == ESteps.LoadWebManifest)
if (_steps == ESteps.InitWebFileSystem)
{
if (_loadWebManifestOp == null)
{
_loadWebManifestOp = new LoadBuildinManifestOperation(_impl.Persistent, _queryWebPackageVersionOp.PackageVersion);
OperationSystem.StartOperation(_impl.PackageName, _loadWebManifestOp);
}
if (_initWebFileSystemOp == null)
_initWebFileSystemOp = _impl.WebFileSystem.InitializeFileSystemAsync();
Progress = _loadWebManifestOp.Progress;
if (_loadWebManifestOp.IsDone == false)
Progress = _initWebFileSystemOp.Progress;
if (_initWebFileSystemOp.IsDone == false)
return;
if (_loadWebManifestOp.Status == EOperationStatus.Succeed)
if (_initWebFileSystemOp.Status == EOperationStatus.Succeed)
{
PackageVersion = _loadWebManifestOp.Manifest.PackageVersion;
_impl.ActiveManifest = _loadWebManifestOp.Manifest;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
@@ -440,66 +441,9 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadWebManifestOp.Error;
Error = _initWebFileSystemOp.Error;
}
}
}
}
/// <summary>
/// 应用程序水印
/// </summary>
internal class AppFootPrint
{
private PersistentManager _persistent;
private string _footPrint;
public AppFootPrint(PersistentManager persistent)
{
_persistent = persistent;
}
/// <summary>
/// 读取应用程序水印
/// </summary>
public void Load(string packageName)
{
string footPrintFilePath = _persistent.SandboxAppFootPrintFilePath;
if (File.Exists(footPrintFilePath))
{
_footPrint = FileUtility.ReadAllText(footPrintFilePath);
}
else
{
Coverage(packageName);
}
}
/// <summary>
/// 检测水印是否发生变化
/// </summary>
public bool IsDirty()
{
#if UNITY_EDITOR
return _footPrint != Application.version;
#else
return _footPrint != Application.buildGUID;
#endif
}
/// <summary>
/// 覆盖掉水印
/// </summary>
public void Coverage(string packageName)
{
#if UNITY_EDITOR
_footPrint = Application.version;
#else
_footPrint = Application.buildGUID;
#endif
string footPrintFilePath = _persistent.SandboxAppFootPrintFilePath;
FileUtility.WriteAllText(footPrintFilePath, _footPrint);
YooLogger.Log($"Save application foot print : {_footPrint}");
}
}
}

View File

@@ -212,9 +212,9 @@ namespace YooAsset
Manifest.BundleDic1.Add(packageBundle.BundleName, packageBundle);
Manifest.BundleDic2.Add(packageBundle.FileName, packageBundle);
// 注意:原始文件可能存在相同的CacheGUID
if (Manifest.BundleDic3.ContainsKey(packageBundle.CacheGUID) == false)
Manifest.BundleDic3.Add(packageBundle.CacheGUID, packageBundle);
// 注意:原始文件可能存在相同的BundleGUID
if (Manifest.BundleDic3.ContainsKey(packageBundle.BundleGUID) == false)
Manifest.BundleDic3.Add(packageBundle.BundleGUID, packageBundle);
_packageBundleCount--;
Progress = 1f - _packageBundleCount / _progressTotalValue;

View File

@@ -1,113 +0,0 @@

namespace YooAsset
{
internal class DownloadManifestOperation : AsyncOperationBase
{
private enum ESteps
{
None,
DownloadPackageHashFile,
DownloadManifestFile,
Done,
}
private readonly PersistentManager _persistent;
private readonly IRemoteServices _remoteServices;
private readonly string _packageVersion;
private readonly int _timeout;
private UnityWebFileRequester _downloader1;
private UnityWebFileRequester _downloader2;
private ESteps _steps = ESteps.None;
private int _requestCount = 0;
internal DownloadManifestOperation(PersistentManager persistent, IRemoteServices remoteServices, string packageVersion, int timeout)
{
_persistent = persistent;
_remoteServices = remoteServices;
_packageVersion = packageVersion;
_timeout = timeout;
}
internal override void InternalOnStart()
{
_requestCount = RequestHelper.GetRequestFailedCount(_persistent.PackageName, nameof(DownloadManifestOperation));
_steps = ESteps.DownloadPackageHashFile;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.DownloadPackageHashFile)
{
if (_downloader1 == null)
{
string savePath = _persistent.GetSandboxPackageHashFilePath(_packageVersion);
string fileName = YooAssetSettingsData.GetPackageHashFileName(_persistent.PackageName, _packageVersion);
string webURL = GetDownloadRequestURL(fileName);
YooLogger.Log($"Beginning to download package hash file : {webURL}");
_downloader1 = new UnityWebFileRequester();
_downloader1.SendRequest(webURL, savePath, _timeout);
}
_downloader1.CheckTimeout();
if (_downloader1.IsDone() == false)
return;
if (_downloader1.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloader1.GetError();
RequestHelper.RecordRequestFailed(_persistent.PackageName, nameof(DownloadManifestOperation));
}
else
{
_steps = ESteps.DownloadManifestFile;
}
_downloader1.Dispose();
}
if (_steps == ESteps.DownloadManifestFile)
{
if (_downloader2 == null)
{
string savePath = _persistent.GetSandboxPackageManifestFilePath(_packageVersion);
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_persistent.PackageName, _packageVersion);
string webURL = GetDownloadRequestURL(fileName);
YooLogger.Log($"Beginning to download package manifest file : {webURL}");
_downloader2 = new UnityWebFileRequester();
_downloader2.SendRequest(webURL, savePath, _timeout);
}
_downloader2.CheckTimeout();
if (_downloader2.IsDone() == false)
return;
if (_downloader2.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloader2.GetError();
RequestHelper.RecordRequestFailed(_persistent.PackageName, nameof(DownloadManifestOperation));
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
_downloader2.Dispose();
}
}
private string GetDownloadRequestURL(string fileName)
{
// 轮流返回请求地址
if (_requestCount % 2 == 0)
return _remoteServices.GetRemoteMainURL(fileName);
else
return _remoteServices.GetRemoteFallbackURL(fileName);
}
}
}

View File

@@ -1,91 +0,0 @@

namespace YooAsset
{
internal class LoadBuildinManifestOperation : AsyncOperationBase
{
private enum ESteps
{
None,
LoadBuildinManifest,
CheckDeserializeManifest,
Done,
}
private readonly PersistentManager _persistent;
private readonly string _buildinPackageVersion;
private UnityWebDataRequester _downloader;
private DeserializeManifestOperation _deserializer;
private ESteps _steps = ESteps.None;
/// <summary>
/// 加载的清单实例
/// </summary>
public PackageManifest Manifest { private set; get; }
public LoadBuildinManifestOperation(PersistentManager persistent, string buildinPackageVersion)
{
_persistent = persistent;
_buildinPackageVersion = buildinPackageVersion;
}
internal override void InternalOnStart()
{
_steps = ESteps.LoadBuildinManifest;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadBuildinManifest)
{
if (_downloader == null)
{
string filePath = _persistent.GetBuildinPackageManifestFilePath(_buildinPackageVersion);
string url = PersistentHelper.ConvertToWWWPath(filePath);
_downloader = new UnityWebDataRequester();
_downloader.SendRequest(url);
}
if (_downloader.IsDone() == false)
return;
if (_downloader.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloader.GetError();
}
else
{
byte[] bytesData = _downloader.GetData();
_deserializer = new DeserializeManifestOperation(bytesData);
OperationSystem.StartOperation(_persistent.PackageName, _deserializer);
_steps = ESteps.CheckDeserializeManifest;
}
_downloader.Dispose();
}
if (_steps == ESteps.CheckDeserializeManifest)
{
Progress = _deserializer.Progress;
if (_deserializer.IsDone == false)
return;
if (_deserializer.Status == EOperationStatus.Succeed)
{
Manifest = _deserializer.Manifest;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _deserializer.Error;
}
}
}
}
}

View File

@@ -1,141 +0,0 @@
using System.IO;
namespace YooAsset
{
internal class LoadCacheManifestOperation : AsyncOperationBase
{
private enum ESteps
{
None,
QueryCachePackageHash,
VerifyFileHash,
LoadCacheManifest,
CheckDeserializeManifest,
Done,
}
private readonly PersistentManager _persistent;
private readonly string _packageVersion;
private QueryCachePackageHashOperation _queryCachePackageHashOp;
private DeserializeManifestOperation _deserializer;
private string _manifestFilePath;
private ESteps _steps = ESteps.None;
/// <summary>
/// 加载的清单实例
/// </summary>
public PackageManifest Manifest { private set; get; }
public LoadCacheManifestOperation(PersistentManager persistent, string packageVersion)
{
_persistent = persistent;
_packageVersion = packageVersion;
}
internal override void InternalOnStart()
{
_steps = ESteps.QueryCachePackageHash;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.QueryCachePackageHash)
{
if (_queryCachePackageHashOp == null)
{
_queryCachePackageHashOp = new QueryCachePackageHashOperation(_persistent, _packageVersion);
OperationSystem.StartOperation(_persistent.PackageName, _queryCachePackageHashOp);
}
if (_queryCachePackageHashOp.IsDone == false)
return;
if (_queryCachePackageHashOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.VerifyFileHash;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _queryCachePackageHashOp.Error;
ClearCacheFile();
}
}
if (_steps == ESteps.VerifyFileHash)
{
_manifestFilePath = _persistent.GetSandboxPackageManifestFilePath(_packageVersion);
if (File.Exists(_manifestFilePath) == false)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Not found cache manifest file : {_manifestFilePath}";
ClearCacheFile();
return;
}
string fileHash = HashUtility.FileMD5Safely(_manifestFilePath);
if (fileHash != _queryCachePackageHashOp.PackageHash)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to verify cache manifest file hash !";
ClearCacheFile();
}
else
{
_steps = ESteps.LoadCacheManifest;
}
}
if (_steps == ESteps.LoadCacheManifest)
{
byte[] bytesData = File.ReadAllBytes(_manifestFilePath);
_deserializer = new DeserializeManifestOperation(bytesData);
OperationSystem.StartOperation(_persistent.PackageName, _deserializer);
_steps = ESteps.CheckDeserializeManifest;
}
if (_steps == ESteps.CheckDeserializeManifest)
{
Progress = _deserializer.Progress;
if (_deserializer.IsDone == false)
return;
if (_deserializer.Status == EOperationStatus.Succeed)
{
Manifest = _deserializer.Manifest;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _deserializer.Error;
ClearCacheFile();
}
}
}
private void ClearCacheFile()
{
// 注意:如果加载沙盒内的清单报错,为了避免流程被卡住,主动把损坏的文件删除。
if (File.Exists(_manifestFilePath))
{
YooLogger.Warning($"Failed to load cache manifest file : {Error}");
YooLogger.Warning($"Invalid cache manifest file have been removed : {_manifestFilePath}");
File.Delete(_manifestFilePath);
}
string hashFilePath = _persistent.GetSandboxPackageHashFilePath(_packageVersion);
if (File.Exists(hashFilePath))
{
File.Delete(hashFilePath);
}
}
}
}

View File

@@ -1,78 +0,0 @@
using System.IO;
namespace YooAsset
{
internal class LoadEditorManifestOperation : AsyncOperationBase
{
private enum ESteps
{
None,
LoadEditorManifest,
CheckDeserializeManifest,
Done,
}
private readonly string _packageName;
private readonly string _manifestFilePath;
private DeserializeManifestOperation _deserializer;
private ESteps _steps = ESteps.None;
/// <summary>
/// 加载的清单实例
/// </summary>
public PackageManifest Manifest { private set; get; }
public LoadEditorManifestOperation(string packageName, string manifestFilePath)
{
_packageName = packageName;
_manifestFilePath = manifestFilePath;
}
internal override void InternalOnStart()
{
_steps = ESteps.LoadEditorManifest;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadEditorManifest)
{
if (File.Exists(_manifestFilePath) == false)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Not found simulation manifest file : {_manifestFilePath}";
return;
}
YooLogger.Log($"Load editor manifest file : {_manifestFilePath}");
byte[] bytesData = FileUtility.ReadAllBytes(_manifestFilePath);
_deserializer = new DeserializeManifestOperation(bytesData);
OperationSystem.StartOperation(_packageName, _deserializer);
_steps = ESteps.CheckDeserializeManifest;
}
if (_steps == ESteps.CheckDeserializeManifest)
{
Progress = _deserializer.Progress;
if (_deserializer.IsDone == false)
return;
if (_deserializer.Status == EOperationStatus.Succeed)
{
Manifest = _deserializer.Manifest;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _deserializer.Error;
}
}
}
}
}

View File

@@ -1,151 +0,0 @@

namespace YooAsset
{
internal class LoadRemoteManifestOperation : AsyncOperationBase
{
private enum ESteps
{
None,
DownloadPackageHashFile,
DownloadManifestFile,
VerifyFileHash,
CheckDeserializeManifest,
Done,
}
private readonly IRemoteServices _remoteServices;
private readonly string _packageName;
private readonly string _packageVersion;
private readonly int _timeout;
private QueryRemotePackageHashOperation _queryRemotePackageHashOp;
private UnityWebDataRequester _downloader;
private DeserializeManifestOperation _deserializer;
private byte[] _fileData;
private ESteps _steps = ESteps.None;
private int _requestCount = 0;
/// <summary>
/// 加载的清单实例
/// </summary>
public PackageManifest Manifest { private set; get; }
internal LoadRemoteManifestOperation(IRemoteServices remoteServices, string packageName, string packageVersion, int timeout)
{
_remoteServices = remoteServices;
_packageName = packageName;
_packageVersion = packageVersion;
_timeout = timeout;
}
internal override void InternalOnStart()
{
_requestCount = RequestHelper.GetRequestFailedCount(_packageName, nameof(LoadRemoteManifestOperation));
_steps = ESteps.DownloadPackageHashFile;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.DownloadPackageHashFile)
{
if (_queryRemotePackageHashOp == null)
{
_queryRemotePackageHashOp = new QueryRemotePackageHashOperation(_remoteServices, _packageName, _packageVersion, _timeout);
OperationSystem.StartOperation(_packageName, _queryRemotePackageHashOp);
}
if (_queryRemotePackageHashOp.IsDone == false)
return;
if (_queryRemotePackageHashOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.DownloadManifestFile;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _queryRemotePackageHashOp.Error;
}
}
if (_steps == ESteps.DownloadManifestFile)
{
if (_downloader == null)
{
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_packageName, _packageVersion);
string webURL = GetDownloadRequestURL(fileName);
YooLogger.Log($"Beginning to download manifest file : {webURL}");
_downloader = new UnityWebDataRequester();
_downloader.SendRequest(webURL, _timeout);
}
_downloader.CheckTimeout();
if (_downloader.IsDone() == false)
return;
if (_downloader.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloader.GetError();
RequestHelper.RecordRequestFailed(_packageName, nameof(LoadRemoteManifestOperation));
}
else
{
_fileData = _downloader.GetData();
_steps = ESteps.VerifyFileHash;
}
_downloader.Dispose();
}
if (_steps == ESteps.VerifyFileHash)
{
string fileHash = HashUtility.BytesMD5(_fileData);
if (fileHash != _queryRemotePackageHashOp.PackageHash)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Failed to verify remote manifest file hash !";
}
else
{
_deserializer = new DeserializeManifestOperation(_fileData);
OperationSystem.StartOperation(_packageName, _deserializer);
_steps = ESteps.CheckDeserializeManifest;
}
}
if (_steps == ESteps.CheckDeserializeManifest)
{
Progress = _deserializer.Progress;
if (_deserializer.IsDone == false)
return;
if (_deserializer.Status == EOperationStatus.Succeed)
{
Manifest = _deserializer.Manifest;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _deserializer.Error;
}
}
}
private string GetDownloadRequestURL(string fileName)
{
// 轮流返回请求地址
if (_requestCount % 2 == 0)
return _remoteServices.GetRemoteMainURL(fileName);
else
return _remoteServices.GetRemoteFallbackURL(fileName);
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 486ce3e7ad16f2948a36d49ecabd76b2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,75 +0,0 @@

namespace YooAsset
{
internal class QueryBuildinPackageVersionOperation : AsyncOperationBase
{
private enum ESteps
{
None,
LoadBuildinPackageVersionFile,
Done,
}
private readonly PersistentManager _persistent;
private UnityWebDataRequester _downloader;
private ESteps _steps = ESteps.None;
/// <summary>
/// 包裹版本
/// </summary>
public string PackageVersion { private set; get; }
public QueryBuildinPackageVersionOperation(PersistentManager persistent)
{
_persistent = persistent;
}
internal override void InternalOnStart()
{
_steps = ESteps.LoadBuildinPackageVersionFile;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadBuildinPackageVersionFile)
{
if (_downloader == null)
{
string filePath = _persistent.GetBuildinPackageVersionFilePath();
string url = PersistentHelper.ConvertToWWWPath(filePath);
_downloader = new UnityWebDataRequester();
_downloader.SendRequest(url);
}
if (_downloader.IsDone() == false)
return;
if (_downloader.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloader.GetError();
}
else
{
PackageVersion = _downloader.GetText();
if (string.IsNullOrEmpty(PackageVersion))
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Buildin package version file content is empty !";
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
}
_downloader.Dispose();
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: bdc251ea99d82e54199dfba540f2814d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,64 +0,0 @@
using System.IO;
namespace YooAsset
{
internal class QueryCachePackageHashOperation : AsyncOperationBase
{
private enum ESteps
{
None,
LoadCachePackageHashFile,
Done,
}
private readonly PersistentManager _persistent;
private readonly string _packageVersion;
private ESteps _steps = ESteps.None;
/// <summary>
/// 包裹哈希值
/// </summary>
public string PackageHash { private set; get; }
public QueryCachePackageHashOperation(PersistentManager persistent, string packageVersion)
{
_persistent = persistent;
_packageVersion = packageVersion;
}
internal override void InternalOnStart()
{
_steps = ESteps.LoadCachePackageHashFile;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadCachePackageHashFile)
{
string filePath = _persistent.GetSandboxPackageHashFilePath(_packageVersion);
if (File.Exists(filePath) == false)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Cache package hash file not found : {filePath}";
return;
}
PackageHash = FileUtility.ReadAllText(filePath);
if (string.IsNullOrEmpty(PackageHash))
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Cache package hash file content is empty !";
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 60db6a6586340664ab7e9f85cec0eef4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,62 +0,0 @@
using System.IO;
namespace YooAsset
{
internal class QueryCachePackageVersionOperation : AsyncOperationBase
{
private enum ESteps
{
None,
LoadCachePackageVersionFile,
Done,
}
private readonly PersistentManager _persistent;
private ESteps _steps = ESteps.None;
/// <summary>
/// 包裹版本
/// </summary>
public string PackageVersion { private set; get; }
public QueryCachePackageVersionOperation(PersistentManager persistent)
{
_persistent = persistent;
}
internal override void InternalOnStart()
{
_steps = ESteps.LoadCachePackageVersionFile;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.LoadCachePackageVersionFile)
{
string filePath = _persistent.GetSandboxPackageVersionFilePath();
if (File.Exists(filePath) == false)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Cache package version file not found : {filePath}";
return;
}
PackageVersion = FileUtility.ReadAllText(filePath);
if (string.IsNullOrEmpty(PackageVersion))
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Cache package version file content is empty !";
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 29a2cbdd051ba1247a24693d56cdc2c3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,100 +0,0 @@

namespace YooAsset
{
internal class QueryRemotePackageHashOperation : AsyncOperationBase
{
private enum ESteps
{
None,
DownloadPackageHash,
Done,
}
private readonly IRemoteServices _remoteServices;
private readonly string _packageName;
private readonly string _packageVersion;
private readonly int _timeout;
private UnityWebDataRequester _downloader;
private ESteps _steps = ESteps.None;
private int _requestCount = 0;
/// <summary>
/// 包裹哈希值
/// </summary>
public string PackageHash { private set; get; }
public QueryRemotePackageHashOperation(IRemoteServices remoteServices, string packageName, string packageVersion, int timeout)
{
_remoteServices = remoteServices;
_packageName = packageName;
_packageVersion = packageVersion;
_timeout = timeout;
}
internal override void InternalOnStart()
{
_requestCount = RequestHelper.GetRequestFailedCount(_packageName, nameof(QueryRemotePackageHashOperation));
_steps = ESteps.DownloadPackageHash;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.DownloadPackageHash)
{
if (_downloader == null)
{
string fileName = YooAssetSettingsData.GetPackageHashFileName(_packageName, _packageVersion);
string webURL = GetPackageHashRequestURL(fileName);
YooLogger.Log($"Beginning to request package hash : {webURL}");
_downloader = new UnityWebDataRequester();
_downloader.SendRequest(webURL, _timeout);
}
Progress = _downloader.Progress();
_downloader.CheckTimeout();
if (_downloader.IsDone() == false)
return;
if (_downloader.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloader.GetError();
RequestHelper.RecordRequestFailed(_packageName, nameof(QueryRemotePackageHashOperation));
}
else
{
PackageHash = _downloader.GetText();
if (string.IsNullOrEmpty(PackageHash))
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Remote package hash is empty : {_downloader.URL}";
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
}
_downloader.Dispose();
}
}
private string GetPackageHashRequestURL(string fileName)
{
string url;
// 轮流返回请求地址
if (_requestCount % 2 == 0)
url = _remoteServices.GetRemoteMainURL(fileName);
else
url = _remoteServices.GetRemoteFallbackURL(fileName);
return url;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: ef77260f58172dd42ad10cfb862b78ec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,104 +0,0 @@

namespace YooAsset
{
internal class QueryRemotePackageVersionOperation : AsyncOperationBase
{
private enum ESteps
{
None,
DownloadPackageVersion,
Done,
}
private readonly IRemoteServices _remoteServices;
private readonly string _packageName;
private readonly bool _appendTimeTicks;
private readonly int _timeout;
private UnityWebDataRequester _downloader;
private ESteps _steps = ESteps.None;
private int _requestCount = 0;
/// <summary>
/// 包裹版本
/// </summary>
public string PackageVersion { private set; get; }
public QueryRemotePackageVersionOperation(IRemoteServices remoteServices, string packageName, bool appendTimeTicks, int timeout)
{
_remoteServices = remoteServices;
_packageName = packageName;
_appendTimeTicks = appendTimeTicks;
_timeout = timeout;
}
internal override void InternalOnStart()
{
_requestCount = RequestHelper.GetRequestFailedCount(_packageName, nameof(QueryRemotePackageVersionOperation));
_steps = ESteps.DownloadPackageVersion;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.DownloadPackageVersion)
{
if (_downloader == null)
{
string fileName = YooAssetSettingsData.GetPackageVersionFileName(_packageName);
string webURL = GetPackageVersionRequestURL(fileName);
YooLogger.Log($"Beginning to request package version : {webURL}");
_downloader = new UnityWebDataRequester();
_downloader.SendRequest(webURL, _timeout);
}
Progress = _downloader.Progress();
_downloader.CheckTimeout();
if (_downloader.IsDone() == false)
return;
if (_downloader.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloader.GetError();
RequestHelper.RecordRequestFailed(_packageName, nameof(QueryRemotePackageVersionOperation));
}
else
{
PackageVersion = _downloader.GetText();
if (string.IsNullOrEmpty(PackageVersion))
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"Remote package version is empty : {_downloader.URL}";
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
}
_downloader.Dispose();
}
}
private string GetPackageVersionRequestURL(string fileName)
{
string url;
// 轮流返回请求地址
if (_requestCount % 2 == 0)
url = _remoteServices.GetRemoteMainURL(fileName);
else
url = _remoteServices.GetRemoteFallbackURL(fileName);
// 在URL末尾添加时间戳
if (_appendTimeTicks)
return $"{url}?{System.DateTime.UtcNow.Ticks}";
else
return url;
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 1d702a1a39789a34da99cbb854708b82
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,92 +0,0 @@

namespace YooAsset
{
internal class UnpackBuildinManifestOperation : AsyncOperationBase
{
private enum ESteps
{
None,
UnpackManifestHashFile,
UnpackManifestFile,
Done,
}
private readonly PersistentManager _persistent;
private readonly string _buildinPackageVersion;
private UnityWebFileRequester _downloader1;
private UnityWebFileRequester _downloader2;
private ESteps _steps = ESteps.None;
public UnpackBuildinManifestOperation(PersistentManager persistent, string buildinPackageVersion)
{
_persistent = persistent;
_buildinPackageVersion = buildinPackageVersion;
}
internal override void InternalOnStart()
{
_steps = ESteps.UnpackManifestHashFile;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.UnpackManifestHashFile)
{
if (_downloader1 == null)
{
string savePath = _persistent.GetSandboxPackageHashFilePath(_buildinPackageVersion);
string filePath = _persistent.GetBuildinPackageHashFilePath(_buildinPackageVersion);
string url = PersistentHelper.ConvertToWWWPath(filePath);
_downloader1 = new UnityWebFileRequester();
_downloader1.SendRequest(url, savePath);
}
if (_downloader1.IsDone() == false)
return;
if (_downloader1.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloader1.GetError();
}
else
{
_steps = ESteps.UnpackManifestFile;
}
_downloader1.Dispose();
}
if (_steps == ESteps.UnpackManifestFile)
{
if (_downloader2 == null)
{
string savePath = _persistent.GetSandboxPackageManifestFilePath(_buildinPackageVersion);
string filePath = _persistent.GetBuildinPackageManifestFilePath(_buildinPackageVersion);
string url = PersistentHelper.ConvertToWWWPath(filePath);
_downloader2 = new UnityWebFileRequester();
_downloader2.SendRequest(url, savePath);
}
if (_downloader2.IsDone() == false)
return;
if (_downloader2.HasError())
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloader2.GetError();
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
_downloader2.Dispose();
}
}
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 3a7685e67b0e948439ffba34513b78c0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -51,11 +51,11 @@ namespace YooAsset
public abstract ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60);
}
internal class EditorPlayModePreDownloadContentOperation : PreDownloadContentOperation
internal class EditorSimulateModePreDownloadContentOperation : PreDownloadContentOperation
{
private readonly EditorSimulateModeImpl _impl;
public EditorPlayModePreDownloadContentOperation(EditorSimulateModeImpl impl)
public EditorSimulateModePreDownloadContentOperation(EditorSimulateModeImpl impl)
{
_impl = impl;
}
@@ -69,23 +69,23 @@ namespace YooAsset
public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
}
internal class OfflinePlayModePreDownloadContentOperation : PreDownloadContentOperation
@@ -106,23 +106,23 @@ namespace YooAsset
public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
}
internal class HostPlayModePreDownloadContentOperation : PreDownloadContentOperation
@@ -130,19 +130,16 @@ namespace YooAsset
private enum ESteps
{
None,
CheckParams,
CheckActiveManifest,
TryLoadCacheManifest,
DownloadManifest,
LoadCacheManifest,
LoadPackageManifest,
Done,
}
private readonly HostPlayModeImpl _impl;
private readonly string _packageVersion;
private readonly int _timeout;
private LoadCacheManifestOperation _tryLoadCacheManifestOp;
private LoadCacheManifestOperation _loadCacheManifestOp;
private DownloadManifestOperation _downloadManifestOp;
private FSLoadPackageManifestOperation _loadPackageManifestOp;
private PackageManifest _manifest;
private ESteps _steps = ESteps.None;
@@ -155,13 +152,26 @@ namespace YooAsset
}
internal override void InternalOnStart()
{
_steps = ESteps.CheckActiveManifest;
_steps = ESteps.CheckParams;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CheckParams)
{
if (string.IsNullOrEmpty(_packageVersion))
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Package version is null or empty.";
return;
}
_steps = ESteps.CheckActiveManifest;
}
if (_steps == ESteps.CheckActiveManifest)
{
// 检测当前激活的清单对象
@@ -175,69 +185,22 @@ namespace YooAsset
return;
}
}
_steps = ESteps.TryLoadCacheManifest;
_steps = ESteps.LoadPackageManifest;
}
if (_steps == ESteps.TryLoadCacheManifest)
if (_steps == ESteps.LoadPackageManifest)
{
if (_tryLoadCacheManifestOp == null)
if (_loadPackageManifestOp == null)
{
_tryLoadCacheManifestOp = new LoadCacheManifestOperation(_impl.Persistent, _packageVersion);
OperationSystem.StartOperation(_impl.PackageName, _tryLoadCacheManifestOp);
_loadPackageManifestOp = _impl.CacheFileSystem.LoadPackageManifestAsync(_packageVersion, _timeout);
}
if (_tryLoadCacheManifestOp.IsDone == false)
if (_loadPackageManifestOp.IsDone == false)
return;
if (_tryLoadCacheManifestOp.Status == EOperationStatus.Succeed)
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
{
_manifest = _tryLoadCacheManifestOp.Manifest;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.DownloadManifest;
}
}
if (_steps == ESteps.DownloadManifest)
{
if (_downloadManifestOp == null)
{
_downloadManifestOp = new DownloadManifestOperation(_impl.Persistent, _impl.RemoteServices, _packageVersion, _timeout);
OperationSystem.StartOperation(_impl.PackageName, _downloadManifestOp);
}
if (_downloadManifestOp.IsDone == false)
return;
if (_downloadManifestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.LoadCacheManifest;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloadManifestOp.Error;
}
}
if (_steps == ESteps.LoadCacheManifest)
{
if (_loadCacheManifestOp == null)
{
_loadCacheManifestOp = new LoadCacheManifestOperation(_impl.Persistent, _packageVersion);
OperationSystem.StartOperation(_impl.PackageName, _loadCacheManifestOp);
}
if (_loadCacheManifestOp.IsDone == false)
return;
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
{
_manifest = _loadCacheManifestOp.Manifest;
_manifest = _loadPackageManifestOp.Result;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
@@ -245,7 +208,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadCacheManifestOp.Error;
Error = _loadPackageManifestOp.Error;
}
}
}
@@ -255,11 +218,11 @@ namespace YooAsset
if (Status != EOperationStatus.Succeed)
{
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
List<BundleInfo> downloadList = _impl.GetDownloadListByAll(_manifest);
var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByAll(_manifest, _impl.BuildinFileSystem, _impl.DeliveryFileSystem, _impl.CacheFileSystem);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
@@ -267,11 +230,11 @@ namespace YooAsset
if (Status != EOperationStatus.Succeed)
{
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, new string[] { tag });
var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByTags(_manifest, new string[] { tag }, _impl.BuildinFileSystem, _impl.DeliveryFileSystem, _impl.CacheFileSystem);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
@@ -279,11 +242,11 @@ namespace YooAsset
if (Status != EOperationStatus.Succeed)
{
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, tags);
var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByTags(_manifest, tags, _impl.BuildinFileSystem, _impl.DeliveryFileSystem, _impl.CacheFileSystem);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
@@ -291,15 +254,15 @@ namespace YooAsset
if (Status != EOperationStatus.Succeed)
{
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
List<AssetInfo> assetInfos = new List<AssetInfo>();
var assetInfo = _manifest.ConvertLocationToAssetInfo(location, null);
assetInfos.Add(assetInfo);
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray());
var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), _impl.BuildinFileSystem, _impl.DeliveryFileSystem, _impl.CacheFileSystem);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
@@ -307,7 +270,7 @@ namespace YooAsset
if (Status != EOperationStatus.Succeed)
{
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
@@ -317,8 +280,8 @@ namespace YooAsset
assetInfos.Add(assetInfo);
}
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray());
var operation = new ResourceDownloaderOperation(_impl.Download, _impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), _impl.BuildinFileSystem, _impl.DeliveryFileSystem, _impl.CacheFileSystem);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
}
@@ -340,23 +303,23 @@ namespace YooAsset
public override ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
public override ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.Download, _impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
}
}
}

View File

@@ -1,13 +1,10 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace YooAsset
{
/// <summary>
/// 请求远端包裹的最新版本
/// 查询远端包裹的最新版本
/// </summary>
public abstract class UpdatePackageVersionOperation : AsyncOperationBase
public abstract class RequestPackageVersionOperation : AsyncOperationBase
{
/// <summary>
/// 当前最新的包裹版本
@@ -16,9 +13,9 @@ namespace YooAsset
}
/// <summary>
/// 编辑器下模拟模式的请求远端包裹的最新版本
/// 编辑器下模拟运行
/// </summary>
internal sealed class EditorPlayModeUpdatePackageVersionOperation : UpdatePackageVersionOperation
internal class EditorSimulateModeRequestPackageVersionOperation : RequestPackageVersionOperation
{
internal override void InternalOnStart()
{
@@ -30,9 +27,9 @@ namespace YooAsset
}
/// <summary>
/// 离线模式的请求远端包裹的最新版本
/// 离线运行模式
/// </summary>
internal sealed class OfflinePlayModeUpdatePackageVersionOperation : UpdatePackageVersionOperation
internal class OfflinePlayModeRequestPackageVersionOperation : RequestPackageVersionOperation
{
internal override void InternalOnStart()
{
@@ -44,24 +41,24 @@ namespace YooAsset
}
/// <summary>
/// 联机模式的请求远端包裹的最新版本
/// 联机运行模式
/// </summary>
internal sealed class HostPlayModeUpdatePackageVersionOperation : UpdatePackageVersionOperation
internal class HostPlayModeRequestPackageVersionOperation : RequestPackageVersionOperation
{
private enum ESteps
{
None,
QueryRemotePackageVersion,
QueryPackageVersion,
Done,
}
private readonly HostPlayModeImpl _impl;
private readonly bool _appendTimeTicks;
private readonly int _timeout;
private QueryRemotePackageVersionOperation _queryRemotePackageVersionOp;
private FSRequestPackageVersionOperation _queryPackageVersionOp;
private ESteps _steps = ESteps.None;
internal HostPlayModeUpdatePackageVersionOperation(HostPlayModeImpl impl, bool appendTimeTicks, int timeout)
internal HostPlayModeRequestPackageVersionOperation(HostPlayModeImpl impl, bool appendTimeTicks, int timeout)
{
_impl = impl;
_appendTimeTicks = appendTimeTicks;
@@ -69,27 +66,26 @@ namespace YooAsset
}
internal override void InternalOnStart()
{
_steps = ESteps.QueryRemotePackageVersion;
_steps = ESteps.QueryPackageVersion;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.QueryRemotePackageVersion)
if (_steps == ESteps.QueryPackageVersion)
{
if (_queryRemotePackageVersionOp == null)
if (_queryPackageVersionOp == null)
{
_queryRemotePackageVersionOp = new QueryRemotePackageVersionOperation(_impl.RemoteServices, _impl.PackageName, _appendTimeTicks, _timeout);
OperationSystem.StartOperation(_impl.PackageName, _queryRemotePackageVersionOp);
_queryPackageVersionOp = _impl.CacheFileSystem.RequestPackageVersionAsync(_appendTimeTicks, _timeout);
}
if (_queryRemotePackageVersionOp.IsDone == false)
if (_queryPackageVersionOp.IsDone == false)
return;
if (_queryRemotePackageVersionOp.Status == EOperationStatus.Succeed)
if (_queryPackageVersionOp.Status == EOperationStatus.Succeed)
{
PackageVersion = _queryRemotePackageVersionOp.PackageVersion;
PackageVersion = _queryPackageVersionOp.PackageVersion;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
@@ -97,31 +93,31 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _queryRemotePackageVersionOp.Error;
Error = _queryPackageVersionOp.Error;
}
}
}
}
/// <summary>
/// WebGL模式的请求远端包裹的最新版本
/// WebGL运行模式
/// </summary>
internal sealed class WebPlayModeUpdatePackageVersionOperation : UpdatePackageVersionOperation
internal class WebPlayModeRequestPackageVersionOperation : RequestPackageVersionOperation
{
private enum ESteps
{
None,
QueryRemotePackageVersion,
QueryPackageVersion,
Done,
}
private readonly WebPlayModeImpl _impl;
private readonly bool _appendTimeTicks;
private readonly int _timeout;
private QueryRemotePackageVersionOperation _queryRemotePackageVersionOp;
private FSRequestPackageVersionOperation _queryPackageVersionOp;
private ESteps _steps = ESteps.None;
internal WebPlayModeUpdatePackageVersionOperation(WebPlayModeImpl impl, bool appendTimeTicks, int timeout)
internal WebPlayModeRequestPackageVersionOperation(WebPlayModeImpl impl, bool appendTimeTicks, int timeout)
{
_impl = impl;
_appendTimeTicks = appendTimeTicks;
@@ -129,27 +125,26 @@ namespace YooAsset
}
internal override void InternalOnStart()
{
_steps = ESteps.QueryRemotePackageVersion;
_steps = ESteps.QueryPackageVersion;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.QueryRemotePackageVersion)
if (_steps == ESteps.QueryPackageVersion)
{
if (_queryRemotePackageVersionOp == null)
if (_queryPackageVersionOp == null)
{
_queryRemotePackageVersionOp = new QueryRemotePackageVersionOperation(_impl.RemoteServices, _impl.PackageName, _appendTimeTicks, _timeout);
OperationSystem.StartOperation(_impl.PackageName, _queryRemotePackageVersionOp);
_queryPackageVersionOp = _impl.WebFileSystem.RequestPackageVersionAsync(_appendTimeTicks, _timeout);
}
if (_queryRemotePackageVersionOp.IsDone == false)
if (_queryPackageVersionOp.IsDone == false)
return;
if (_queryRemotePackageVersionOp.Status == EOperationStatus.Succeed)
if (_queryPackageVersionOp.Status == EOperationStatus.Succeed)
{
PackageVersion = _queryRemotePackageVersionOp.PackageVersion;
PackageVersion = _queryPackageVersionOp.PackageVersion;
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
@@ -157,7 +152,7 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _queryRemotePackageVersionOp.Error;
Error = _queryPackageVersionOp.Error;
}
}
}

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;

namespace YooAsset
{
/// <summary>
@@ -9,18 +6,14 @@ namespace YooAsset
/// </summary>
public abstract class UpdatePackageManifestOperation : AsyncOperationBase
{
/// <summary>
/// 保存当前清单的版本,用于下次启动时自动加载的版本。
/// </summary>
public virtual void SavePackageVersion() { }
}
/// <summary>
/// 编辑器下模拟运行的更新清单操作
/// 编辑器下模拟运行
/// </summary>
internal sealed class EditorPlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
internal sealed class EditorSimulateModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
{
public EditorPlayModeUpdatePackageManifestOperation()
public EditorSimulateModeUpdatePackageManifestOperation()
{
}
internal override void InternalOnStart()
@@ -33,7 +26,7 @@ namespace YooAsset
}
/// <summary>
/// 离线模式的更新清单操作
/// 离线运行模式
/// </summary>
internal sealed class OfflinePlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
{
@@ -50,8 +43,7 @@ namespace YooAsset
}
/// <summary>
/// 联机模式的更新清单操作
/// 注意:优先加载沙盒里缓存的清单文件,如果缓存没找到就下载远端清单文件,并保存到本地。
/// 联机运行模式
/// </summary>
internal sealed class HostPlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
{
@@ -60,27 +52,21 @@ namespace YooAsset
None,
CheckParams,
CheckActiveManifest,
TryLoadCacheManifest,
DownloadManifest,
LoadCacheManifest,
LoadPackageManifest,
Done,
}
private readonly HostPlayModeImpl _impl;
private readonly string _packageVersion;
private readonly bool _autoSaveVersion;
private readonly int _timeout;
private LoadCacheManifestOperation _tryLoadCacheManifestOp;
private LoadCacheManifestOperation _loadCacheManifestOp;
private DownloadManifestOperation _downloadManifestOp;
private FSLoadPackageManifestOperation _loadPackageManifestOp;
private ESteps _steps = ESteps.None;
internal HostPlayModeUpdatePackageManifestOperation(HostPlayModeImpl impl, string packageVersion, bool autoSaveVersion, int timeout)
internal HostPlayModeUpdatePackageManifestOperation(HostPlayModeImpl impl, string packageVersion, int timeout)
{
_impl = impl;
_packageVersion = packageVersion;
_autoSaveVersion = autoSaveVersion;
_timeout = timeout;
}
internal override void InternalOnStart()
@@ -99,10 +85,11 @@ namespace YooAsset
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Package version is null or empty.";
return;
}
_steps = ESteps.CheckActiveManifest;
else
{
_steps = ESteps.CheckActiveManifest;
}
}
if (_steps == ESteps.CheckActiveManifest)
@@ -115,94 +102,36 @@ namespace YooAsset
}
else
{
_steps = ESteps.TryLoadCacheManifest;
_steps = ESteps.LoadPackageManifest;
}
}
if (_steps == ESteps.TryLoadCacheManifest)
if (_steps == ESteps.LoadPackageManifest)
{
if (_tryLoadCacheManifestOp == null)
{
_tryLoadCacheManifestOp = new LoadCacheManifestOperation(_impl.Persistent, _packageVersion);
OperationSystem.StartOperation(_impl.PackageName, _tryLoadCacheManifestOp);
}
if (_loadPackageManifestOp == null)
_loadPackageManifestOp = _impl.CacheFileSystem.LoadPackageManifestAsync(_packageVersion, _timeout);
if (_tryLoadCacheManifestOp.IsDone == false)
if (_loadPackageManifestOp.IsDone == false)
return;
if (_tryLoadCacheManifestOp.Status == EOperationStatus.Succeed)
{
_impl.ActiveManifest = _tryLoadCacheManifestOp.Manifest;
if (_autoSaveVersion)
SavePackageVersion();
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.DownloadManifest;
}
}
if (_steps == ESteps.DownloadManifest)
{
if (_downloadManifestOp == null)
{
_downloadManifestOp = new DownloadManifestOperation(_impl.Persistent, _impl.RemoteServices, _packageVersion, _timeout);
OperationSystem.StartOperation(_impl.PackageName, _downloadManifestOp);
}
if (_downloadManifestOp.IsDone == false)
return;
if (_downloadManifestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.LoadCacheManifest;
}
else
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _downloadManifestOp.Error;
}
}
if (_steps == ESteps.LoadCacheManifest)
{
if (_loadCacheManifestOp == null)
{
_loadCacheManifestOp = new LoadCacheManifestOperation(_impl.Persistent, _packageVersion);
OperationSystem.StartOperation(_impl.PackageName, _loadCacheManifestOp);
}
if (_loadCacheManifestOp.IsDone == false)
return;
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
{
_impl.ActiveManifest = _loadCacheManifestOp.Manifest;
if (_autoSaveVersion)
SavePackageVersion();
_steps = ESteps.Done;
_impl.ActiveManifest = _loadPackageManifestOp.Result;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadCacheManifestOp.Error;
Error = _loadPackageManifestOp.Error;
}
}
}
public override void SavePackageVersion()
{
_impl.FlushManifestVersionFile();
}
}
/// <summary>
/// WebGL模式的更新清单操作
/// WebGL运行模式
/// </summary>
internal sealed class WebPlayModeUpdatePackageManifestOperation : UpdatePackageManifestOperation
{
@@ -218,7 +147,7 @@ namespace YooAsset
private readonly WebPlayModeImpl _impl;
private readonly string _packageVersion;
private readonly int _timeout;
private LoadRemoteManifestOperation _loadCacheManifestOp;
private FSLoadPackageManifestOperation _loadPackageManifestOp;
private ESteps _steps = ESteps.None;
@@ -244,10 +173,11 @@ namespace YooAsset
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = "Package version is null or empty.";
return;
}
_steps = ESteps.CheckActiveManifest;
else
{
_steps = ESteps.CheckActiveManifest;
}
}
if (_steps == ESteps.CheckActiveManifest)
@@ -266,26 +196,23 @@ namespace YooAsset
if (_steps == ESteps.LoadRemoteManifest)
{
if (_loadCacheManifestOp == null)
{
_loadCacheManifestOp = new LoadRemoteManifestOperation(_impl.RemoteServices, _impl.PackageName, _packageVersion, _timeout);
OperationSystem.StartOperation(_impl.PackageName, _loadCacheManifestOp);
}
if (_loadPackageManifestOp == null)
_loadPackageManifestOp = _impl.WebFileSystem.LoadPackageManifestAsync(_packageVersion, _timeout);
if (_loadCacheManifestOp.IsDone == false)
if (_loadPackageManifestOp.IsDone == false)
return;
if (_loadCacheManifestOp.Status == EOperationStatus.Succeed)
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
{
_impl.ActiveManifest = _loadCacheManifestOp.Manifest;
_steps = ESteps.Done;
_impl.ActiveManifest = _loadPackageManifestOp.Result;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadCacheManifestOp.Error;
Error = _loadPackageManifestOp.Error;
}
}
}

View File

@@ -55,12 +55,12 @@ namespace YooAsset
/// <summary>
/// 所属的构建管线
/// </summary>
public string Buildpipeline { private set; get; }
public string BuildPipeline { private set; get; }
/// <summary>
/// 缓存GUID
/// 资源包GUID
/// </summary>
public string CacheGUID
public string BundleGUID
{
get { return FileHash; }
}
@@ -104,7 +104,7 @@ namespace YooAsset
public void ParseBundle(PackageManifest manifest)
{
PackageName = manifest.PackageName;
Buildpipeline = manifest.BuildPipeline;
BuildPipeline = manifest.BuildPipeline;
_fileExtension = ManifestTools.GetRemoteBundleFileExtension(BundleName);
_fileName = ManifestTools.GetRemoteBundleFileName(manifest.OutputNameStyle, BundleName, _fileExtension, FileHash);
}

View File

@@ -76,7 +76,7 @@ namespace YooAsset
public Dictionary<string, PackageBundle> BundleDic2;
/// <summary>
/// 资源包集合(提供CacheGUID获取PackageBundle
/// 资源包集合(提供BundleGUID获取PackageBundle
/// </summary>
[NonSerialized]
public Dictionary<string, PackageBundle> BundleDic3;
@@ -192,17 +192,17 @@ namespace YooAsset
/// <summary>
/// 尝试获取包裹的资源包
/// </summary>
public bool TryGetPackageBundleByCacheGUID(string cacheGUID, out PackageBundle result)
public bool TryGetPackageBundleByBundleGUID(string bundleGUID, out PackageBundle result)
{
return BundleDic3.TryGetValue(cacheGUID, out result);
return BundleDic3.TryGetValue(bundleGUID, out result);
}
/// <summary>
/// 是否包含资源文件
/// </summary>
public bool IsIncludeBundleFile(string cacheGUID)
public bool IsIncludeBundleFile(string bundleGUID)
{
return BundleDic3.ContainsKey(cacheGUID);
return BundleDic3.ContainsKey(bundleGUID);
}
/// <summary>

View File

@@ -6,14 +6,9 @@ namespace YooAsset
{
internal class EditorSimulateModeImpl : IPlayMode, IBundleQuery
{
private PackageManifest _activeManifest;
private ResourceAssist _assist;
public readonly string PackageName;
public DownloadManager Download
{
get { return _assist.Download; }
}
public IFileSystem EditorFileSystem { set; get; }
public EditorSimulateModeImpl(string packageName)
{
@@ -23,75 +18,89 @@ namespace YooAsset
/// <summary>
/// 异步初始化
/// </summary>
public InitializationOperation InitializeAsync(ResourceAssist assist, string simulateManifestFilePath)
public InitializationOperation InitializeAsync(EditorSimulateModeParameters initParameters)
{
_assist = assist;
var operation = new EditorSimulateModeInitializationOperation(this, simulateManifestFilePath);
var operation = new EditorSimulateModeInitializationOperation(this, initParameters);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
#region IPlayMode接口
public PackageManifest ActiveManifest
{
set
{
_activeManifest = value;
}
get
{
return _activeManifest;
}
}
public void FlushManifestVersionFile()
public PackageManifest ActiveManifest { set; get; }
void IPlayMode.UpdatePlayMode()
{
if (EditorFileSystem != null)
EditorFileSystem.OnUpdate();
}
UpdatePackageVersionOperation IPlayMode.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
{
var operation = new EditorPlayModeUpdatePackageVersionOperation();
var operation = new EditorSimulateModeRequestPackageVersionOperation();
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 EditorPlayModeUpdatePackageManifestOperation();
var operation = new EditorSimulateModeUpdatePackageManifestOperation();
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout)
{
var operation = new EditorPlayModePreDownloadContentOperation(this);
var operation = new EditorSimulateModePreDownloadContentOperation(this);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ClearAllBundleFilesOperation IPlayMode.ClearAllBundleFilesAsync()
{
var operation = new EditorSimulateModeClearAllBundleFilesOperation(this);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ClearUnusedBundleFilesOperation IPlayMode.ClearUnusedBundleFilesAsync()
{
var operation = new EditorSimulateModeClearUnusedBundleFilesOperation(this);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByAll(ActiveManifest, EditorFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByTags(ActiveManifest, tags, EditorFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByPaths(ActiveManifest, assetInfos, EditorFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
{
return ResourceUnpackerOperation.CreateEmptyUnpacker(Download, PackageName, upackingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> unpcakList = PlayModeHelper.GetUnpackListByAll(ActiveManifest, EditorFileSystem);
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, EditorFileSystem);
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, EditorFileSystem);
var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
return operation;
}
#endregion
@@ -101,9 +110,14 @@ namespace YooAsset
if (packageBundle == null)
throw new Exception("Should never get here !");
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromEditor);
bundleInfo.IncludeAssetsInEditor = _activeManifest.GetBundleIncludeAssets(assetInfo.AssetPath);
return bundleInfo;
if (EditorFileSystem.Belong(packageBundle))
{
BundleInfo bundleInfo = new BundleInfo(EditorFileSystem, packageBundle);
bundleInfo.IncludeAssetsInEditor = ActiveManifest.GetBundleIncludeAssets(assetInfo.AssetPath);
return bundleInfo;
}
throw new Exception($"Can not found belong file system : {packageBundle.BundleName}");
}
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
{
@@ -111,7 +125,7 @@ namespace YooAsset
throw new Exception("Should never get here !");
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = _activeManifest.GetMainPackageBundle(assetInfo.AssetPath);
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.AssetPath);
return CreateBundleInfo(packageBundle, assetInfo);
}
BundleInfo[] IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo)
@@ -120,7 +134,7 @@ 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)
{
@@ -135,7 +149,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)
@@ -144,7 +158,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)
{
@@ -154,7 +168,7 @@ namespace YooAsset
}
bool IBundleQuery.ManifestValid()
{
return _activeManifest != null;
return ActiveManifest != null;
}
#endregion
}

View File

@@ -6,29 +6,10 @@ namespace YooAsset
{
internal class HostPlayModeImpl : IPlayMode, IBundleQuery
{
private PackageManifest _activeManifest;
private ResourceAssist _assist;
private IBuildinQueryServices _buildinQueryServices;
private IDeliveryQueryServices _deliveryQueryServices;
private IRemoteServices _remoteServices;
public readonly string PackageName;
public DownloadManager Download
{
get { return _assist.Download; }
}
public PersistentManager Persistent
{
get { return _assist.Persistent; }
}
public CacheManager Cache
{
get { return _assist.Cache; }
}
public IRemoteServices RemoteServices
{
get { return _remoteServices; }
}
public IFileSystem BuildinFileSystem { set; get; }
public IFileSystem DeliveryFileSystem { set; get; } //可以为空!
public IFileSystem CacheFileSystem { set; get; }
public HostPlayModeImpl(string packageName)
@@ -39,82 +20,37 @@ namespace YooAsset
/// <summary>
/// 异步初始化
/// </summary>
public InitializationOperation InitializeAsync(ResourceAssist assist, IBuildinQueryServices buildinQueryServices, IDeliveryQueryServices deliveryQueryServices, IRemoteServices remoteServices)
public InitializationOperation InitializeAsync(HostPlayModeParameters initParameters)
{
_assist = assist;
_buildinQueryServices = buildinQueryServices;
_deliveryQueryServices = deliveryQueryServices;
_remoteServices = remoteServices;
var operation = new HostPlayModeInitializationOperation(this);
var operation = new HostPlayModeInitializationOperation(this, initParameters);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
// 下载相关
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 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 bool IsDeliveryPackageBundle(PackageBundle packageBundle)
{
if (_deliveryQueryServices == null)
return false;
return _deliveryQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
}
private bool IsCachedPackageBundle(PackageBundle packageBundle)
{
return _assist.Cache.IsCached(packageBundle.CacheGUID);
}
private bool IsBuildinPackageBundle(PackageBundle packageBundle)
{
return _buildinQueryServices.Query(PackageName, packageBundle.FileName, packageBundle.FileCRC);
}
#region IPlayMode接口
public PackageManifest ActiveManifest
public PackageManifest ActiveManifest { set; get; }
void IPlayMode.UpdatePlayMode()
{
set
{
_activeManifest = value;
}
get
{
return _activeManifest;
}
}
public void FlushManifestVersionFile()
{
if (_activeManifest != null)
{
_assist.Persistent.SaveSandboxPackageVersionFile(_activeManifest.PackageVersion);
}
if (BuildinFileSystem != null)
BuildinFileSystem.OnUpdate();
if (DeliveryFileSystem != null)
DeliveryFileSystem.OnUpdate();
if (CacheFileSystem != null)
CacheFileSystem.OnUpdate();
}
UpdatePackageVersionOperation IPlayMode.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
{
var operation = new HostPlayModeUpdatePackageVersionOperation(this, appendTimeTicks, timeout);
var operation = new HostPlayModeRequestPackageVersionOperation(this, 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 HostPlayModeUpdatePackageManifestOperation(this, packageVersion, autoSaveVersion, timeout);
var operation = new HostPlayModeUpdatePackageManifestOperation(this, packageVersion, timeout);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
@@ -125,241 +61,80 @@ namespace YooAsset
return operation;
}
ClearAllBundleFilesOperation IPlayMode.ClearAllBundleFilesAsync()
{
var operation = new HostPlayModeClearAllBundleFilesOperation(this);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ClearUnusedBundleFilesOperation IPlayMode.ClearUnusedBundleFilesAsync()
{
var operation = new HostPlayModeClearUnusedBundleFilesOperation(this);
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, BuildinFileSystem, DeliveryFileSystem, CacheFileSystem);
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 (IsDeliveryPackageBundle(packageBundle))
continue;
// 忽略缓存文件
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, BuildinFileSystem, DeliveryFileSystem, CacheFileSystem);
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 (IsDeliveryPackageBundle(packageBundle))
continue;
// 忽略缓存文件
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, BuildinFileSystem, DeliveryFileSystem, CacheFileSystem);
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 (IsDeliveryPackageBundle(packageBundle))
continue;
// 忽略缓存文件
if (IsCachedPackageBundle(packageBundle))
continue;
// 忽略APP资源
if (IsBuildinPackageBundle(packageBundle))
continue;
downloadList.Add(packageBundle);
}
return ConvertToDownloadList(downloadList);
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> unpcakList = GetUnpackListByAll(_activeManifest);
var operation = new ResourceUnpackerOperation(Download, PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> unpcakList = PlayModeHelper.GetUnpackListByAll(ActiveManifest, BuildinFileSystem, DeliveryFileSystem, CacheFileSystem);
var operation = new ResourceUnpackerOperation(PackageName, 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;
if (IsBuildinPackageBundle(packageBundle))
{
downloadList.Add(packageBundle);
}
}
return BundleInfo.CreateUnpackInfos(_assist, downloadList);
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> unpcakList = GetUnpackListByTags(_activeManifest, tags);
var operation = new ResourceUnpackerOperation(Download, PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> unpcakList = PlayModeHelper.GetUnpackListByTags(ActiveManifest, tags, BuildinFileSystem, DeliveryFileSystem, CacheFileSystem);
var operation = new ResourceUnpackerOperation(PackageName, 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 (IsBuildinPackageBundle(packageBundle))
{
if (packageBundle.HasTag(tags))
{
downloadList.Add(packageBundle);
}
}
}
return BundleInfo.CreateUnpackInfos(_assist, downloadList);
}
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> importerList = GetImporterListByFilePaths(_activeManifest, filePaths);
var operation = new ResourceImporterOperation(Download, PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
List<BundleInfo> importerList = PlayModeHelper.GetImporterListByFilePaths(ActiveManifest, filePaths, BuildinFileSystem, DeliveryFileSystem, CacheFileSystem);
var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
return operation;
}
private List<BundleInfo> GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths)
{
List<BundleInfo> result = new List<BundleInfo>();
foreach (var filePath in filePaths)
{
string fileName = System.IO.Path.GetFileName(filePath);
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle))
{
// 忽略缓存文件
if (IsCachedPackageBundle(packageBundle))
continue;
var bundleInfo = BundleInfo.CreateImportInfo(_assist, packageBundle, filePath);
result.Add(bundleInfo);
}
else
{
YooLogger.Warning($"Not found package bundle, importer file path : {filePath}");
}
}
return result;
}
#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 !");
// 查询分发资源
if (IsDeliveryPackageBundle(packageBundle))
if (BuildinFileSystem.Belong(packageBundle))
{
string deliveryFilePath = _deliveryQueryServices.GetFilePath(PackageName, packageBundle.FileName);
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromDelivery, deliveryFilePath);
BundleInfo bundleInfo = new BundleInfo(BuildinFileSystem, packageBundle);
return bundleInfo;
}
if (DeliveryFileSystem != null && DeliveryFileSystem.Belong(packageBundle))
{
BundleInfo bundleInfo = new BundleInfo(DeliveryFileSystem, packageBundle);
return bundleInfo;
}
if (CacheFileSystem.Belong(packageBundle))
{
BundleInfo bundleInfo = new BundleInfo(CacheFileSystem, packageBundle);
return bundleInfo;
}
// 查询沙盒资源
if (IsCachedPackageBundle(packageBundle))
{
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromCache);
return bundleInfo;
}
// 查询APP资源
if (IsBuildinPackageBundle(packageBundle))
{
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromStreaming);
return bundleInfo;
}
// 从服务端下载
return ConvertToDownloadInfo(packageBundle);
throw new Exception($"Can not found belong file system : {packageBundle.BundleName}");
}
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
{
@@ -367,8 +142,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)
{
@@ -376,11 +151,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();
@@ -391,7 +166,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)
@@ -400,7 +175,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)
{
@@ -410,7 +185,7 @@ namespace YooAsset
}
bool IBundleQuery.ManifestValid()
{
return _activeManifest != null;
return ActiveManifest != null;
}
#endregion
}

View File

@@ -6,22 +6,8 @@ namespace YooAsset
{
internal class OfflinePlayModeImpl : IPlayMode, IBundleQuery
{
private PackageManifest _activeManifest;
private ResourceAssist _assist;
public readonly string PackageName;
public DownloadManager Download
{
get { return _assist.Download; }
}
public PersistentManager Persistent
{
get { return _assist.Persistent; }
}
public CacheManager Cache
{
get { return _assist.Cache; }
}
public IFileSystem BuildinFileSystem { set; get; }
public OfflinePlayModeImpl(string packageName)
@@ -32,44 +18,29 @@ namespace YooAsset
/// <summary>
/// 异步初始化
/// </summary>
public InitializationOperation InitializeAsync(ResourceAssist assist)
public InitializationOperation InitializeAsync(OfflinePlayModeParameters initParameters)
{
_assist = assist;
var operation = new OfflinePlayModeInitializationOperation(this);
var operation = new OfflinePlayModeInitializationOperation(this, initParameters);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
// 查询相关
private bool IsCachedPackageBundle(PackageBundle packageBundle)
{
return _assist.Cache.IsCached(packageBundle.CacheGUID);
}
#region IPlayMode接口
public PackageManifest ActiveManifest
{
set
{
_activeManifest = value;
}
get
{
return _activeManifest;
}
}
public void FlushManifestVersionFile()
public PackageManifest ActiveManifest { set; get; }
void IPlayMode.UpdatePlayMode()
{
if (BuildinFileSystem != null)
BuildinFileSystem.OnUpdate();
}
UpdatePackageVersionOperation IPlayMode.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
{
var operation = new OfflinePlayModeUpdatePackageVersionOperation();
var operation = new OfflinePlayModeRequestPackageVersionOperation();
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 OfflinePlayModeUpdatePackageManifestOperation();
OperationSystem.StartOperation(PackageName, operation);
@@ -82,113 +53,70 @@ namespace YooAsset
return operation;
}
ClearAllBundleFilesOperation IPlayMode.ClearAllBundleFilesAsync()
{
var operation = new OfflinePlayModeClearAllBundleFilesOperation(this);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ClearUnusedBundleFilesOperation IPlayMode.ClearUnusedBundleFilesAsync()
{
var operation = new OfflinePlayModeClearUnusedBundleFilesOperation(this);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByAll(ActiveManifest, BuildinFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByTags(ActiveManifest, tags, BuildinFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(Download, PackageName, downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = PlayModeHelper.GetDownloadListByPaths(ActiveManifest, assetInfos, BuildinFileSystem);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> unpcakList = GetUnpackListByAll(_activeManifest);
var operation = new ResourceUnpackerOperation(Download, PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> unpcakList = PlayModeHelper.GetUnpackListByAll(ActiveManifest, BuildinFileSystem);
var operation = new ResourceUnpackerOperation(PackageName, 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 BundleInfo.CreateUnpackInfos(_assist, downloadList);
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> unpcakList = GetUnpackListByTags(_activeManifest, tags);
var operation = new ResourceUnpackerOperation(Download, PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> unpcakList = PlayModeHelper.GetUnpackListByTags(ActiveManifest, tags, BuildinFileSystem);
var operation = new ResourceUnpackerOperation(PackageName, 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 BundleInfo.CreateUnpackInfos(_assist, downloadList);
}
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
{
List<BundleInfo> importerList = GetImporterListByFilePaths(_activeManifest, filePaths);
var operation = new ResourceImporterOperation(Download, PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
List<BundleInfo> importerList = PlayModeHelper.GetImporterListByFilePaths(ActiveManifest, filePaths, BuildinFileSystem);
var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
return operation;
}
private List<BundleInfo> GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths)
{
List<BundleInfo> result = new List<BundleInfo>();
foreach (var filePath in filePaths)
{
string fileName = System.IO.Path.GetFileName(filePath);
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle))
{
// 忽略缓存文件
if (IsCachedPackageBundle(packageBundle))
continue;
var bundleInfo = BundleInfo.CreateImportInfo(_assist, packageBundle, filePath);
result.Add(bundleInfo);
}
else
{
YooLogger.Warning($"Not found package bundle, importer file path : {filePath}");
}
}
return result;
}
#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 !");
// 查询沙盒资源
if (IsCachedPackageBundle(packageBundle))
if (BuildinFileSystem.Belong(packageBundle))
{
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromCache);
BundleInfo bundleInfo = new BundleInfo(BuildinFileSystem, packageBundle);
return bundleInfo;
}
// 查询APP资源
{
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromStreaming);
return bundleInfo;
}
throw new Exception($"Can not found belong file system : {packageBundle.BundleName}");
}
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
{
@@ -196,8 +124,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)
{
@@ -205,11 +133,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();
@@ -220,7 +148,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)
@@ -229,7 +157,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)
{
@@ -239,7 +167,7 @@ namespace YooAsset
}
bool IBundleQuery.ManifestValid()
{
return _activeManifest != null;
return ActiveManifest != null;
}
#endregion
}

View File

@@ -0,0 +1,282 @@
using System;
using System.Collections.Generic;
namespace YooAsset
{
internal class PlayModeHelper
{
public static IFileSystem CreateFileSystem(string packageName, FileSystemParameters parameters)
{
Type classType = Type.GetType(parameters.FileSystemClass);
if (classType == null)
{
YooLogger.Error($"Not found file system class type {parameters.FileSystemClass}");
return null;
}
var instance = (IFileSystem)System.Activator.CreateInstance(classType, true);
if (instance == null)
{
YooLogger.Error($"Failed to create file system instance {parameters.FileSystemClass}");
return null;
}
foreach (var param in parameters.CreateParameters)
{
instance.SetParameter(param.Key, param.Value);
}
instance.OnCreate(packageName, parameters.RootDirectory);
return instance;
}
public static List<BundleInfo> GetDownloadListByAll(PackageManifest manifest, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null)
{
List<BundleInfo> result = new List<BundleInfo>(1000);
foreach (var packageBundle in manifest.BundleList)
{
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
if (fileSystemA.CheckNeedDownload(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
if (fileSystemB.CheckNeedDownload(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
if (fileSystemC.CheckNeedDownload(packageBundle))
fileSystem = fileSystemC;
}
else
{
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
}
if (fileSystem == null)
continue;
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
return result;
}
public static List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null)
{
List<BundleInfo> result = new List<BundleInfo>(1000);
foreach (var packageBundle in manifest.BundleList)
{
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
if (fileSystemA.CheckNeedDownload(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
if (fileSystemB.CheckNeedDownload(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
if (fileSystemC.CheckNeedDownload(packageBundle))
fileSystem = fileSystemC;
}
else
{
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
}
if (fileSystem == null)
continue;
// 如果未带任何标记,则统一下载
if (packageBundle.HasAnyTags() == false)
{
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
else
{
// 查询DLC资源
if (packageBundle.HasTag(tags))
{
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
}
}
return result;
}
public static List<BundleInfo> GetDownloadListByPaths(PackageManifest manifest, AssetInfo[] assetInfos, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null)
{
// 获取资源对象的资源包和所有依赖资源包
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<BundleInfo> result = new List<BundleInfo>(1000);
foreach (var packageBundle in checkList)
{
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
if (fileSystemA.CheckNeedDownload(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
if (fileSystemB.CheckNeedDownload(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
if (fileSystemC.CheckNeedDownload(packageBundle))
fileSystem = fileSystemC;
}
else
{
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
}
if (fileSystem == null)
continue;
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
return result;
}
public static List<BundleInfo> GetUnpackListByAll(PackageManifest manifest, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null)
{
List<BundleInfo> result = new List<BundleInfo>(1000);
foreach (var packageBundle in manifest.BundleList)
{
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
if (fileSystemA.CheckNeedUnpack(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
if (fileSystemB.CheckNeedUnpack(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
if (fileSystemC.CheckNeedUnpack(packageBundle))
fileSystem = fileSystemC;
}
else
{
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
}
if (fileSystem == null)
continue;
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
return result;
}
public static List<BundleInfo> GetUnpackListByTags(PackageManifest manifest, string[] tags, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null)
{
List<BundleInfo> result = new List<BundleInfo>(1000);
foreach (var packageBundle in manifest.BundleList)
{
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
if (fileSystemA.CheckNeedUnpack(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
if (fileSystemB.CheckNeedUnpack(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
if (fileSystemC.CheckNeedUnpack(packageBundle))
fileSystem = fileSystemC;
}
else
{
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
}
if (fileSystem == null)
continue;
// 查询DLC资源
if (packageBundle.HasTag(tags))
{
var bundleInfo = new BundleInfo(fileSystem, packageBundle);
result.Add(bundleInfo);
}
}
return result;
}
public static List<BundleInfo> GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths, IFileSystem fileSystemA = null, IFileSystem fileSystemB = null, IFileSystem fileSystemC = null)
{
List<BundleInfo> result = new List<BundleInfo>();
foreach (var filePath in filePaths)
{
string fileName = System.IO.Path.GetFileName(filePath);
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle))
{
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
if (fileSystemA.CheckNeedImport(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
if (fileSystemB.CheckNeedImport(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
if (fileSystemC.CheckNeedImport(packageBundle))
fileSystem = fileSystemC;
}
else
{
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
}
if (fileSystem == null)
continue;
var bundleInfo = new BundleInfo(fileSystem, packageBundle, filePath);
result.Add(bundleInfo);
}
else
{
YooLogger.Warning($"Not found package bundle, importer file path : {filePath}");
}
}
return result;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: f3a2fe7d8d4747d43b3ac48097341e36
guid: fbbce8ae4b0d0784683413d6466d27f8
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -6,25 +6,8 @@ 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 WebFileSystem { set; get; }
public WebPlayModeImpl(string packageName)
@@ -35,73 +18,29 @@ 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 (WebFileSystem != null)
WebFileSystem.OnUpdate();
}
UpdatePackageVersionOperation IPlayMode.UpdatePackageVersionAsync(bool appendTimeTicks, int timeout)
RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
{
var operation = new WebPlayModeUpdatePackageVersionOperation(this, appendTimeTicks, timeout);
var operation = new WebPlayModeRequestPackageVersionOperation(this, 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);
@@ -114,147 +53,70 @@ namespace YooAsset
return operation;
}
ClearAllBundleFilesOperation IPlayMode.ClearAllBundleFilesAsync()
{
var operation = new WebPlayModeClearAllBundleFilesOperation(this);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
ClearUnusedBundleFilesOperation IPlayMode.ClearUnusedBundleFilesAsync()
{
var operation = new WebPlayModeClearUnusedBundleFilesOperation(this);
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, WebFileSystem);
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, WebFileSystem);
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, WebFileSystem);
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, WebFileSystem);
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, WebFileSystem);
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, WebFileSystem);
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 (WebFileSystem.Belong(packageBundle))
{
BundleInfo bundleInfo = new BundleInfo(_assist, packageBundle, BundleInfo.ELoadMode.LoadFromStreaming);
BundleInfo bundleInfo = new BundleInfo(WebFileSystem, packageBundle);
return bundleInfo;
}
// 从服务端下载
return ConvertToDownloadInfo(packageBundle);
throw new Exception($"Can not found belong file system : {packageBundle.BundleName}");
}
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
{
@@ -262,8 +124,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 +133,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 +148,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 +157,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 +167,7 @@ namespace YooAsset
}
bool IBundleQuery.ManifestValid()
{
return _activeManifest != null;
return ActiveManifest != null;
}
#endregion
}

View File

@@ -1,11 +0,0 @@

namespace YooAsset
{
internal class ResourceAssist
{
public CacheManager Cache { set; get; }
public PersistentManager Persistent { set; get; }
public DownloadManager Download { set; get; }
public ResourceLoader Loader { set; get; }
}
}

View File

@@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 395d187f862588340b6fe7c437f477ec
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -14,11 +14,7 @@ namespace YooAsset
private EPlayMode _playMode;
// 管理器
private CacheManager _cacheMgr;
private PersistentManager _persistentMgr;
private DownloadManager _downloadMgr;
private ResourceManager _resourceMgr;
private ResourceLoader _resourceLoader;
private ResourceManager _resourceManager;
private IBundleQuery _bundleQuery;
private IPlayMode _playModeImpl;
@@ -36,9 +32,6 @@ namespace YooAsset
}
private ResourcePackage()
{
}
internal ResourcePackage(string packageName)
{
PackageName = packageName;
@@ -49,11 +42,11 @@ namespace YooAsset
/// </summary>
internal void UpdatePackage()
{
if (_resourceMgr != null)
_resourceMgr.Update();
if (_resourceManager != null)
_resourceManager.Update();
if (_downloadMgr != null)
_downloadMgr.Update();
if (_playModeImpl != null)
_playModeImpl.UpdatePlayMode();
}
/// <summary>
@@ -67,32 +60,9 @@ namespace YooAsset
_initializeError = string.Empty;
_initializeStatus = EOperationStatus.None;
_resourceManager = null;
_bundleQuery = null;
_playModeImpl = null;
_persistentMgr = null;
_resourceLoader = null;
if (_resourceMgr != null)
{
_resourceMgr.ForceUnloadAllAssets();
_resourceMgr = null;
}
if (_downloadMgr != null)
{
_downloadMgr.DestroyAll();
_downloadMgr = null;
}
if (_cacheMgr != null)
{
_cacheMgr.ClearAll();
_cacheMgr = null;
}
// 最后清理该包裹的异步任务
// 注意:对于有线程操作的异步任务,需要保证线程安全释放。
OperationSystem.ClearPackageOperation(PackageName);
}
}
@@ -101,91 +71,54 @@ namespace YooAsset
/// </summary>
public InitializationOperation InitializeAsync(InitializeParameters parameters)
{
// 注意:WebGL平台因为网络原因可能会初始化失败!
// 注意:联机平台因为网络原因可能会初始化失败!
ResetInitializeAfterFailed();
// 检测初始化参数合法性
CheckInitializeParameters(parameters);
// 创建缓存管理器
_cacheMgr = new CacheManager(PackageName, parameters.CacheBootVerifyLevel);
// 创建持久化管理器
_persistentMgr = new PersistentManager(PackageName);
_persistentMgr.Initialize(parameters.BuildinRootDirectory, parameters.SandboxRootDirectory, parameters.CacheFileAppendExtension);
// 创建下载管理器
_downloadMgr = new DownloadManager(PackageName);
_downloadMgr.Initialize(parameters.BreakpointResumeFileSize);
// 创建资源包加载器
if (_playMode == EPlayMode.HostPlayMode)
{
var initializeParameters = parameters as HostPlayModeParameters;
_resourceLoader = new ResourceLoader();
_resourceLoader.Init(parameters.DecryptionServices, initializeParameters.DeliveryLoadServices);
}
else
{
_resourceLoader = new ResourceLoader();
_resourceLoader.Init(parameters.DecryptionServices, null);
}
// 创建资源协助类
ResourceAssist assist = new ResourceAssist();
assist.Cache = _cacheMgr;
assist.Persistent = _persistentMgr;
assist.Download = _downloadMgr;
assist.Loader = _resourceLoader;
// 创建资源管理器
InitializationOperation initializeOperation;
_resourceMgr = new ResourceManager(PackageName);
_resourceManager = new ResourceManager(PackageName);
if (_playMode == EPlayMode.EditorSimulateMode)
{
var editorSimulateModeImpl = new EditorSimulateModeImpl(PackageName);
_bundleQuery = editorSimulateModeImpl;
_playModeImpl = editorSimulateModeImpl;
_resourceMgr.Initialize(true, parameters.AutoDestroyAssetProvider, _bundleQuery);
_resourceManager.Initialize(parameters, _bundleQuery);
var initializeParameters = parameters as EditorSimulateModeParameters;
initializeOperation = editorSimulateModeImpl.InitializeAsync(assist, initializeParameters.SimulateManifestFilePath);
initializeOperation = editorSimulateModeImpl.InitializeAsync(initializeParameters);
}
else if (_playMode == EPlayMode.OfflinePlayMode)
{
var offlinePlayModeImpl = new OfflinePlayModeImpl(PackageName);
_bundleQuery = offlinePlayModeImpl;
_playModeImpl = offlinePlayModeImpl;
_resourceMgr.Initialize(false, parameters.AutoDestroyAssetProvider, _bundleQuery);
_resourceManager.Initialize(parameters, _bundleQuery);
var initializeParameters = parameters as OfflinePlayModeParameters;
initializeOperation = offlinePlayModeImpl.InitializeAsync(assist);
initializeOperation = offlinePlayModeImpl.InitializeAsync(initializeParameters);
}
else if (_playMode == EPlayMode.HostPlayMode)
{
var hostPlayModeImpl = new HostPlayModeImpl(PackageName);
_bundleQuery = hostPlayModeImpl;
_playModeImpl = hostPlayModeImpl;
_resourceMgr.Initialize(false, parameters.AutoDestroyAssetProvider, _bundleQuery);
_resourceManager.Initialize(parameters, _bundleQuery);
var initializeParameters = parameters as HostPlayModeParameters;
initializeOperation = hostPlayModeImpl.InitializeAsync(assist,
initializeParameters.BuildinQueryServices,
initializeParameters.DeliveryQueryServices,
initializeParameters.RemoteServices);
initializeOperation = hostPlayModeImpl.InitializeAsync(initializeParameters);
}
else if (_playMode == EPlayMode.WebPlayMode)
{
var webPlayModeImpl = new WebPlayModeImpl(PackageName);
_bundleQuery = webPlayModeImpl;
_playModeImpl = webPlayModeImpl;
_resourceMgr.Initialize(false, parameters.AutoDestroyAssetProvider, _bundleQuery);
_resourceManager.Initialize(parameters, _bundleQuery);
var initializeParameters = parameters as WebPlayModeParameters;
initializeOperation = webPlayModeImpl.InitializeAsync(assist,
initializeParameters.BuildinQueryServices,
initializeParameters.RemoteServices,
initializeParameters.WechatQueryServices);
initializeOperation = webPlayModeImpl.InitializeAsync(initializeParameters);
}
else
{
@@ -219,27 +152,6 @@ namespace YooAsset
throw new Exception($"Editor simulate mode only support unity editor.");
#endif
if (parameters is EditorSimulateModeParameters)
{
var editorSimulateModeParameters = parameters as EditorSimulateModeParameters;
if (string.IsNullOrEmpty(editorSimulateModeParameters.SimulateManifestFilePath))
throw new Exception($"{nameof(editorSimulateModeParameters.SimulateManifestFilePath)} is null or empty.");
}
if (parameters is HostPlayModeParameters)
{
var hostPlayModeParameters = parameters as HostPlayModeParameters;
if (hostPlayModeParameters.RemoteServices == null)
throw new Exception($"{nameof(IRemoteServices)} is null.");
if (hostPlayModeParameters.BuildinQueryServices == null)
throw new Exception($"{nameof(IBuildinQueryServices)} is null.");
if (hostPlayModeParameters.DeliveryQueryServices != null)
{
if (hostPlayModeParameters.DeliveryLoadServices == null)
throw new Exception($"{nameof(IDeliveryLoadServices)} is null.");
}
}
// 鉴定运行模式
if (parameters is EditorSimulateModeParameters)
_playMode = EPlayMode.EditorSimulateMode;
@@ -258,7 +170,7 @@ namespace YooAsset
#if UNITY_WEBGL
if (_playMode != EPlayMode.WebPlayMode)
{
throw new Exception($"{_playMode} can not support WebGL plateform ! Please use {nameof(EPlayMode.WebPlayMode)}");
throw new Exception($"{_playMode} can not support WebGL plateform !");
}
#else
if (_playMode == EPlayMode.WebPlayMode)
@@ -274,34 +186,43 @@ namespace YooAsset
_initializeError = op.Error;
}
/// <summary>
/// 异步销毁
/// </summary>
public DestroyOperation DestroyAsync()
{
var operation = new DestroyOperation(this);
OperationSystem.StartOperation(null, operation);
return operation;
}
/// <summary>
/// 向网络端请求最新的资源版本
/// </summary>
/// <param name="appendTimeTicks">在URL末尾添加时间戳</param>
/// <param name="timeout">超时时间默认值60秒</param>
public UpdatePackageVersionOperation UpdatePackageVersionAsync(bool appendTimeTicks = true, int timeout = 60)
public RequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks = true, int timeout = 60)
{
DebugCheckInitialize(false);
return _playModeImpl.UpdatePackageVersionAsync(appendTimeTicks, timeout);
return _playModeImpl.RequestPackageVersionAsync(appendTimeTicks, timeout);
}
/// <summary>
/// 向网络端请求并更新清单
/// </summary>
/// <param name="packageVersion">更新的包裹版本</param>
/// <param name="autoSaveVersion">更新成功后自动保存版本号,作为下次初始化的版本。</param>
/// <param name="timeout">超时时间默认值60秒</param>
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, bool autoSaveVersion = true, int timeout = 60)
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout = 60)
{
DebugCheckInitialize(false);
// 注意:强烈建议在更新之前保持加载器为空!
if (_resourceMgr.HasAnyLoader())
if (_resourceManager.HasAnyLoader())
{
YooLogger.Warning($"Found loaded bundle before update manifest ! Recommended to call the {nameof(ForceUnloadAllAssets)} method to release loaded bundle !");
YooLogger.Warning($"Found loaded bundle before update manifest ! Recommended to call the {nameof(UnloadAllAssetsAsync)} method to release loaded bundle !");
}
return _playModeImpl.UpdatePackageManifestAsync(packageVersion, autoSaveVersion, timeout);
return _playModeImpl.UpdatePackageManifestAsync(packageVersion, timeout);
}
/// <summary>
@@ -315,6 +236,24 @@ namespace YooAsset
return _playModeImpl.PreDownloadContentAsync(packageVersion, timeout);
}
/// <summary>
/// 清理文件系统所有的资源文件
/// </summary>
public ClearAllBundleFilesOperation ClearAllBundleFilesAsync()
{
DebugCheckInitialize();
return _playModeImpl.ClearAllBundleFilesAsync();
}
/// <summary>
/// 清理文件系统未使用的资源文件
/// </summary>
public ClearUnusedBundleFilesOperation ClearUnusedBundleFilesAsync()
{
DebugCheckInitialize();
return _playModeImpl.ClearUnusedBundleFilesAsync();
}
/// <summary>
/// 获取本地包裹的版本信息
/// </summary>
@@ -324,106 +263,49 @@ namespace YooAsset
return _playModeImpl.ActiveManifest.PackageVersion;
}
#region
#region
/// <summary>
/// 资源回收(卸载引用计数为零的资源
/// 强制回收所有资源
/// </summary>
public void UnloadUnusedAssets()
public UnloadAllAssetsOperation UnloadAllAssetsAsync()
{
DebugCheckInitialize();
_resourceMgr.UnloadUnusedAssets();
var operation = new UnloadAllAssetsOperation(_resourceManager);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
/// <summary>
/// 资源回收(尝试卸载指定的资源
/// 回收不再使用的资源
/// 说明:卸载引用计数为零的资源
/// </summary>
public UnloadUnusedAssetsOperation UnloadUnusedAssetsAsync()
{
DebugCheckInitialize();
var operation = new UnloadUnusedAssetsOperation(_resourceManager);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
/// <summary>
/// 资源回收
/// 说明:尝试卸载指定的资源
/// </summary>
public void TryUnloadUnusedAsset(string location)
{
DebugCheckInitialize();
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
_resourceMgr.TryUnloadUnusedAsset(assetInfo);
_resourceManager.TryUnloadUnusedAsset(assetInfo);
}
/// <summary>
/// 资源回收(尝试卸载指定的资源)
/// 资源回收
/// 说明:尝试卸载指定的资源
/// </summary>
public void TryUnloadUnusedAsset(AssetInfo assetInfo)
{
DebugCheckInitialize();
_resourceMgr.TryUnloadUnusedAsset(assetInfo);
}
/// <summary>
/// 强制回收所有资源
/// </summary>
public void ForceUnloadAllAssets()
{
DebugCheckInitialize();
_resourceMgr.ForceUnloadAllAssets();
}
#endregion
#region
/// <summary>
/// 获取包裹的内置文件根路径
/// </summary>
public string GetPackageBuildinRootDirectory()
{
DebugCheckInitialize();
return _persistentMgr.BuildinRoot;
}
/// <summary>
/// 获取包裹的沙盒文件根路径
/// </summary>
public string GetPackageSandboxRootDirectory()
{
DebugCheckInitialize();
return _persistentMgr.SandboxRoot;
}
/// <summary>
/// 清空包裹的沙盒目录
/// </summary>
public void ClearPackageSandbox()
{
DebugCheckInitialize();
_persistentMgr.DeleteSandboxPackageFolder();
_cacheMgr.ClearAll();
}
/// <summary>
/// 清理包裹未使用的缓存文件
/// </summary>
public ClearUnusedCacheFilesOperation ClearUnusedCacheFilesAsync()
{
DebugCheckInitialize();
var operation = new ClearUnusedCacheFilesOperation(this, _cacheMgr);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
/// <summary>
/// 清理包裹本地所有的缓存文件
/// </summary>
public ClearAllCacheFilesOperation ClearAllCacheFilesAsync()
{
DebugCheckInitialize();
var operation = new ClearAllCacheFilesOperation(_cacheMgr);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
/// <summary>
/// 获取指定版本的缓存信息
/// </summary>
public GetAllCacheFileInfosOperation GetAllCacheFileInfosAsync(string packageVersion)
{
DebugCheckInitialize();
var operation = new GetAllCacheFileInfosOperation(_persistentMgr, _cacheMgr, packageVersion);
OperationSystem.StartOperation(PackageName, operation);
return operation;
_resourceManager.TryUnloadUnusedAsset(assetInfo);
}
#endregion
@@ -532,13 +414,13 @@ namespace YooAsset
}
BundleInfo bundleInfo = _bundleQuery.GetMainBundleInfo(assetInfo);
if (bundleInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
if (bundleInfo.IsNeedDownloadFromRemote())
return true;
BundleInfo[] depends = _bundleQuery.GetDependBundleInfos(assetInfo);
foreach (var depend in depends)
{
if (depend.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
if (depend.IsNeedDownloadFromRemote())
return true;
}
@@ -594,8 +476,7 @@ namespace YooAsset
private RawFileHandle LoadRawFileInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
{
DebugCheckRawFileLoadMethod(nameof(LoadRawFileAsync));
var handle = _resourceMgr.LoadRawFileAsync(assetInfo, priority);
var handle = _resourceManager.LoadRawFileAsync(assetInfo, priority);
if (waitForAsyncComplete)
handle.WaitForAsyncComplete();
return handle;
@@ -655,9 +536,8 @@ namespace YooAsset
private SceneHandle LoadSceneInternal(AssetInfo assetInfo, bool waitForAsyncComplete, LoadSceneMode sceneMode, bool suspendLoad, uint priority)
{
DebugCheckAssetLoadMethod(nameof(LoadAssetAsync));
DebugCheckAssetLoadType(assetInfo.AssetType);
var handle = _resourceMgr.LoadSceneAsync(assetInfo, sceneMode, suspendLoad, priority);
var handle = _resourceManager.LoadSceneAsync(assetInfo, sceneMode, suspendLoad, priority);
if (waitForAsyncComplete)
handle.WaitForAsyncComplete();
return handle;
@@ -765,9 +645,8 @@ namespace YooAsset
private AssetHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
{
DebugCheckAssetLoadMethod(nameof(LoadAssetAsync));
DebugCheckAssetLoadType(assetInfo.AssetType);
var handle = _resourceMgr.LoadAssetAsync(assetInfo, priority);
var handle = _resourceManager.LoadAssetAsync(assetInfo, priority);
if (waitForAsyncComplete)
handle.WaitForAsyncComplete();
return handle;
@@ -875,9 +754,8 @@ namespace YooAsset
private SubAssetsHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
{
DebugCheckAssetLoadMethod(nameof(LoadSubAssetsAsync));
DebugCheckAssetLoadType(assetInfo.AssetType);
var handle = _resourceMgr.LoadSubAssetsAsync(assetInfo, priority);
var handle = _resourceManager.LoadSubAssetsAsync(assetInfo, priority);
if (waitForAsyncComplete)
handle.WaitForAsyncComplete();
return handle;
@@ -985,9 +863,8 @@ namespace YooAsset
private AllAssetsHandle LoadAllAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete, uint priority)
{
DebugCheckAssetLoadMethod(nameof(LoadAllAssetsAsync));
DebugCheckAssetLoadType(assetInfo.AssetType);
var handle = _resourceMgr.LoadAllAssetsAsync(assetInfo, priority);
var handle = _resourceManager.LoadAllAssetsAsync(assetInfo, priority);
if (waitForAsyncComplete)
handle.WaitForAsyncComplete();
return handle;
@@ -1148,17 +1025,6 @@ namespace YooAsset
#endregion
#region
/// <summary>
/// 是否包含资源文件
/// </summary>
internal bool IsIncludeBundleFile(string cacheGUID)
{
// NOTE : 编辑器模拟模式下始终返回TRUE
if (_playMode == EPlayMode.EditorSimulateMode)
return true;
return _playModeImpl.ActiveManifest.IsIncludeBundleFile(cacheGUID);
}
private AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType)
{
return _playModeImpl.ActiveManifest.ConvertLocationToAssetInfo(location, assetType);
@@ -1185,24 +1051,6 @@ namespace YooAsset
}
}
[Conditional("DEBUG")]
private void DebugCheckRawFileLoadMethod(string method)
{
if (_playModeImpl.ActiveManifest.BuildPipeline != EDefaultBuildPipeline.RawFileBuildPipeline.ToString())
{
throw new Exception($"Cannot load asset bundle file using {method} method !");
}
}
[Conditional("DEBUG")]
private void DebugCheckAssetLoadMethod(string method)
{
if (_playModeImpl.ActiveManifest.BuildPipeline == EDefaultBuildPipeline.RawFileBuildPipeline.ToString())
{
throw new Exception($"Cannot load raw file using {method} method !");
}
}
[Conditional("DEBUG")]
private void DebugCheckAssetLoadType(System.Type type)
{
@@ -1226,7 +1074,7 @@ namespace YooAsset
{
DebugPackageData data = new DebugPackageData();
data.PackageName = PackageName;
data.ProviderInfos = _resourceMgr.GetDebugReportInfos();
data.ProviderInfos = _resourceManager.GetDebugReportInfos();
return data;
}
#endregion