96 lines
3.0 KiB
C#
96 lines
3.0 KiB
C#
|
|
namespace YooAsset
|
|
{
|
|
/// <summary>
|
|
/// 向远端请求并更新清单
|
|
/// </summary>
|
|
public abstract class UpdatePackageManifestOperation : AsyncOperationBase
|
|
{
|
|
}
|
|
internal sealed class UpdatePackageManifestImplOperation : UpdatePackageManifestOperation
|
|
{
|
|
private enum ESteps
|
|
{
|
|
None,
|
|
CheckParams,
|
|
CheckActiveManifest,
|
|
LoadPackageManifest,
|
|
Done,
|
|
}
|
|
|
|
private readonly IPlayMode _impl;
|
|
private readonly IFileSystem _fileSystem;
|
|
private readonly string _packageVersion;
|
|
private readonly int _timeout;
|
|
private FSLoadPackageManifestOperation _loadPackageManifestOp;
|
|
private ESteps _steps = ESteps.None;
|
|
|
|
|
|
internal UpdatePackageManifestImplOperation(IPlayMode impl, IFileSystem fileSystem, string packageVersion, int timeout)
|
|
{
|
|
_impl = impl;
|
|
_fileSystem = fileSystem;
|
|
_packageVersion = packageVersion;
|
|
_timeout = timeout;
|
|
}
|
|
internal override void InternalOnStart()
|
|
{
|
|
_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.";
|
|
}
|
|
else
|
|
{
|
|
_steps = ESteps.CheckActiveManifest;
|
|
}
|
|
}
|
|
|
|
if (_steps == ESteps.CheckActiveManifest)
|
|
{
|
|
// 检测当前激活的清单对象
|
|
if (_impl.ActiveManifest != null && _impl.ActiveManifest.PackageVersion == _packageVersion)
|
|
{
|
|
_steps = ESteps.Done;
|
|
Status = EOperationStatus.Succeed;
|
|
}
|
|
else
|
|
{
|
|
_steps = ESteps.LoadPackageManifest;
|
|
}
|
|
}
|
|
|
|
if (_steps == ESteps.LoadPackageManifest)
|
|
{
|
|
if (_loadPackageManifestOp == null)
|
|
_loadPackageManifestOp = _fileSystem.LoadPackageManifestAsync(_packageVersion, _timeout);
|
|
|
|
if (_loadPackageManifestOp.IsDone == false)
|
|
return;
|
|
|
|
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
|
|
{
|
|
_steps = ESteps.Done;
|
|
_impl.ActiveManifest = _loadPackageManifestOp.Manifest;
|
|
Status = EOperationStatus.Succeed;
|
|
}
|
|
else
|
|
{
|
|
_steps = ESteps.Done;
|
|
Status = EOperationStatus.Failed;
|
|
Error = _loadPackageManifestOp.Error;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |