mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-07-01 11:13:42 +00:00
update file system
This commit is contained in:
@@ -4,8 +4,8 @@ namespace YooAsset
|
||||
internal abstract class FSLoadPackageManifestOperation : AsyncOperationBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载结果
|
||||
/// 资源清单
|
||||
/// </summary>
|
||||
internal PackageManifest Result { set; get; }
|
||||
internal PackageManifest Manifest { set; get; }
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ namespace YooAsset
|
||||
internal abstract class FSRequestPackageVersionOperation : AsyncOperationBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询的最新版本信息
|
||||
/// 资源版本
|
||||
/// </summary>
|
||||
internal string PackageVersion { set; get; }
|
||||
}
|
||||
|
||||
@@ -17,11 +17,8 @@ namespace YooAsset
|
||||
Done,
|
||||
}
|
||||
|
||||
// 初始参数
|
||||
protected readonly string _mainURL;
|
||||
protected readonly string _fallbackURL;
|
||||
protected readonly int _failedTryAgain;
|
||||
protected readonly int _timeout;
|
||||
// 下载参数
|
||||
protected readonly DownloadParam Param;
|
||||
|
||||
// 请求相关
|
||||
protected UnityWebRequest _webRequest;
|
||||
@@ -38,15 +35,10 @@ namespace YooAsset
|
||||
protected int FailedTryAgain;
|
||||
|
||||
|
||||
internal DefaultDownloadFileOperation(PackageBundle bundle,
|
||||
string mainURL, string fallbackURL, int failedTryAgain, int timeout) : base(bundle)
|
||||
internal DefaultDownloadFileOperation(PackageBundle bundle, DownloadParam param) : base(bundle)
|
||||
{
|
||||
_mainURL = mainURL;
|
||||
_fallbackURL = fallbackURL;
|
||||
_failedTryAgain = failedTryAgain;
|
||||
_timeout = timeout;
|
||||
|
||||
FailedTryAgain = failedTryAgain;
|
||||
Param = param;
|
||||
FailedTryAgain = param.FailedTryAgain;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,9 +49,9 @@ namespace YooAsset
|
||||
// 轮流返回请求地址
|
||||
_requestCount++;
|
||||
if (_requestCount % 2 == 0)
|
||||
return _fallbackURL;
|
||||
return Param.FallbackURL;
|
||||
else
|
||||
return _mainURL;
|
||||
return Param.MainURL;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -95,7 +87,7 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
float offset = UnityEngine.Time.realtimeSinceStartup - _latestDownloadRealtime;
|
||||
if (offset > _timeout)
|
||||
if (offset > Param.Timeout)
|
||||
{
|
||||
YooLogger.Warning($"Web file request timeout : {_requestURL}");
|
||||
if (_webRequest != null)
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class DefaultGetRemotePackageVersionOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestPackageVersion,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly string _packageName;
|
||||
private readonly string _mainURL;
|
||||
private readonly string _fallbackURL;
|
||||
private readonly bool _appendTimeTicks;
|
||||
private readonly int _timeout;
|
||||
private UnityWebTextRequestOperation _webTextRequestOp;
|
||||
private int _requestCount = 0;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 查询的远端版本信息
|
||||
/// </summary>
|
||||
internal string PackageVersion { set; get; }
|
||||
|
||||
|
||||
internal DefaultGetRemotePackageVersionOperation(string packageName, string mainURL, string fallbackURL, bool appendTimeTicks, int timeout)
|
||||
{
|
||||
_packageName = packageName;
|
||||
_mainURL = mainURL;
|
||||
_fallbackURL = fallbackURL;
|
||||
_appendTimeTicks = appendTimeTicks;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalOnStart()
|
||||
{
|
||||
_requestCount = WebRequestCounter.GetRequestFailedCount(_packageName, nameof(DefaultGetRemotePackageVersionOperation));
|
||||
_steps = ESteps.RequestPackageVersion;
|
||||
}
|
||||
internal override void InternalOnUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestPackageVersion)
|
||||
{
|
||||
if (_webTextRequestOp == null)
|
||||
{
|
||||
string url = GetPackageVersionRequestURL();
|
||||
YooLogger.Log($"Beginning to request package version : {url}");
|
||||
_webTextRequestOp = new UnityWebTextRequestOperation(url, _timeout);
|
||||
OperationSystem.StartOperation(_packageName, _webTextRequestOp);
|
||||
}
|
||||
|
||||
Progress = _webTextRequestOp.Progress;
|
||||
if (_webTextRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_webTextRequestOp.Status != EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _webTextRequestOp.Error;
|
||||
WebRequestCounter.RecordRequestFailed(_packageName, nameof(DefaultGetRemotePackageVersionOperation));
|
||||
}
|
||||
else
|
||||
{
|
||||
PackageVersion = _webTextRequestOp.Result;
|
||||
if (string.IsNullOrEmpty(PackageVersion))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Remote package version file content is empty !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetPackageVersionRequestURL()
|
||||
{
|
||||
string url;
|
||||
|
||||
// 轮流返回请求地址
|
||||
if (_requestCount % 2 == 0)
|
||||
url = _mainURL;
|
||||
else
|
||||
url = _fallbackURL;
|
||||
|
||||
// 在URL末尾添加时间戳
|
||||
if (_appendTimeTicks)
|
||||
return $"{url}?{System.DateTime.UtcNow.Ticks}";
|
||||
else
|
||||
return url;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b078a220cc4f7d4392d77ccc77c001e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user