mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-25 18:20:15 +00:00
refactor : 重构资源包裹模块
This commit is contained in:
@@ -129,16 +129,16 @@ namespace YooAsset
|
||||
var operation = new DBFSInitializeOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
||||
{
|
||||
var operation = new DBFSLoadPackageManifestOperation(this, packageVersion);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options)
|
||||
{
|
||||
var operation = new DBFSRequestPackageVersionOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options)
|
||||
{
|
||||
var operation = new DBFSLoadPackageManifestOperation(this, options.PackageVersion);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
|
||||
{
|
||||
return _unpackFileSystem.ClearCacheFilesAsync(manifest, options);
|
||||
|
||||
@@ -151,14 +151,14 @@ namespace YooAsset
|
||||
var operation = new DCFSInitializeOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options)
|
||||
{
|
||||
var operation = new DCFSLoadPackageManifestOperation(this, packageVersion, timeout);
|
||||
var operation = new DCFSRequestPackageVersionOperation(this, options.AppendTimeTicks, options.Timeout);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options)
|
||||
{
|
||||
var operation = new DCFSRequestPackageVersionOperation(this, appendTimeTicks, timeout);
|
||||
var operation = new DCFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
|
||||
|
||||
@@ -83,16 +83,16 @@ namespace YooAsset
|
||||
var operation = new DEFSInitializeOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
||||
{
|
||||
var operation = new DEFSLoadPackageManifestOperation(this, packageVersion);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options)
|
||||
{
|
||||
var operation = new DEFSRequestPackageVersionOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options)
|
||||
{
|
||||
var operation = new DEFSLoadPackageManifestOperation(this, options.PackageVersion);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
|
||||
{
|
||||
var operation = new FSClearCacheFilesCompleteOperation();
|
||||
|
||||
@@ -78,14 +78,14 @@ namespace YooAsset
|
||||
var operation = new DWRFSInitializeOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options)
|
||||
{
|
||||
var operation = new DWRFSLoadPackageManifestOperation(this, packageVersion, timeout);
|
||||
var operation = new DWRFSRequestPackageVersionOperation(this, options.AppendTimeTicks, options.Timeout);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options)
|
||||
{
|
||||
var operation = new DWRFSRequestPackageVersionOperation(this, appendTimeTicks, timeout);
|
||||
var operation = new DWRFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
|
||||
|
||||
@@ -87,14 +87,14 @@ namespace YooAsset
|
||||
var operation = new DWSFSInitializeOperation(this);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout)
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options)
|
||||
{
|
||||
var operation = new DWSFSLoadPackageManifestOperation(this, packageVersion, timeout);
|
||||
var operation = new DWSFSRequestPackageVersionOperation(this, options.Timeout);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
public virtual FSLoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options)
|
||||
{
|
||||
var operation = new DWSFSRequestPackageVersionOperation(this, timeout);
|
||||
var operation = new DWSFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout);
|
||||
return operation;
|
||||
}
|
||||
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options)
|
||||
|
||||
@@ -24,15 +24,15 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
FSInitializeFileSystemOperation InitializeFileSystemAsync();
|
||||
|
||||
/// <summary>
|
||||
/// 加载包裹清单
|
||||
/// </summary>
|
||||
FSLoadPackageManifestOperation LoadPackageManifestAsync(string packageVersion, int timeout);
|
||||
|
||||
/// <summary>
|
||||
/// 查询包裹版本
|
||||
/// </summary>
|
||||
FSRequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout);
|
||||
FSRequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// 加载包裹清单
|
||||
/// </summary>
|
||||
FSLoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// 清理缓存文件
|
||||
@@ -43,7 +43,7 @@ namespace YooAsset
|
||||
/// 下载Bundle文件
|
||||
/// </summary>
|
||||
FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 加载Bundle文件
|
||||
/// </summary>
|
||||
|
||||
@@ -1,19 +1,6 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class ClearCacheFilesOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理模式
|
||||
/// </summary>
|
||||
public string ClearMode;
|
||||
|
||||
/// <summary>
|
||||
/// 附加参数
|
||||
/// </summary>
|
||||
public object ClearParam;
|
||||
}
|
||||
|
||||
internal abstract class FSClearCacheFilesOperation : AsyncOperationBase
|
||||
{
|
||||
}
|
||||
|
||||
@@ -3,19 +3,6 @@ using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public sealed class UnloadAllAssetsOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 释放所有资源句柄,防止卸载过程中触发完成回调!
|
||||
/// </summary>
|
||||
public bool ReleaseAllHandles = false;
|
||||
|
||||
/// <summary>
|
||||
/// 卸载过程中锁定加载操作,防止新的任务请求!
|
||||
/// </summary>
|
||||
public bool LockLoadOperation = false;
|
||||
}
|
||||
|
||||
public sealed class UnloadAllAssetsOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
@@ -49,14 +36,6 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.CheckOptions)
|
||||
{
|
||||
if (_options == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{nameof(UnloadAllAssetsOptions)} is null.";
|
||||
return;
|
||||
}
|
||||
|
||||
// 设置锁定状态
|
||||
if (_options.LockLoadOperation)
|
||||
_resManager.LockLoadOperation = true;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public struct UnloadAllAssetsOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 释放所有资源句柄,防止卸载过程中触发完成回调!
|
||||
/// </summary>
|
||||
public bool ReleaseAllHandles { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 卸载过程中锁定加载操作,防止新的任务请求!
|
||||
/// </summary>
|
||||
public bool LockLoadOperation { private set; get; }
|
||||
|
||||
public UnloadAllAssetsOptions(bool releaseAllHandles, bool lockLoadOperation)
|
||||
{
|
||||
ReleaseAllHandles = releaseAllHandles;
|
||||
LockLoadOperation = lockLoadOperation;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc733fff9ba8d5747b556fb6cdb2b9e2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -44,11 +44,11 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
public void Initialize(InitializeParameters parameters, IBundleQuery bundleServices)
|
||||
public void Initialize(InitializePackageOptions options, IBundleQuery bundleServices)
|
||||
{
|
||||
_bundleLoadingMaxConcurrency = parameters.BundleLoadingMaxConcurrency;
|
||||
AutoUnloadBundleWhenUnused = parameters.AutoUnloadBundleWhenUnused;
|
||||
WebGLForceSyncLoadAsset = parameters.WebGLForceSyncLoadAsset;
|
||||
_bundleLoadingMaxConcurrency = options.BundleLoadingMaxConcurrency;
|
||||
AutoUnloadBundleWhenUnused = options.AutoUnloadBundleWhenUnused;
|
||||
WebGLForceSyncLoadAsset = options.WebGLForceSyncLoadAsset;
|
||||
_bundleQuery = bundleServices;
|
||||
SceneManager.sceneUnloaded += OnSceneUnloaded;
|
||||
}
|
||||
|
||||
34
Assets/YooAsset/Runtime/ResourcePackage/EPlayMode.cs
Normal file
34
Assets/YooAsset/Runtime/ResourcePackage/EPlayMode.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 运行模式
|
||||
/// </summary>
|
||||
public enum EPlayMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑器下的模拟模式
|
||||
/// </summary>
|
||||
EditorSimulateMode,
|
||||
|
||||
/// <summary>
|
||||
/// 离线运行模式
|
||||
/// </summary>
|
||||
OfflinePlayMode,
|
||||
|
||||
/// <summary>
|
||||
/// 联机运行模式
|
||||
/// </summary>
|
||||
HostPlayMode,
|
||||
|
||||
/// <summary>
|
||||
/// WebGL运行模式
|
||||
/// </summary>
|
||||
WebPlayMode,
|
||||
|
||||
/// <summary>
|
||||
/// 自定义运行模式
|
||||
/// </summary>
|
||||
CustomPlayMode,
|
||||
}
|
||||
}
|
||||
11
Assets/YooAsset/Runtime/ResourcePackage/EPlayMode.cs.meta
Normal file
11
Assets/YooAsset/Runtime/ResourcePackage/EPlayMode.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c870af6a4c0efe444af84f4c3ba8c2c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -14,25 +14,25 @@ namespace YooAsset
|
||||
void DestroyFileSystem();
|
||||
|
||||
/// <summary>
|
||||
/// 向网络端请求最新的资源版本
|
||||
/// 请求最新的资源版本
|
||||
/// </summary>
|
||||
RequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks, int timeout);
|
||||
RequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// 向网络端请求并更新清单
|
||||
/// 请求并加载资源清单
|
||||
/// </summary>
|
||||
UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout);
|
||||
LoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// 预下载指定版本的包裹内容
|
||||
/// </summary>
|
||||
PreDownloadContentOperation PreDownloadContentAsync(string packageVersion, int timeout);
|
||||
PreDownloadContentOperation PreDownloadContentAsync(PreDownloadContentOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// 清理缓存文件
|
||||
/// </summary>
|
||||
ClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options);
|
||||
|
||||
|
||||
// 下载相关
|
||||
ResourceDownloaderOperation CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain);
|
||||
ResourceDownloaderOperation CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain);
|
||||
@@ -41,7 +41,7 @@ namespace YooAsset
|
||||
// 解压相关
|
||||
ResourceUnpackerOperation CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain);
|
||||
ResourceUnpackerOperation CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain);
|
||||
|
||||
|
||||
// 导入相关
|
||||
ResourceImporterOperation CreateResourceImporterByFilePaths(string[] filePaths, int importingMaxNumber, int failedTryAgain);
|
||||
ResourceImporterOperation CreateResourceImporterByFileInfos(ImportFileInfo[] fileInfos, int importingMaxNumber, int failedTryAgain);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public struct ClearCacheFilesOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理模式
|
||||
/// </summary>
|
||||
public string ClearMode { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 附加参数
|
||||
/// </summary>
|
||||
public object ClearParam { private set; get; }
|
||||
|
||||
public ClearCacheFilesOptions(EFileClearMode clearMode)
|
||||
{
|
||||
ClearMode = clearMode.ToString();
|
||||
ClearParam = null;
|
||||
}
|
||||
public ClearCacheFilesOptions(EFileClearMode clearMode, object clearParam)
|
||||
{
|
||||
ClearMode = clearMode.ToString();
|
||||
ClearParam = clearParam;
|
||||
}
|
||||
public ClearCacheFilesOptions(string clearMode, object clearParam)
|
||||
{
|
||||
ClearMode = clearMode;
|
||||
ClearParam = clearParam;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4213bf1907101944b88f32ff19367b6f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class DestroyOperation : AsyncOperationBase
|
||||
public class DestroyPackageOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
@@ -18,7 +18,7 @@ namespace YooAsset
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
public DestroyOperation(ResourcePackage resourcePackage, UnloadAllAssetsOptions options)
|
||||
public DestroyPackageOperation(ResourcePackage resourcePackage, UnloadAllAssetsOptions options)
|
||||
{
|
||||
_resourcePackage = resourcePackage;
|
||||
_options = options;
|
||||
@@ -90,7 +90,7 @@ namespace YooAsset
|
||||
if (_steps == ESteps.DestroyPackage)
|
||||
{
|
||||
// 销毁包裹
|
||||
_resourcePackage.DestroyPackage();
|
||||
_resourcePackage.InternalDestroy();
|
||||
|
||||
// 最后清理该包裹的异步任务
|
||||
// 注意:对于有线程操作的异步任务,需要保证线程安全释放。
|
||||
@@ -0,0 +1,192 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class InitializePackageOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
SetPlayMode,
|
||||
CheckOptions,
|
||||
CheckPlatform,
|
||||
CreateCore,
|
||||
InitFileSystem,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly ResourcePackage _package;
|
||||
private readonly InitializePackageOptions _options;
|
||||
private PlayModeImpl _playModeImpl;
|
||||
private InitializeFileSystemOperation _initializeFileSystemOp;
|
||||
private EPlayMode _playMode;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal InitializePackageOperation(ResourcePackage package, InitializePackageOptions options)
|
||||
{
|
||||
_package = package;
|
||||
_options = options;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.SetPlayMode;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.SetPlayMode)
|
||||
{
|
||||
if (_options is EditorSimulateModeOptions)
|
||||
_playMode = EPlayMode.EditorSimulateMode;
|
||||
else if (_options is OfflinePlayModeOptions)
|
||||
_playMode = EPlayMode.OfflinePlayMode;
|
||||
else if (_options is HostPlayModeOptions)
|
||||
_playMode = EPlayMode.HostPlayMode;
|
||||
else if (_options is WebPlayModeOptions)
|
||||
_playMode = EPlayMode.WebPlayMode;
|
||||
else if (_options is CustomPlayModeOptions)
|
||||
_playMode = EPlayMode.CustomPlayMode;
|
||||
else
|
||||
throw new NotImplementedException($"{_options.GetType().Name}");
|
||||
|
||||
_package._playMode = _playMode;
|
||||
_steps = ESteps.CheckOptions;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckOptions)
|
||||
{
|
||||
// 检测初始化参数
|
||||
if (_options.BundleLoadingMaxConcurrency <= 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{nameof(_options.BundleLoadingMaxConcurrency)} value must be greater than zero.";
|
||||
YooLogger.Error(Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckPlatform;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckPlatform)
|
||||
{
|
||||
#if !UNITY_EDITOR
|
||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Editor simulate mode only support unity editor.";
|
||||
YooLogger.Error(Error);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UNITY_WEBGL
|
||||
if (_playMode != EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
if (_playMode != EPlayMode.WebPlayMode)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{_playMode} can not support WebGL plateform !";
|
||||
YooLogger.Error(Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !UNITY_WEBGL
|
||||
if (_playMode != EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
if (_playMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"{nameof(EPlayMode.WebPlayMode)} only support WebGL plateform !";
|
||||
YooLogger.Error(Error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
_steps = ESteps.CreateCore;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CreateCore)
|
||||
{
|
||||
string packageName = _package.PackageName;
|
||||
var resourceManager = new ResourceManager(packageName);
|
||||
var playModeImpl = new PlayModeImpl(packageName);
|
||||
resourceManager.Initialize(_options, playModeImpl);
|
||||
|
||||
_playModeImpl = playModeImpl;
|
||||
_package._bundleQuery = playModeImpl;
|
||||
_package._playModeImpl = playModeImpl;
|
||||
_package._resourceManager = resourceManager;
|
||||
_steps = ESteps.InitFileSystem;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.InitFileSystem)
|
||||
{
|
||||
if (_initializeFileSystemOp == null)
|
||||
{
|
||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
var initializeParameters = _options as EditorSimulateModeOptions;
|
||||
_initializeFileSystemOp = _playModeImpl.InitializeAsync(initializeParameters.EditorFileSystemParameters);
|
||||
}
|
||||
else if (_playMode == EPlayMode.OfflinePlayMode)
|
||||
{
|
||||
var initializeParameters = _options as OfflinePlayModeOptions;
|
||||
_initializeFileSystemOp = _playModeImpl.InitializeAsync(initializeParameters.BuildinFileSystemParameters);
|
||||
}
|
||||
else if (_playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
var initializeParameters = _options as HostPlayModeOptions;
|
||||
_initializeFileSystemOp = _playModeImpl.InitializeAsync(initializeParameters.BuildinFileSystemParameters, initializeParameters.CacheFileSystemParameters);
|
||||
}
|
||||
else if (_playMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
var initializeParameters = _options as WebPlayModeOptions;
|
||||
_initializeFileSystemOp = _playModeImpl.InitializeAsync(initializeParameters.WebServerFileSystemParameters, initializeParameters.WebRemoteFileSystemParameters);
|
||||
}
|
||||
else if (_playMode == EPlayMode.CustomPlayMode)
|
||||
{
|
||||
var initializeParameters = _options as CustomPlayModeOptions;
|
||||
_initializeFileSystemOp = _playModeImpl.InitializeAsync(initializeParameters.FileSystemParameterList);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException(_playMode.ToString());
|
||||
}
|
||||
|
||||
_initializeFileSystemOp.StartOperation();
|
||||
AddChildOperation(_initializeFileSystemOp);
|
||||
}
|
||||
|
||||
_initializeFileSystemOp.UpdateOperation();
|
||||
if (_initializeFileSystemOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_initializeFileSystemOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _initializeFileSystemOp.Error;
|
||||
YooLogger.Error(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override string InternalGetDesc()
|
||||
{
|
||||
return $"PlayMode : {_playMode}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ecb6fb1cbab9e0242849d2657f438478
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -2,41 +2,10 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 运行模式
|
||||
/// </summary>
|
||||
public enum EPlayMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑器下的模拟模式
|
||||
/// </summary>
|
||||
EditorSimulateMode,
|
||||
|
||||
/// <summary>
|
||||
/// 离线运行模式
|
||||
/// </summary>
|
||||
OfflinePlayMode,
|
||||
|
||||
/// <summary>
|
||||
/// 联机运行模式
|
||||
/// </summary>
|
||||
HostPlayMode,
|
||||
|
||||
/// <summary>
|
||||
/// WebGL运行模式
|
||||
/// </summary>
|
||||
WebPlayMode,
|
||||
|
||||
/// <summary>
|
||||
/// 自定义运行模式
|
||||
/// </summary>
|
||||
CustomPlayMode,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化参数
|
||||
/// </summary>
|
||||
public abstract class InitializeParameters
|
||||
public abstract class InitializePackageOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 同时加载Bundle文件的最大并发数
|
||||
@@ -57,7 +26,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 编辑器下模拟运行模式的初始化参数
|
||||
/// </summary>
|
||||
public class EditorSimulateModeParameters : InitializeParameters
|
||||
public class EditorSimulateModeOptions : InitializePackageOptions
|
||||
{
|
||||
public FileSystemParameters EditorFileSystemParameters;
|
||||
}
|
||||
@@ -65,7 +34,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 离线运行模式的初始化参数
|
||||
/// </summary>
|
||||
public class OfflinePlayModeParameters : InitializeParameters
|
||||
public class OfflinePlayModeOptions : InitializePackageOptions
|
||||
{
|
||||
public FileSystemParameters BuildinFileSystemParameters;
|
||||
}
|
||||
@@ -73,7 +42,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 联机运行模式的初始化参数
|
||||
/// </summary>
|
||||
public class HostPlayModeParameters : InitializeParameters
|
||||
public class HostPlayModeOptions : InitializePackageOptions
|
||||
{
|
||||
public FileSystemParameters BuildinFileSystemParameters;
|
||||
public FileSystemParameters CacheFileSystemParameters;
|
||||
@@ -82,7 +51,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// WebGL运行模式的初始化参数
|
||||
/// </summary>
|
||||
public class WebPlayModeParameters : InitializeParameters
|
||||
public class WebPlayModeOptions : InitializePackageOptions
|
||||
{
|
||||
public FileSystemParameters WebServerFileSystemParameters;
|
||||
public FileSystemParameters WebRemoteFileSystemParameters;
|
||||
@@ -91,7 +60,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 自定义运行模式的初始化参数
|
||||
/// </summary>
|
||||
public class CustomPlayModeParameters : InitializeParameters
|
||||
public class CustomPlayModeOptions : InitializePackageOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件系统初始化参数列表
|
||||
@@ -3,13 +3,12 @@ using System.Linq;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public class InitializationOperation : AsyncOperationBase
|
||||
public class InitializeFileSystemOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
Prepare,
|
||||
ClearOldFileSystem,
|
||||
InitFileSystem,
|
||||
CheckInitResult,
|
||||
Done,
|
||||
@@ -20,8 +19,8 @@ namespace YooAsset
|
||||
private List<FileSystemParameters> _cloneList;
|
||||
private FSInitializeFileSystemOperation _initFileSystemOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal InitializationOperation(PlayModeImpl impl, List<FileSystemParameters> parametersList)
|
||||
|
||||
internal InitializeFileSystemOperation(PlayModeImpl impl, List<FileSystemParameters> parametersList)
|
||||
{
|
||||
_impl = impl;
|
||||
_parametersList = parametersList;
|
||||
@@ -57,18 +56,6 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
_cloneList = _parametersList.ToList();
|
||||
_steps = ESteps.ClearOldFileSystem;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.ClearOldFileSystem)
|
||||
{
|
||||
// 注意:初始化失败后可能会残存一些旧的文件系统!
|
||||
foreach (var fileSystem in _impl.FileSystems)
|
||||
{
|
||||
fileSystem.OnDestroy();
|
||||
}
|
||||
|
||||
_impl.FileSystems.Clear();
|
||||
_steps = ESteps.InitFileSystem;
|
||||
}
|
||||
|
||||
@@ -121,9 +108,5 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
}
|
||||
internal override string InternalGetDesc()
|
||||
{
|
||||
return $"PlayMode : {_impl.PlayMode}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public sealed class UpdatePackageManifestOperation : AsyncOperationBase
|
||||
public sealed class LoadPackageManifestOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
@@ -13,16 +13,14 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
private readonly PlayModeImpl _impl;
|
||||
private readonly string _packageVersion;
|
||||
private readonly int _timeout;
|
||||
private readonly LoadPackageManifestOptions _options;
|
||||
private FSLoadPackageManifestOperation _loadPackageManifestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal UpdatePackageManifestOperation(PlayModeImpl impl, string packageVersion, int timeout)
|
||||
internal LoadPackageManifestOperation(PlayModeImpl impl, LoadPackageManifestOptions options)
|
||||
{
|
||||
_impl = impl;
|
||||
_packageVersion = packageVersion;
|
||||
_timeout = timeout;
|
||||
_options = options;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
@@ -35,7 +33,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.CheckParams)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_packageVersion))
|
||||
if (string.IsNullOrEmpty(_options.PackageVersion))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
@@ -50,7 +48,7 @@ namespace YooAsset
|
||||
if (_steps == ESteps.CheckActiveManifest)
|
||||
{
|
||||
// 检测当前激活的清单对象
|
||||
if (_impl.ActiveManifest != null && _impl.ActiveManifest.PackageVersion == _packageVersion)
|
||||
if (_impl.ActiveManifest != null && _impl.ActiveManifest.PackageVersion == _options.PackageVersion)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
@@ -66,7 +64,7 @@ namespace YooAsset
|
||||
if (_loadPackageManifestOp == null)
|
||||
{
|
||||
var mainFileSystem = _impl.GetMainFileSystem();
|
||||
_loadPackageManifestOp = mainFileSystem.LoadPackageManifestAsync(_packageVersion, _timeout);
|
||||
_loadPackageManifestOp = mainFileSystem.LoadPackageManifestAsync(_options);
|
||||
_loadPackageManifestOp.StartOperation();
|
||||
AddChildOperation(_loadPackageManifestOp);
|
||||
}
|
||||
@@ -91,7 +89,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override string InternalGetDesc()
|
||||
{
|
||||
return $"PackageVersion : {_packageVersion}";
|
||||
return $"PackageVersion : {_options.PackageVersion}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public struct LoadPackageManifestOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 包裹版本
|
||||
/// </summary>
|
||||
public string PackageVersion { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 超时时间
|
||||
/// </summary>
|
||||
public int Timeout { private set; get; }
|
||||
|
||||
public LoadPackageManifestOptions(string packageVersion, int timeout)
|
||||
{
|
||||
PackageVersion = packageVersion;
|
||||
Timeout = timeout;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02958c7c4e947ae4b95472741e166cb6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -16,18 +16,17 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
private readonly PlayModeImpl _impl;
|
||||
private readonly string _packageVersion;
|
||||
private readonly PreDownloadContentOptions _options;
|
||||
private readonly int _timeout;
|
||||
private FSLoadPackageManifestOperation _loadPackageManifestOp;
|
||||
private PackageManifest _manifest;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal PreDownloadContentOperation(PlayModeImpl impl, string packageVersion, int timeout)
|
||||
internal PreDownloadContentOperation(PlayModeImpl impl, PreDownloadContentOptions options)
|
||||
{
|
||||
_impl = impl;
|
||||
_packageVersion = packageVersion;
|
||||
_timeout = timeout;
|
||||
_options = options;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
@@ -40,7 +39,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.CheckParams)
|
||||
{
|
||||
if (string.IsNullOrEmpty(_packageVersion))
|
||||
if (string.IsNullOrEmpty(_options.PackageVersion))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
@@ -56,7 +55,7 @@ namespace YooAsset
|
||||
// 检测当前激活的清单对象
|
||||
if (_impl.ActiveManifest != null)
|
||||
{
|
||||
if (_impl.ActiveManifest.PackageVersion == _packageVersion)
|
||||
if (_impl.ActiveManifest.PackageVersion == _options.PackageVersion)
|
||||
{
|
||||
_manifest = _impl.ActiveManifest;
|
||||
_steps = ESteps.Done;
|
||||
@@ -72,7 +71,8 @@ namespace YooAsset
|
||||
if (_loadPackageManifestOp == null)
|
||||
{
|
||||
var mainFileSystem = _impl.GetMainFileSystem();
|
||||
_loadPackageManifestOp = mainFileSystem.LoadPackageManifestAsync(_packageVersion, _timeout);
|
||||
var options = new LoadPackageManifestOptions(_options.PackageVersion, _options.Timeout);
|
||||
_loadPackageManifestOp = mainFileSystem.LoadPackageManifestAsync(options);
|
||||
_loadPackageManifestOp.StartOperation();
|
||||
AddChildOperation(_loadPackageManifestOp);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public struct PreDownloadContentOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 预下载的包裹版本
|
||||
/// </summary>
|
||||
public string PackageVersion { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源清单请求超时时间
|
||||
/// </summary>
|
||||
public int Timeout { private set; get; }
|
||||
|
||||
public PreDownloadContentOptions(string packageVersion, int timeout)
|
||||
{
|
||||
PackageVersion = packageVersion;
|
||||
Timeout = timeout;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6ccb056c8ca90c49a01cc15aa75a513
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -18,16 +18,14 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
private readonly PlayModeImpl _impl;
|
||||
private readonly bool _appendTimeTicks;
|
||||
private readonly int _timeout;
|
||||
private readonly RequestPackageVersionOptions _options;
|
||||
private FSRequestPackageVersionOperation _requestPackageVersionOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal RequestPackageVersionImplOperation(PlayModeImpl impl, bool appendTimeTicks, int timeout)
|
||||
internal RequestPackageVersionImplOperation(PlayModeImpl impl, RequestPackageVersionOptions options)
|
||||
{
|
||||
_impl = impl;
|
||||
_appendTimeTicks = appendTimeTicks;
|
||||
_timeout = timeout;
|
||||
_options = options;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
@@ -43,7 +41,7 @@ namespace YooAsset
|
||||
if (_requestPackageVersionOp == null)
|
||||
{
|
||||
var mainFileSystem = _impl.GetMainFileSystem();
|
||||
_requestPackageVersionOp = mainFileSystem.RequestPackageVersionAsync(_appendTimeTicks, _timeout);
|
||||
_requestPackageVersionOp = mainFileSystem.RequestPackageVersionAsync(_options);
|
||||
_requestPackageVersionOp.StartOperation();
|
||||
AddChildOperation(_requestPackageVersionOp);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
public struct RequestPackageVersionOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 在URL末尾添加时间戳
|
||||
/// </summary>
|
||||
public bool AppendTimeTicks { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 超时时间
|
||||
/// </summary>
|
||||
public int Timeout { private set; get; }
|
||||
|
||||
public RequestPackageVersionOptions(bool appendTimeTicks, int timeout)
|
||||
{
|
||||
AppendTimeTicks = appendTimeTicks;
|
||||
Timeout = timeout;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e89594016c3fa69499adf8d642490ed6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -7,19 +7,17 @@ namespace YooAsset
|
||||
internal class PlayModeImpl : IPlayMode, IBundleQuery
|
||||
{
|
||||
public readonly string PackageName;
|
||||
public readonly EPlayMode PlayMode;
|
||||
public readonly List<IFileSystem> FileSystems = new List<IFileSystem>(10);
|
||||
|
||||
public PlayModeImpl(string packageName, EPlayMode playMode)
|
||||
public PlayModeImpl(string packageName)
|
||||
{
|
||||
PackageName = packageName;
|
||||
PlayMode = playMode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(FileSystemParameters fileSystemParameter)
|
||||
public InitializeFileSystemOperation InitializeAsync(FileSystemParameters fileSystemParameter)
|
||||
{
|
||||
var fileSystemParamList = new List<FileSystemParameters>();
|
||||
if (fileSystemParameter != null)
|
||||
@@ -30,7 +28,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(FileSystemParameters fileSystemParameterA, FileSystemParameters fileSystemParameterB)
|
||||
public InitializeFileSystemOperation InitializeAsync(FileSystemParameters fileSystemParameterA, FileSystemParameters fileSystemParameterB)
|
||||
{
|
||||
var fileSystemParamList = new List<FileSystemParameters>();
|
||||
if (fileSystemParameterA != null)
|
||||
@@ -43,9 +41,9 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(List<FileSystemParameters> fileSystemParameterList)
|
||||
public InitializeFileSystemOperation InitializeAsync(List<FileSystemParameters> fileSystemParameterList)
|
||||
{
|
||||
var operation = new InitializationOperation(this, fileSystemParameterList);
|
||||
var operation = new InitializeFileSystemOperation(this, fileSystemParameterList);
|
||||
return operation;
|
||||
}
|
||||
|
||||
@@ -70,27 +68,27 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 向网络端请求最新的资源版本
|
||||
/// </summary>
|
||||
RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(bool appendTimeTicks, int timeout)
|
||||
RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(RequestPackageVersionOptions options)
|
||||
{
|
||||
var operation = new RequestPackageVersionImplOperation(this, appendTimeTicks, timeout);
|
||||
var operation = new RequestPackageVersionImplOperation(this, options);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 向网络端请求并更新清单
|
||||
/// </summary>
|
||||
UpdatePackageManifestOperation IPlayMode.UpdatePackageManifestAsync(string packageVersion, int timeout)
|
||||
LoadPackageManifestOperation IPlayMode.LoadPackageManifestAsync(LoadPackageManifestOptions options)
|
||||
{
|
||||
var operation = new UpdatePackageManifestOperation(this, packageVersion, timeout);
|
||||
var operation = new LoadPackageManifestOperation(this, options);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 预下载指定版本的包裹内容
|
||||
/// </summary>
|
||||
PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(string packageVersion, int timeout)
|
||||
PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(PreDownloadContentOptions options)
|
||||
{
|
||||
var operation = new PreDownloadContentOperation(this, packageVersion, timeout);
|
||||
var operation = new PreDownloadContentOperation(this, options);
|
||||
return operation;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,15 +8,11 @@ namespace YooAsset
|
||||
{
|
||||
public class ResourcePackage
|
||||
{
|
||||
private bool _isInitialize = false;
|
||||
private string _initializeError = string.Empty;
|
||||
private EOperationStatus _initializeStatus = EOperationStatus.None;
|
||||
private EPlayMode _playMode;
|
||||
|
||||
// 管理器
|
||||
private ResourceManager _resourceManager;
|
||||
private IBundleQuery _bundleQuery;
|
||||
private IPlayMode _playModeImpl;
|
||||
private InitializePackageOperation _initializeOp;
|
||||
internal ResourceManager _resourceManager;
|
||||
internal IBundleQuery _bundleQuery;
|
||||
internal IPlayMode _playModeImpl;
|
||||
internal EPlayMode _playMode;
|
||||
|
||||
/// <summary>
|
||||
/// 包裹名
|
||||
@@ -28,7 +24,12 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public EOperationStatus InitializeStatus
|
||||
{
|
||||
get { return _initializeStatus; }
|
||||
get
|
||||
{
|
||||
if (_initializeOp == null)
|
||||
return EOperationStatus.None;
|
||||
return _initializeOp.Status;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -52,7 +53,7 @@ namespace YooAsset
|
||||
get { return OperationSystem.GetSchedulerPriority(PackageName); }
|
||||
set { OperationSystem.SetSchedulerPriority(PackageName, value); }
|
||||
}
|
||||
|
||||
|
||||
|
||||
internal ResourcePackage(string packageName)
|
||||
{
|
||||
@@ -62,40 +63,10 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 销毁资源包裹
|
||||
/// </summary>
|
||||
internal void DestroyPackage()
|
||||
internal void InternalDestroy()
|
||||
{
|
||||
if (_isInitialize)
|
||||
{
|
||||
_isInitialize = false;
|
||||
_initializeError = string.Empty;
|
||||
_initializeStatus = EOperationStatus.None;
|
||||
|
||||
// 销毁资源管理器
|
||||
if (_resourceManager != null)
|
||||
{
|
||||
_resourceManager.Destroy();
|
||||
_resourceManager = null;
|
||||
}
|
||||
|
||||
// 销毁文件系统
|
||||
if (_playModeImpl != null)
|
||||
_playModeImpl.DestroyFileSystem();
|
||||
|
||||
_bundleQuery = null;
|
||||
_playModeImpl = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步初始化
|
||||
/// </summary>
|
||||
public InitializationOperation InitializeAsync(InitializeParameters parameters)
|
||||
{
|
||||
// 注意:联机平台因为网络原因可能会初始化失败!
|
||||
ResetInitializeAfterFailed();
|
||||
|
||||
// 检测初始化参数合法性
|
||||
CheckInitializeParameters(parameters);
|
||||
_initializeOp = null;
|
||||
_bundleQuery = null;
|
||||
|
||||
// 销毁资源管理器
|
||||
if (_resourceManager != null)
|
||||
@@ -104,147 +75,75 @@ namespace YooAsset
|
||||
_resourceManager = null;
|
||||
}
|
||||
|
||||
// 创建资源管理器
|
||||
_resourceManager = new ResourceManager(PackageName);
|
||||
var playModeImpl = new PlayModeImpl(PackageName, _playMode);
|
||||
_bundleQuery = playModeImpl;
|
||||
_playModeImpl = playModeImpl;
|
||||
_resourceManager.Initialize(parameters, _bundleQuery);
|
||||
|
||||
// 初始化资源系统
|
||||
InitializationOperation initializeOperation;
|
||||
if (_playMode == EPlayMode.EditorSimulateMode)
|
||||
// 销毁文件系统
|
||||
if (_playModeImpl != null)
|
||||
{
|
||||
var initializeParameters = parameters as EditorSimulateModeParameters;
|
||||
initializeOperation = playModeImpl.InitializeAsync(initializeParameters.EditorFileSystemParameters);
|
||||
_playModeImpl.DestroyFileSystem();
|
||||
_playModeImpl = null;
|
||||
}
|
||||
else if (_playMode == EPlayMode.OfflinePlayMode)
|
||||
{
|
||||
var initializeParameters = parameters as OfflinePlayModeParameters;
|
||||
initializeOperation = playModeImpl.InitializeAsync(initializeParameters.BuildinFileSystemParameters);
|
||||
}
|
||||
else if (_playMode == EPlayMode.HostPlayMode)
|
||||
{
|
||||
var initializeParameters = parameters as HostPlayModeParameters;
|
||||
initializeOperation = playModeImpl.InitializeAsync(initializeParameters.BuildinFileSystemParameters, initializeParameters.CacheFileSystemParameters);
|
||||
}
|
||||
else if (_playMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
var initializeParameters = parameters as WebPlayModeParameters;
|
||||
initializeOperation = playModeImpl.InitializeAsync(initializeParameters.WebServerFileSystemParameters, initializeParameters.WebRemoteFileSystemParameters);
|
||||
}
|
||||
else if (_playMode == EPlayMode.CustomPlayMode)
|
||||
{
|
||||
var initializeParameters = parameters as CustomPlayModeParameters;
|
||||
initializeOperation = playModeImpl.InitializeAsync(initializeParameters.FileSystemParameterList);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// 监听初始化结果
|
||||
_isInitialize = true;
|
||||
OperationSystem.StartOperation(PackageName, initializeOperation);
|
||||
initializeOperation.Completed += InitializeOperation_Completed;
|
||||
return initializeOperation;
|
||||
}
|
||||
private void ResetInitializeAfterFailed()
|
||||
{
|
||||
if (_isInitialize && _initializeStatus == EOperationStatus.Failed)
|
||||
{
|
||||
_isInitialize = false;
|
||||
_initializeStatus = EOperationStatus.None;
|
||||
_initializeError = string.Empty;
|
||||
}
|
||||
}
|
||||
private void CheckInitializeParameters(InitializeParameters parameters)
|
||||
{
|
||||
if (_isInitialize)
|
||||
throw new YooPackageException(PackageName, $"Package '{PackageName}' is already initialized !");
|
||||
|
||||
if (parameters == null)
|
||||
throw new YooPackageException(PackageName, $"Initialize parameters cannot be null.");
|
||||
|
||||
#if !UNITY_EDITOR
|
||||
if (parameters is EditorSimulateModeParameters)
|
||||
throw new YooPlatformNotSupportedException($"Editor simulate mode only support unity editor.");
|
||||
#endif
|
||||
|
||||
// 检测初始化参数
|
||||
if (parameters.BundleLoadingMaxConcurrency <= 0)
|
||||
throw new YooPackageException(PackageName, $"{nameof(parameters.BundleLoadingMaxConcurrency)} value must be greater than zero.");
|
||||
|
||||
// 鉴定运行模式
|
||||
if (parameters is EditorSimulateModeParameters)
|
||||
_playMode = EPlayMode.EditorSimulateMode;
|
||||
else if (parameters is OfflinePlayModeParameters)
|
||||
_playMode = EPlayMode.OfflinePlayMode;
|
||||
else if (parameters is HostPlayModeParameters)
|
||||
_playMode = EPlayMode.HostPlayMode;
|
||||
else if (parameters is WebPlayModeParameters)
|
||||
_playMode = EPlayMode.WebPlayMode;
|
||||
else if (parameters is CustomPlayModeParameters)
|
||||
_playMode = EPlayMode.CustomPlayMode;
|
||||
else
|
||||
throw new NotImplementedException();
|
||||
|
||||
// 检测运行时平台
|
||||
if (_playMode != EPlayMode.EditorSimulateMode)
|
||||
{
|
||||
#if UNITY_WEBGL
|
||||
if (_playMode != EPlayMode.WebPlayMode)
|
||||
{
|
||||
throw new YooPlatformNotSupportedException($"{_playMode} can not support WebGL plateform !");
|
||||
}
|
||||
#else
|
||||
if (_playMode == EPlayMode.WebPlayMode)
|
||||
{
|
||||
throw new YooPlatformNotSupportedException($"{nameof(EPlayMode.WebPlayMode)} only support WebGL plateform !");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
private void InitializeOperation_Completed(AsyncOperationBase op)
|
||||
{
|
||||
_initializeStatus = op.Status;
|
||||
_initializeError = op.Error;
|
||||
if (_initializeStatus != EOperationStatus.Succeed)
|
||||
YooLogger.Error(_initializeError);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步销毁
|
||||
/// 异步初始化包裹
|
||||
/// </summary>
|
||||
public DestroyOperation DestroyAsync()
|
||||
public InitializePackageOperation InitializePackageAsync(InitializePackageOptions options)
|
||||
{
|
||||
var options = new UnloadAllAssetsOptions();
|
||||
options.ReleaseAllHandles = true;
|
||||
options.LockLoadOperation = true;
|
||||
var operation = new DestroyOperation(this, options);
|
||||
// 注意:联机平台因为网络原因可能会初始化失败!
|
||||
ResetInitializeAfterFailed();
|
||||
|
||||
// 检测重复初始化
|
||||
if (_initializeOp != null)
|
||||
throw new YooPackageException(PackageName, $"Package '{PackageName}' is already initialized !");
|
||||
|
||||
// 开始初始化操作
|
||||
_initializeOp = new InitializePackageOperation(this, options);
|
||||
OperationSystem.StartOperation(PackageName, _initializeOp);
|
||||
return _initializeOp;
|
||||
}
|
||||
private void ResetInitializeAfterFailed()
|
||||
{
|
||||
if (InitializeStatus == EOperationStatus.Failed)
|
||||
{
|
||||
InternalDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步销毁包裹
|
||||
/// </summary>
|
||||
public DestroyPackageOperation DestroyPackageAsync()
|
||||
{
|
||||
var options = new UnloadAllAssetsOptions(true, true);
|
||||
var operation = new DestroyPackageOperation(this, options);
|
||||
OperationSystem.StartOperation(OperationSystem.GLOBAL_SCHEDULER_NAME, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求最新的资源版本
|
||||
/// 说明:超时时间默认60秒
|
||||
/// </summary>
|
||||
/// <param name="appendTimeTicks">在URL末尾添加时间戳</param>
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
public RequestPackageVersionOperation RequestPackageVersionAsync(bool appendTimeTicks = true, int timeout = 60)
|
||||
public RequestPackageVersionOperation RequestPackageVersionAsync()
|
||||
{
|
||||
var options = new RequestPackageVersionOptions(true, 60);
|
||||
return RequestPackageVersionAsync(options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求最新的资源版本
|
||||
/// </summary>
|
||||
public RequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options)
|
||||
{
|
||||
DebugCheckInitialize(false);
|
||||
var operation = _playModeImpl.RequestPackageVersionAsync(appendTimeTicks, timeout);
|
||||
var operation = _playModeImpl.RequestPackageVersionAsync(options);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新并加载指定版本的资源清单
|
||||
/// 加载指定版本的资源清单
|
||||
/// </summary>
|
||||
/// <param name="packageVersion">包裹版本</param>
|
||||
/// <param name="timeout">超时时间(默认值:60秒)</param>
|
||||
public UpdatePackageManifestOperation UpdatePackageManifestAsync(string packageVersion, int timeout = 60)
|
||||
public LoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options)
|
||||
{
|
||||
DebugCheckInitialize(false);
|
||||
|
||||
@@ -254,7 +153,7 @@ namespace YooAsset
|
||||
YooLogger.Warning($"Found loaded bundle before update manifest ! Recommended to call the {nameof(UnloadAllAssetsAsync)} method to release loaded bundle !");
|
||||
}
|
||||
|
||||
var operation = _playModeImpl.UpdatePackageManifestAsync(packageVersion, timeout);
|
||||
var operation = _playModeImpl.LoadPackageManifestAsync(options);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
@@ -262,12 +161,10 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 预下载指定版本的包裹资源
|
||||
/// </summary>
|
||||
/// <param name="packageVersion">包裹版本</param>
|
||||
/// <param name="timeout">资源清单下载的超时时间(默认值:60秒)</param>
|
||||
public PreDownloadContentOperation PreDownloadContentAsync(string packageVersion, int timeout = 60)
|
||||
public PreDownloadContentOperation PreDownloadContentAsync(PreDownloadContentOptions options)
|
||||
{
|
||||
DebugCheckInitialize(false);
|
||||
var operation = _playModeImpl.PreDownloadContentAsync(packageVersion, timeout);
|
||||
var operation = _playModeImpl.PreDownloadContentAsync(options);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
@@ -275,30 +172,9 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 清理缓存文件
|
||||
/// </summary>
|
||||
/// <param name="clearMode">清理方式</param>
|
||||
/// <param name="clearParam">执行参数</param>
|
||||
public ClearCacheFilesOperation ClearCacheFilesAsync(EFileClearMode clearMode, object clearParam = null)
|
||||
public ClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options)
|
||||
{
|
||||
DebugCheckInitialize(false);
|
||||
ClearCacheFilesOptions options = new ClearCacheFilesOptions();
|
||||
options.ClearMode = clearMode.ToString();
|
||||
options.ClearParam = clearParam;
|
||||
var operation = _playModeImpl.ClearCacheFilesAsync(options);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理缓存文件
|
||||
/// </summary>
|
||||
/// <param name="clearMode">清理方式</param>
|
||||
/// <param name="clearParam">执行参数</param>
|
||||
public ClearCacheFilesOperation ClearCacheFilesAsync(string clearMode, object clearParam = null)
|
||||
{
|
||||
DebugCheckInitialize(false);
|
||||
ClearCacheFilesOptions options = new ClearCacheFilesOptions();
|
||||
options.ClearMode = clearMode;
|
||||
options.ClearParam = clearParam;
|
||||
var operation = _playModeImpl.ClearCacheFilesAsync(options);
|
||||
OperationSystem.StartOperation(PackageName, operation);
|
||||
return operation;
|
||||
@@ -1165,10 +1041,22 @@ namespace YooAsset
|
||||
#region 调试方法
|
||||
private void DebugCheckInitialize(bool checkActiveManifest = true)
|
||||
{
|
||||
if (_initializeStatus == EOperationStatus.None)
|
||||
throw new YooPackageException(PackageName, "Package initialize not completed !");
|
||||
else if (_initializeStatus == EOperationStatus.Failed)
|
||||
throw new YooPackageException(PackageName, $"Package initialize failed ! {_initializeError}");
|
||||
if (InitializeStatus != EOperationStatus.Succeed)
|
||||
{
|
||||
if (InitializeStatus == EOperationStatus.None)
|
||||
{
|
||||
throw new YooPackageException(PackageName, "Package not initialize !");
|
||||
}
|
||||
else if (InitializeStatus == EOperationStatus.Processing)
|
||||
{
|
||||
throw new YooPackageException(PackageName, "Package initialize not completed !");
|
||||
}
|
||||
else if (InitializeStatus == EOperationStatus.Failed)
|
||||
{
|
||||
string error = _initializeOp == null ? string.Empty : _initializeOp.Error;
|
||||
throw new YooPackageException(PackageName, $"Package initialize failed ! {error}");
|
||||
}
|
||||
}
|
||||
|
||||
if (checkActiveManifest)
|
||||
{
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace YooAsset
|
||||
string packageName = package.PackageName;
|
||||
if (package.InitializeStatus != EOperationStatus.None)
|
||||
{
|
||||
YooLogger.Error($"The resource package {packageName} has not been destroyed, please call the method {nameof(ResourcePackage.DestroyAsync)} to destroy!");
|
||||
YooLogger.Error($"The resource package {packageName} has not been destroyed, please call the method {nameof(ResourcePackage.DestroyPackageAsync)} to destroy!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user