mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-30 13:38:46 +00:00
Compare commits
7 Commits
dd6fab46f9
...
053b4a00d7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
053b4a00d7 | ||
|
|
db159428c6 | ||
|
|
ac7ee16017 | ||
|
|
c2fb7c3cbb | ||
|
|
e70b0d37cd | ||
|
|
53db012fc8 | ||
|
|
b3622167da |
@@ -94,4 +94,25 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public long FileSize;
|
public long FileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 导入文件的信息
|
||||||
|
/// </summary>
|
||||||
|
public struct ImportFileInfo
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 本地文件路径
|
||||||
|
/// </summary>
|
||||||
|
public string FilePath;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源包名称
|
||||||
|
/// </summary>
|
||||||
|
public string BundleName;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源包GUID
|
||||||
|
/// </summary>
|
||||||
|
public string BundleGUID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public AssetBundle Result { private set; get; }
|
public AssetBundle Result { private set; get; }
|
||||||
|
|
||||||
internal UnityAssetBundleRequestOperation(PackageBundle packageBundle, bool disableUnityWebCache, string url, int timeout = 60) : base(url, timeout)
|
internal UnityAssetBundleRequestOperation(PackageBundle packageBundle, bool disableUnityWebCache, string url) : base(url)
|
||||||
{
|
{
|
||||||
_packageBundle = packageBundle;
|
_packageBundle = packageBundle;
|
||||||
_disableUnityWebCache = disableUnityWebCache;
|
_disableUnityWebCache = disableUnityWebCache;
|
||||||
@@ -40,7 +40,6 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.CreateRequest)
|
if (_steps == ESteps.CreateRequest)
|
||||||
{
|
{
|
||||||
ResetTimeout();
|
|
||||||
CreateWebRequest();
|
CreateWebRequest();
|
||||||
_steps = ESteps.Download;
|
_steps = ESteps.Download;
|
||||||
}
|
}
|
||||||
@@ -51,10 +50,7 @@ namespace YooAsset
|
|||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
Progress = _requestOperation.progress;
|
Progress = _requestOperation.progress;
|
||||||
if (_requestOperation.isDone == false)
|
if (_requestOperation.isDone == false)
|
||||||
{
|
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (CheckRequestResult())
|
if (CheckRequestResult())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,77 @@
|
|||||||
|
using UnityEngine.Networking;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class UnityWebCacheRequestOperation : UnityWebRequestOperation
|
||||||
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
Download,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private UnityWebRequestAsyncOperation _requestOperation;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
|
internal UnityWebCacheRequestOperation(string url) : base(url)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.CreateRequest)
|
||||||
|
{
|
||||||
|
CreateWebRequest();
|
||||||
|
_steps = ESteps.Download;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.Download)
|
||||||
|
{
|
||||||
|
DownloadProgress = _webRequest.downloadProgress;
|
||||||
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
|
Progress = _requestOperation.progress;
|
||||||
|
if (_requestOperation.isDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (CheckRequestResult())
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注意:最终释放请求器
|
||||||
|
DisposeRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置请求头信息
|
||||||
|
/// </summary>
|
||||||
|
public void SetRequestHeader(string name, string value)
|
||||||
|
{
|
||||||
|
_webRequest.SetRequestHeader(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateWebRequest()
|
||||||
|
{
|
||||||
|
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||||
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
|
_requestOperation = _webRequest.SendWebRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 375d88bcf5b9a6146adaf98ceb5369f8
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -14,17 +14,24 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
private UnityWebRequestAsyncOperation _requestOperation;
|
private UnityWebRequestAsyncOperation _requestOperation;
|
||||||
private bool _checkTimeout = true;
|
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 响应的超时时间(单位:秒),在经过Timeout的秒数后尝试中止。
|
||||||
|
/// 注意:当Timeout设置为0时,不会应用超时。
|
||||||
|
/// 注意:设置的超时值可能应用于Android上的每个URL重定向,这可能会导致响应时间增加。
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _timeout;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 请求结果
|
/// 请求结果
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public byte[] Result { private set; get; }
|
public byte[] Result { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
internal UnityWebDataRequestOperation(string url, int timeout = 60) : base(url, timeout)
|
internal UnityWebDataRequestOperation(string url, int timeout) : base(url)
|
||||||
{
|
{
|
||||||
|
_timeout = timeout;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
@@ -37,7 +44,6 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.CreateRequest)
|
if (_steps == ESteps.CreateRequest)
|
||||||
{
|
{
|
||||||
ResetTimeout();
|
|
||||||
CreateWebRequest();
|
CreateWebRequest();
|
||||||
_steps = ESteps.Download;
|
_steps = ESteps.Download;
|
||||||
}
|
}
|
||||||
@@ -48,11 +54,7 @@ namespace YooAsset
|
|||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
Progress = _requestOperation.progress;
|
Progress = _requestOperation.progress;
|
||||||
if (_requestOperation.isDone == false)
|
if (_requestOperation.isDone == false)
|
||||||
{
|
|
||||||
if (_checkTimeout)
|
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (CheckRequestResult())
|
if (CheckRequestResult())
|
||||||
{
|
{
|
||||||
@@ -81,18 +83,11 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 不检测超时
|
|
||||||
/// </summary>
|
|
||||||
public void DontCheckTimeout()
|
|
||||||
{
|
|
||||||
_checkTimeout = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateWebRequest()
|
private void CreateWebRequest()
|
||||||
{
|
{
|
||||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
|
||||||
DownloadHandlerBuffer handler = new DownloadHandlerBuffer();
|
DownloadHandlerBuffer handler = new DownloadHandlerBuffer();
|
||||||
|
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||||
|
_webRequest.timeout = _timeout;
|
||||||
_webRequest.downloadHandler = handler;
|
_webRequest.downloadHandler = handler;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
_requestOperation = _webRequest.SendWebRequest();
|
_requestOperation = _webRequest.SendWebRequest();
|
||||||
|
|||||||
@@ -17,10 +17,18 @@ namespace YooAsset
|
|||||||
private readonly string _fileSavePath;
|
private readonly string _fileSavePath;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 响应的超时时间(单位:秒),在经过Timeout的秒数后尝试中止。
|
||||||
|
/// 注意:当Timeout设置为0时,不会应用超时。
|
||||||
|
/// 注意:设置的超时值可能应用于Android上的每个URL重定向,这可能会导致响应时间增加。
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _timeout;
|
||||||
|
|
||||||
internal UnityWebFileRequestOperation(string url, string fileSavePath, int timeout = 60) : base(url, timeout)
|
|
||||||
|
internal UnityWebFileRequestOperation(string url, string fileSavePath, int timeout) : base(url)
|
||||||
{
|
{
|
||||||
_fileSavePath = fileSavePath;
|
_fileSavePath = fileSavePath;
|
||||||
|
_timeout = timeout;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
@@ -33,7 +41,6 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.CreateRequest)
|
if (_steps == ESteps.CreateRequest)
|
||||||
{
|
{
|
||||||
ResetTimeout();
|
|
||||||
CreateWebRequest();
|
CreateWebRequest();
|
||||||
_steps = ESteps.Download;
|
_steps = ESteps.Download;
|
||||||
}
|
}
|
||||||
@@ -44,10 +51,7 @@ namespace YooAsset
|
|||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
Progress = _requestOperation.progress;
|
Progress = _requestOperation.progress;
|
||||||
if (_requestOperation.isDone == false)
|
if (_requestOperation.isDone == false)
|
||||||
{
|
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (CheckRequestResult())
|
if (CheckRequestResult())
|
||||||
{
|
{
|
||||||
@@ -67,9 +71,10 @@ namespace YooAsset
|
|||||||
|
|
||||||
private void CreateWebRequest()
|
private void CreateWebRequest()
|
||||||
{
|
{
|
||||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
|
||||||
DownloadHandlerFile handler = new DownloadHandlerFile(_fileSavePath);
|
DownloadHandlerFile handler = new DownloadHandlerFile(_fileSavePath);
|
||||||
handler.removeFileOnAbort = true;
|
handler.removeFileOnAbort = true;
|
||||||
|
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||||
|
_webRequest.timeout = _timeout;
|
||||||
_webRequest.downloadHandler = handler;
|
_webRequest.downloadHandler = handler;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
_requestOperation = _webRequest.SendWebRequest();
|
_requestOperation = _webRequest.SendWebRequest();
|
||||||
|
|||||||
@@ -8,11 +8,6 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
protected UnityWebRequest _webRequest;
|
protected UnityWebRequest _webRequest;
|
||||||
protected readonly string _requestURL;
|
protected readonly string _requestURL;
|
||||||
|
|
||||||
// 超时相关
|
|
||||||
private readonly float _timeout;
|
|
||||||
private ulong _latestDownloadBytes;
|
|
||||||
private float _latestDownloadRealtime;
|
|
||||||
private bool _isAbort = false;
|
private bool _isAbort = false;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -38,10 +33,9 @@ namespace YooAsset
|
|||||||
get { return _requestURL; }
|
get { return _requestURL; }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal UnityWebRequestOperation(string url, int timeout)
|
internal UnityWebRequestOperation(string url)
|
||||||
{
|
{
|
||||||
_requestURL = url;
|
_requestURL = url;
|
||||||
_timeout = timeout;
|
|
||||||
}
|
}
|
||||||
internal override void InternalAbort()
|
internal override void InternalAbort()
|
||||||
{
|
{
|
||||||
@@ -71,42 +65,6 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 重置超时计时
|
|
||||||
/// </summary>
|
|
||||||
protected void ResetTimeout()
|
|
||||||
{
|
|
||||||
_latestDownloadBytes = 0;
|
|
||||||
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 检测超时
|
|
||||||
/// </summary>
|
|
||||||
protected void CheckRequestTimeout()
|
|
||||||
{
|
|
||||||
if (_webRequest.isDone)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 注意:在连续时间段内无新增下载数据及判定为超时
|
|
||||||
if (_isAbort == false)
|
|
||||||
{
|
|
||||||
if (_latestDownloadBytes != _webRequest.downloadedBytes)
|
|
||||||
{
|
|
||||||
_latestDownloadBytes = _webRequest.downloadedBytes;
|
|
||||||
_latestDownloadRealtime = Time.realtimeSinceStartup;
|
|
||||||
}
|
|
||||||
|
|
||||||
float offset = Time.realtimeSinceStartup - _latestDownloadRealtime;
|
|
||||||
if (offset > _timeout)
|
|
||||||
{
|
|
||||||
YooLogger.Warning($"Web request timeout : {_requestURL}");
|
|
||||||
_webRequest.Abort();
|
|
||||||
_isAbort = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 检测请求结果
|
/// 检测请求结果
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -16,14 +16,22 @@ namespace YooAsset
|
|||||||
private UnityWebRequestAsyncOperation _requestOperation;
|
private UnityWebRequestAsyncOperation _requestOperation;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 响应的超时时间(单位:秒),在经过Timeout的秒数后尝试中止。
|
||||||
|
/// 注意:当Timeout设置为0时,不会应用超时。
|
||||||
|
/// 注意:设置的超时值可能应用于Android上的每个URL重定向,这可能会导致响应时间增加。
|
||||||
|
/// </summary>
|
||||||
|
private readonly int _timeout;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 请求结果
|
/// 请求结果
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Result { private set; get; }
|
public string Result { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
internal UnityWebTextRequestOperation(string url, int timeout = 60) : base(url, timeout)
|
internal UnityWebTextRequestOperation(string url, int timeout) : base(url)
|
||||||
{
|
{
|
||||||
|
_timeout = timeout;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
@@ -36,7 +44,6 @@ namespace YooAsset
|
|||||||
|
|
||||||
if (_steps == ESteps.CreateRequest)
|
if (_steps == ESteps.CreateRequest)
|
||||||
{
|
{
|
||||||
ResetTimeout();
|
|
||||||
CreateWebRequest();
|
CreateWebRequest();
|
||||||
_steps = ESteps.Download;
|
_steps = ESteps.Download;
|
||||||
}
|
}
|
||||||
@@ -47,10 +54,7 @@ namespace YooAsset
|
|||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
Progress = _requestOperation.progress;
|
Progress = _requestOperation.progress;
|
||||||
if (_requestOperation.isDone == false)
|
if (_requestOperation.isDone == false)
|
||||||
{
|
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (CheckRequestResult())
|
if (CheckRequestResult())
|
||||||
{
|
{
|
||||||
@@ -81,8 +85,9 @@ namespace YooAsset
|
|||||||
|
|
||||||
private void CreateWebRequest()
|
private void CreateWebRequest()
|
||||||
{
|
{
|
||||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
|
||||||
DownloadHandlerBuffer handler = new DownloadHandlerBuffer();
|
DownloadHandlerBuffer handler = new DownloadHandlerBuffer();
|
||||||
|
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||||
|
_webRequest.timeout = _timeout;
|
||||||
_webRequest.downloadHandler = handler;
|
_webRequest.downloadHandler = handler;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
_requestOperation = _webRequest.SendWebRequest();
|
_requestOperation = _webRequest.SendWebRequest();
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ namespace YooAsset
|
|||||||
string sourcePath = _fileSystem.GetBuildinPackageHashFilePath(_buildinPackageVersion);
|
string sourcePath = _fileSystem.GetBuildinPackageHashFilePath(_buildinPackageVersion);
|
||||||
string destPath = GetCopyPackageHashDestPath(_buildinPackageVersion);
|
string destPath = GetCopyPackageHashDestPath(_buildinPackageVersion);
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
||||||
_hashFileRequestOp = new UnityWebFileRequestOperation(url, destPath);
|
_hashFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60);
|
||||||
_hashFileRequestOp.StartOperation();
|
_hashFileRequestOp.StartOperation();
|
||||||
AddChildOperation(_hashFileRequestOp);
|
AddChildOperation(_hashFileRequestOp);
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,7 @@ namespace YooAsset
|
|||||||
string sourcePath = _fileSystem.GetBuildinPackageManifestFilePath(_buildinPackageVersion);
|
string sourcePath = _fileSystem.GetBuildinPackageManifestFilePath(_buildinPackageVersion);
|
||||||
string destPath = GetCopyPackageManifestDestPath(_buildinPackageVersion);
|
string destPath = GetCopyPackageManifestDestPath(_buildinPackageVersion);
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
||||||
_manifestFileRequestOp = new UnityWebFileRequestOperation(url, destPath);
|
_manifestFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60);
|
||||||
_manifestFileRequestOp.StartOperation();
|
_manifestFileRequestOp.StartOperation();
|
||||||
AddChildOperation(_manifestFileRequestOp);
|
AddChildOperation(_manifestFileRequestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
string filePath = _fileSystem.GetCatalogBinaryFileLoadPath();
|
string filePath = _fileSystem.GetCatalogBinaryFileLoadPath();
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||||
_webDataRequestOp = new UnityWebDataRequestOperation(url);
|
_webDataRequestOp = new UnityWebDataRequestOperation(url, 60);
|
||||||
_webDataRequestOp.StartOperation();
|
_webDataRequestOp.StartOperation();
|
||||||
AddChildOperation(_webDataRequestOp);
|
AddChildOperation(_webDataRequestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
string filePath = _fileSystem.GetBuildinPackageManifestFilePath(_packageVersion);
|
string filePath = _fileSystem.GetBuildinPackageManifestFilePath(_packageVersion);
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||||
_webDataRequestOp = new UnityWebDataRequestOperation(url);
|
_webDataRequestOp = new UnityWebDataRequestOperation(url, 60);
|
||||||
_webDataRequestOp.StartOperation();
|
_webDataRequestOp.StartOperation();
|
||||||
AddChildOperation(_webDataRequestOp);
|
AddChildOperation(_webDataRequestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
string filePath = _fileSystem.GetBuildinPackageHashFilePath(_packageVersion);
|
string filePath = _fileSystem.GetBuildinPackageHashFilePath(_packageVersion);
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||||
_webTextRequestOp = new UnityWebTextRequestOperation(url);
|
_webTextRequestOp = new UnityWebTextRequestOperation(url, 60);
|
||||||
_webTextRequestOp.StartOperation();
|
_webTextRequestOp.StartOperation();
|
||||||
AddChildOperation(_webTextRequestOp);
|
AddChildOperation(_webTextRequestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
string filePath = _fileSystem.GetBuildinPackageVersionFilePath();
|
string filePath = _fileSystem.GetBuildinPackageVersionFilePath();
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||||
_webTextRequestOp = new UnityWebTextRequestOperation(url);
|
_webTextRequestOp = new UnityWebTextRequestOperation(url, 60);
|
||||||
_webTextRequestOp.StartOperation();
|
_webTextRequestOp.StartOperation();
|
||||||
AddChildOperation(_webTextRequestOp);
|
AddChildOperation(_webTextRequestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (_downloadFileOp == null)
|
if (_downloadFileOp == null)
|
||||||
{
|
{
|
||||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
|
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||||
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options);
|
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options);
|
||||||
_downloadFileOp.StartOperation();
|
_downloadFileOp.StartOperation();
|
||||||
AddChildOperation(_downloadFileOp);
|
AddChildOperation(_downloadFileOp);
|
||||||
@@ -304,7 +304,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (_downloadFileOp == null)
|
if (_downloadFileOp == null)
|
||||||
{
|
{
|
||||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
|
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||||
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options);
|
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options);
|
||||||
_downloadFileOp.StartOperation();
|
_downloadFileOp.StartOperation();
|
||||||
AddChildOperation(_downloadFileOp);
|
AddChildOperation(_downloadFileOp);
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建下载任务
|
/// 创建下载任务
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public UnityDownloadFileOperation DownloadFileAsync(PackageBundle bundle, string url, int timeout)
|
public UnityDownloadFileOperation DownloadFileAsync(PackageBundle bundle, string url)
|
||||||
{
|
{
|
||||||
// 查询旧的下载器
|
// 查询旧的下载器
|
||||||
if (_downloaders.TryGetValue(bundle.BundleGUID, out var oldDownloader))
|
if (_downloaders.TryGetValue(bundle.BundleGUID, out var oldDownloader))
|
||||||
@@ -99,7 +99,7 @@ namespace YooAsset
|
|||||||
bool isRequestLocalFile = DownloadSystemHelper.IsRequestLocalFile(url);
|
bool isRequestLocalFile = DownloadSystemHelper.IsRequestLocalFile(url);
|
||||||
if (isRequestLocalFile)
|
if (isRequestLocalFile)
|
||||||
{
|
{
|
||||||
newDownloader = new UnityDownloadLocalFileOperation(_fileSystem, bundle, url, timeout);
|
newDownloader = new UnityDownloadLocalFileOperation(_fileSystem, bundle, url);
|
||||||
AddChildOperation(newDownloader);
|
AddChildOperation(newDownloader);
|
||||||
_downloaders.Add(bundle.BundleGUID, newDownloader);
|
_downloaders.Add(bundle.BundleGUID, newDownloader);
|
||||||
}
|
}
|
||||||
@@ -107,13 +107,13 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
if (bundle.FileSize >= _fileSystem.ResumeDownloadMinimumSize)
|
if (bundle.FileSize >= _fileSystem.ResumeDownloadMinimumSize)
|
||||||
{
|
{
|
||||||
newDownloader = new UnityDownloadResumeFileOperation(_fileSystem, bundle, url, timeout);
|
newDownloader = new UnityDownloadResumeFileOperation(_fileSystem, bundle, url);
|
||||||
AddChildOperation(newDownloader);
|
AddChildOperation(newDownloader);
|
||||||
_downloaders.Add(bundle.BundleGUID, newDownloader);
|
_downloaders.Add(bundle.BundleGUID, newDownloader);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
newDownloader = new UnityDownloadNormalFileOperation(_fileSystem, bundle, url, timeout);
|
newDownloader = new UnityDownloadNormalFileOperation(_fileSystem, bundle, url);
|
||||||
AddChildOperation(newDownloader);
|
AddChildOperation(newDownloader);
|
||||||
_downloaders.Add(bundle.BundleGUID, newDownloader);
|
_downloaders.Add(bundle.BundleGUID, newDownloader);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
string url = GetRequestURL();
|
string url = GetRequestURL();
|
||||||
_unityDownloadFileOp = _fileSystem.DownloadCenter.DownloadFileAsync(Bundle, url, _options.Timeout);
|
_unityDownloadFileOp = _fileSystem.DownloadCenter.DownloadFileAsync(Bundle, url);
|
||||||
_steps = ESteps.CheckRequest;
|
_steps = ESteps.CheckRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public int RefCount { private set; get; }
|
public int RefCount { private set; get; }
|
||||||
|
|
||||||
internal UnityDownloadFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string url, int timeout) : base(url, timeout)
|
internal UnityDownloadFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string url) : base(url)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_bundle = bundle;
|
_bundle = bundle;
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ namespace YooAsset
|
|||||||
private VerifyTempFileOperation _verifyOperation;
|
private VerifyTempFileOperation _verifyOperation;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal UnityDownloadLocalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string url, int timeout = 60)
|
internal UnityDownloadLocalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string url)
|
||||||
: base(fileSystem, bundle, url, timeout)
|
: base(fileSystem, bundle, url)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
@@ -32,7 +32,6 @@ namespace YooAsset
|
|||||||
if (File.Exists(_tempFilePath))
|
if (File.Exists(_tempFilePath))
|
||||||
File.Delete(_tempFilePath);
|
File.Delete(_tempFilePath);
|
||||||
|
|
||||||
ResetTimeout();
|
|
||||||
CreateWebRequest();
|
CreateWebRequest();
|
||||||
_steps = ESteps.Download;
|
_steps = ESteps.Download;
|
||||||
}
|
}
|
||||||
@@ -44,10 +43,7 @@ namespace YooAsset
|
|||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
Progress = DownloadProgress;
|
Progress = DownloadProgress;
|
||||||
if (_webRequest.isDone == false)
|
if (_webRequest.isDone == false)
|
||||||
{
|
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// 检查网络错误
|
// 检查网络错误
|
||||||
if (CheckRequestResult())
|
if (CheckRequestResult())
|
||||||
@@ -161,9 +157,9 @@ namespace YooAsset
|
|||||||
|
|
||||||
private void CreateWebRequest()
|
private void CreateWebRequest()
|
||||||
{
|
{
|
||||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
|
||||||
DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath);
|
DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath);
|
||||||
handler.removeFileOnAbort = true;
|
handler.removeFileOnAbort = true;
|
||||||
|
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||||
_webRequest.downloadHandler = handler;
|
_webRequest.downloadHandler = handler;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
_webRequest.SendWebRequest();
|
_webRequest.SendWebRequest();
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ namespace YooAsset
|
|||||||
private VerifyTempFileOperation _verifyOperation;
|
private VerifyTempFileOperation _verifyOperation;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal UnityDownloadNormalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string url, int timeout = 60)
|
internal UnityDownloadNormalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string url)
|
||||||
: base(fileSystem, bundle, url, timeout)
|
: base(fileSystem, bundle, url)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
@@ -29,7 +29,6 @@ namespace YooAsset
|
|||||||
if (File.Exists(_tempFilePath))
|
if (File.Exists(_tempFilePath))
|
||||||
File.Delete(_tempFilePath);
|
File.Delete(_tempFilePath);
|
||||||
|
|
||||||
ResetTimeout();
|
|
||||||
CreateWebRequest();
|
CreateWebRequest();
|
||||||
_steps = ESteps.Download;
|
_steps = ESteps.Download;
|
||||||
}
|
}
|
||||||
@@ -41,10 +40,7 @@ namespace YooAsset
|
|||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
Progress = DownloadProgress;
|
Progress = DownloadProgress;
|
||||||
if (_webRequest.isDone == false)
|
if (_webRequest.isDone == false)
|
||||||
{
|
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// 检查网络错误
|
// 检查网络错误
|
||||||
if (CheckRequestResult())
|
if (CheckRequestResult())
|
||||||
@@ -115,9 +111,9 @@ namespace YooAsset
|
|||||||
|
|
||||||
private void CreateWebRequest()
|
private void CreateWebRequest()
|
||||||
{
|
{
|
||||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
|
||||||
DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath);
|
DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath);
|
||||||
handler.removeFileOnAbort = true;
|
handler.removeFileOnAbort = true;
|
||||||
|
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||||
_webRequest.downloadHandler = handler;
|
_webRequest.downloadHandler = handler;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
_webRequest.SendWebRequest();
|
_webRequest.SendWebRequest();
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ namespace YooAsset
|
|||||||
private long _fileOriginLength = 0;
|
private long _fileOriginLength = 0;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal UnityDownloadResumeFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string url, int timeout = 60)
|
internal UnityDownloadResumeFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string url)
|
||||||
: base(fileSystem, bundle, url, timeout)
|
: base(fileSystem, bundle, url)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
@@ -46,7 +46,6 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ResetTimeout();
|
|
||||||
CreateWebRequest(fileBeginLength);
|
CreateWebRequest(fileBeginLength);
|
||||||
_steps = ESteps.Download;
|
_steps = ESteps.Download;
|
||||||
}
|
}
|
||||||
@@ -58,10 +57,7 @@ namespace YooAsset
|
|||||||
DownloadedBytes = _fileOriginLength + (long)_webRequest.downloadedBytes;
|
DownloadedBytes = _fileOriginLength + (long)_webRequest.downloadedBytes;
|
||||||
Progress = DownloadProgress;
|
Progress = DownloadProgress;
|
||||||
if (_webRequest.isDone == false)
|
if (_webRequest.isDone == false)
|
||||||
{
|
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// 检查网络错误
|
// 检查网络错误
|
||||||
if (CheckRequestResult())
|
if (CheckRequestResult())
|
||||||
@@ -147,9 +143,9 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
private void CreateWebRequest(long fileBeginLength)
|
private void CreateWebRequest(long fileBeginLength)
|
||||||
{
|
{
|
||||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
|
||||||
var handler = new DownloadHandlerFile(_tempFilePath, true);
|
var handler = new DownloadHandlerFile(_tempFilePath, true);
|
||||||
handler.removeFileOnAbort = false;
|
handler.removeFileOnAbort = false;
|
||||||
|
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||||
_webRequest.downloadHandler = handler;
|
_webRequest.downloadHandler = handler;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
if (fileBeginLength > 0)
|
if (fileBeginLength > 0)
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ namespace YooAsset
|
|||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
DownloadAssetBundle,
|
LoadWebAssetBundle,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly DefaultWebRemoteFileSystem _fileSystem;
|
private readonly DefaultWebRemoteFileSystem _fileSystem;
|
||||||
private readonly PackageBundle _bundle;
|
private readonly PackageBundle _bundle;
|
||||||
private DownloadAssetBundleOperation _downloadAssetBundleOp;
|
private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
@@ -23,51 +23,51 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
_steps = ESteps.DownloadAssetBundle;
|
_steps = ESteps.LoadWebAssetBundle;
|
||||||
}
|
}
|
||||||
internal override void InternalUpdate()
|
internal override void InternalUpdate()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_steps == ESteps.DownloadAssetBundle)
|
if (_steps == ESteps.LoadWebAssetBundle)
|
||||||
{
|
{
|
||||||
if (_downloadAssetBundleOp == null)
|
if (_loadWebAssetBundleOp == null)
|
||||||
{
|
{
|
||||||
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
|
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
|
||||||
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
||||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
|
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||||
options.SetURL(mainURL, fallbackURL);
|
options.SetURL(mainURL, fallbackURL);
|
||||||
|
|
||||||
if (_bundle.Encrypted)
|
if (_bundle.Encrypted)
|
||||||
{
|
{
|
||||||
_downloadAssetBundleOp = new DownloadEncryptAssetBundleOperation(_bundle, options, true, _fileSystem.DecryptionServices);
|
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices);
|
||||||
_downloadAssetBundleOp.StartOperation();
|
_loadWebAssetBundleOp.StartOperation();
|
||||||
AddChildOperation(_downloadAssetBundleOp);
|
AddChildOperation(_loadWebAssetBundleOp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_downloadAssetBundleOp = new DownloadNormalAssetBundleOperation(_bundle, options, _fileSystem.DisableUnityWebCache);
|
_loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(_bundle, options, _fileSystem.DisableUnityWebCache);
|
||||||
_downloadAssetBundleOp.StartOperation();
|
_loadWebAssetBundleOp.StartOperation();
|
||||||
AddChildOperation(_downloadAssetBundleOp);
|
AddChildOperation(_loadWebAssetBundleOp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_downloadAssetBundleOp.UpdateOperation();
|
_loadWebAssetBundleOp.UpdateOperation();
|
||||||
DownloadProgress = _downloadAssetBundleOp.DownloadProgress;
|
DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
|
||||||
DownloadedBytes = _downloadAssetBundleOp.DownloadedBytes;
|
DownloadedBytes = _loadWebAssetBundleOp.DownloadedBytes;
|
||||||
Progress = _downloadAssetBundleOp.Progress;
|
Progress = _loadWebAssetBundleOp.Progress;
|
||||||
if (_downloadAssetBundleOp.IsDone == false)
|
if (_loadWebAssetBundleOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_downloadAssetBundleOp.Status == EOperationStatus.Succeed)
|
if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
var assetBundle = _downloadAssetBundleOp.Result;
|
var assetBundle = _loadWebAssetBundleOp.Result;
|
||||||
if (assetBundle == null)
|
if (assetBundle == null)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = $"{nameof(DownloadAssetBundleOperation)} loaded asset bundle is null !";
|
Error = $"{nameof(LoadWebAssetBundleOperation)} loaded asset bundle is null !";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -80,7 +80,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _downloadAssetBundleOp.Error;
|
Error = _loadWebAssetBundleOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ namespace YooAsset
|
|||||||
if (_loadWebPackageManifestOp == null)
|
if (_loadWebPackageManifestOp == null)
|
||||||
{
|
{
|
||||||
string packageHash = _requestWebPackageHashOp.PackageHash;
|
string packageHash = _requestWebPackageHashOp.PackageHash;
|
||||||
_loadWebPackageManifestOp = new LoadWebRemotePackageManifestOperation(_fileSystem, _packageVersion, packageHash);
|
_loadWebPackageManifestOp = new LoadWebRemotePackageManifestOperation(_fileSystem, _packageVersion, packageHash, _timeout);
|
||||||
_loadWebPackageManifestOp.StartOperation();
|
_loadWebPackageManifestOp.StartOperation();
|
||||||
AddChildOperation(_loadWebPackageManifestOp);
|
AddChildOperation(_loadWebPackageManifestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace YooAsset
|
|||||||
private readonly DefaultWebRemoteFileSystem _fileSystem;
|
private readonly DefaultWebRemoteFileSystem _fileSystem;
|
||||||
private readonly string _packageVersion;
|
private readonly string _packageVersion;
|
||||||
private readonly string _packageHash;
|
private readonly string _packageHash;
|
||||||
|
private readonly int _timeout;
|
||||||
private UnityWebDataRequestOperation _webDataRequestOp;
|
private UnityWebDataRequestOperation _webDataRequestOp;
|
||||||
private DeserializeManifestOperation _deserializer;
|
private DeserializeManifestOperation _deserializer;
|
||||||
private int _requestCount = 0;
|
private int _requestCount = 0;
|
||||||
@@ -26,11 +27,12 @@ namespace YooAsset
|
|||||||
public PackageManifest Manifest { private set; get; }
|
public PackageManifest Manifest { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
internal LoadWebRemotePackageManifestOperation(DefaultWebRemoteFileSystem fileSystem, string packageVersion, string packageHash)
|
internal LoadWebRemotePackageManifestOperation(DefaultWebRemoteFileSystem fileSystem, string packageVersion, string packageHash, int timeout)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_packageVersion = packageVersion;
|
_packageVersion = packageVersion;
|
||||||
_packageHash = packageHash;
|
_packageHash = packageHash;
|
||||||
|
_timeout = timeout;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
@@ -48,7 +50,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_fileSystem.PackageName, _packageVersion);
|
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_fileSystem.PackageName, _packageVersion);
|
||||||
string url = GetWebRequestURL(fileName);
|
string url = GetWebRequestURL(fileName);
|
||||||
_webDataRequestOp = new UnityWebDataRequestOperation(url);
|
_webDataRequestOp = new UnityWebDataRequestOperation(url, _timeout);
|
||||||
_webDataRequestOp.StartOperation();
|
_webDataRequestOp.StartOperation();
|
||||||
AddChildOperation(_webDataRequestOp);
|
AddChildOperation(_webDataRequestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace YooAsset
|
|||||||
*/
|
*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
_loadCatalogFileOp = new LoadWebServerCatalogFileOperation(_fileSystem);
|
_loadCatalogFileOp = new LoadWebServerCatalogFileOperation(_fileSystem, 60);
|
||||||
_loadCatalogFileOp.StartOperation();
|
_loadCatalogFileOp.StartOperation();
|
||||||
AddChildOperation(_loadCatalogFileOp);
|
AddChildOperation(_loadCatalogFileOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ namespace YooAsset
|
|||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
DownloadAssetBundle,
|
LoadWebAssetBundle,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly DefaultWebServerFileSystem _fileSystem;
|
private readonly DefaultWebServerFileSystem _fileSystem;
|
||||||
private readonly PackageBundle _bundle;
|
private readonly PackageBundle _bundle;
|
||||||
private DownloadAssetBundleOperation _downloadAssetBundleOp;
|
private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
@@ -23,51 +23,51 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
_steps = ESteps.DownloadAssetBundle;
|
_steps = ESteps.LoadWebAssetBundle;
|
||||||
}
|
}
|
||||||
internal override void InternalUpdate()
|
internal override void InternalUpdate()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_steps == ESteps.DownloadAssetBundle)
|
if (_steps == ESteps.LoadWebAssetBundle)
|
||||||
{
|
{
|
||||||
if (_downloadAssetBundleOp == null)
|
if (_loadWebAssetBundleOp == null)
|
||||||
{
|
{
|
||||||
string fileLoadPath = _fileSystem.GetWebFileLoadPath(_bundle);
|
string fileLoadPath = _fileSystem.GetWebFileLoadPath(_bundle);
|
||||||
string mainURL = DownloadSystemHelper.ConvertToWWWPath(fileLoadPath);
|
string mainURL = DownloadSystemHelper.ConvertToWWWPath(fileLoadPath);
|
||||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
|
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||||
options.SetURL(mainURL, mainURL);
|
options.SetURL(mainURL, mainURL);
|
||||||
|
|
||||||
if (_bundle.Encrypted)
|
if (_bundle.Encrypted)
|
||||||
{
|
{
|
||||||
_downloadAssetBundleOp = new DownloadEncryptAssetBundleOperation(_bundle, options, true, _fileSystem.DecryptionServices);
|
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices);
|
||||||
_downloadAssetBundleOp.StartOperation();
|
_loadWebAssetBundleOp.StartOperation();
|
||||||
AddChildOperation(_downloadAssetBundleOp);
|
AddChildOperation(_loadWebAssetBundleOp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_downloadAssetBundleOp = new DownloadNormalAssetBundleOperation(_bundle, options, _fileSystem.DisableUnityWebCache);
|
_loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(_bundle, options, _fileSystem.DisableUnityWebCache);
|
||||||
_downloadAssetBundleOp.StartOperation();
|
_loadWebAssetBundleOp.StartOperation();
|
||||||
AddChildOperation(_downloadAssetBundleOp);
|
AddChildOperation(_loadWebAssetBundleOp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_downloadAssetBundleOp.UpdateOperation();
|
_loadWebAssetBundleOp.UpdateOperation();
|
||||||
DownloadProgress = _downloadAssetBundleOp.DownloadProgress;
|
DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
|
||||||
DownloadedBytes = _downloadAssetBundleOp.DownloadedBytes;
|
DownloadedBytes = _loadWebAssetBundleOp.DownloadedBytes;
|
||||||
Progress = _downloadAssetBundleOp.Progress;
|
Progress = _loadWebAssetBundleOp.Progress;
|
||||||
if (_downloadAssetBundleOp.IsDone == false)
|
if (_loadWebAssetBundleOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_downloadAssetBundleOp.Status == EOperationStatus.Succeed)
|
if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
var assetBundle = _downloadAssetBundleOp.Result;
|
var assetBundle = _loadWebAssetBundleOp.Result;
|
||||||
if (assetBundle == null)
|
if (assetBundle == null)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = $"{nameof(DownloadAssetBundleOperation)} loaded asset bundle is null !";
|
Error = $"{nameof(LoadWebAssetBundleOperation)} loaded asset bundle is null !";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -80,7 +80,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _downloadAssetBundleOp.Error;
|
Error = _loadWebAssetBundleOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ namespace YooAsset
|
|||||||
if (_loadWebPackageManifestOp == null)
|
if (_loadWebPackageManifestOp == null)
|
||||||
{
|
{
|
||||||
string packageHash = _requestWebPackageHashOp.PackageHash;
|
string packageHash = _requestWebPackageHashOp.PackageHash;
|
||||||
_loadWebPackageManifestOp = new LoadWebServerPackageManifestOperation(_fileSystem, _packageVersion, packageHash);
|
_loadWebPackageManifestOp = new LoadWebServerPackageManifestOperation(_fileSystem, _packageVersion, packageHash, _timeout);
|
||||||
_loadWebPackageManifestOp.StartOperation();
|
_loadWebPackageManifestOp.StartOperation();
|
||||||
AddChildOperation(_loadWebPackageManifestOp);
|
AddChildOperation(_loadWebPackageManifestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,12 +16,14 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly DefaultWebServerFileSystem _fileSystem;
|
private readonly DefaultWebServerFileSystem _fileSystem;
|
||||||
|
private readonly int _timeout;
|
||||||
private UnityWebDataRequestOperation _webDataRequestOp;
|
private UnityWebDataRequestOperation _webDataRequestOp;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal LoadWebServerCatalogFileOperation(DefaultWebServerFileSystem fileSystem)
|
internal LoadWebServerCatalogFileOperation(DefaultWebServerFileSystem fileSystem, int timeout)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
|
_timeout = timeout;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
@@ -38,7 +40,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
string filePath = _fileSystem.GetCatalogBinaryFileLoadPath();
|
string filePath = _fileSystem.GetCatalogBinaryFileLoadPath();
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||||
_webDataRequestOp = new UnityWebDataRequestOperation(url);
|
_webDataRequestOp = new UnityWebDataRequestOperation(url, _timeout);
|
||||||
_webDataRequestOp.StartOperation();
|
_webDataRequestOp.StartOperation();
|
||||||
AddChildOperation(_webDataRequestOp);
|
AddChildOperation(_webDataRequestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace YooAsset
|
|||||||
private readonly DefaultWebServerFileSystem _fileSystem;
|
private readonly DefaultWebServerFileSystem _fileSystem;
|
||||||
private readonly string _packageVersion;
|
private readonly string _packageVersion;
|
||||||
private readonly string _packageHash;
|
private readonly string _packageHash;
|
||||||
|
private readonly int _timeout;
|
||||||
private UnityWebDataRequestOperation _webDataRequestOp;
|
private UnityWebDataRequestOperation _webDataRequestOp;
|
||||||
private DeserializeManifestOperation _deserializer;
|
private DeserializeManifestOperation _deserializer;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
@@ -25,11 +26,12 @@ namespace YooAsset
|
|||||||
public PackageManifest Manifest { private set; get; }
|
public PackageManifest Manifest { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
internal LoadWebServerPackageManifestOperation(DefaultWebServerFileSystem fileSystem, string packageVersion, string packageHash)
|
internal LoadWebServerPackageManifestOperation(DefaultWebServerFileSystem fileSystem, string packageVersion, string packageHash, int timeout)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_packageVersion = packageVersion;
|
_packageVersion = packageVersion;
|
||||||
_packageHash = packageHash;
|
_packageHash = packageHash;
|
||||||
|
_timeout = timeout;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
@@ -46,7 +48,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
string filePath = _fileSystem.GetWebPackageManifestFilePath(_packageVersion);
|
string filePath = _fileSystem.GetWebPackageManifestFilePath(_packageVersion);
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||||
_webDataRequestOp = new UnityWebDataRequestOperation(url);
|
_webDataRequestOp = new UnityWebDataRequestOperation(url, _timeout);
|
||||||
_webDataRequestOp.StartOperation();
|
_webDataRequestOp.StartOperation();
|
||||||
AddChildOperation(_webDataRequestOp);
|
AddChildOperation(_webDataRequestOp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,11 +8,6 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly int FailedTryAgain;
|
public readonly int FailedTryAgain;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 超时时间
|
|
||||||
/// </summary>
|
|
||||||
public readonly int Timeout;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 主资源地址
|
/// 主资源地址
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -28,10 +23,9 @@ namespace YooAsset
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string ImportFilePath { set; get; }
|
public string ImportFilePath { set; get; }
|
||||||
|
|
||||||
public DownloadFileOptions(int failedTryAgain, int timeout)
|
public DownloadFileOptions(int failedTryAgain)
|
||||||
{
|
{
|
||||||
FailedTryAgain = failedTryAgain;
|
FailedTryAgain = failedTryAgain;
|
||||||
Timeout = timeout;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
internal abstract class DownloadAssetBundleOperation : AsyncOperationBase
|
internal abstract class LoadWebAssetBundleOperation : AsyncOperationBase
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// AssetBundle对象
|
/// AssetBundle对象
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
internal class DownloadEncryptAssetBundleOperation : DownloadAssetBundleOperation
|
internal class LoadWebEncryptAssetBundleOperation : LoadWebAssetBundleOperation
|
||||||
{
|
{
|
||||||
protected enum ESteps
|
protected enum ESteps
|
||||||
{
|
{
|
||||||
@@ -16,7 +16,6 @@ namespace YooAsset
|
|||||||
private UnityWebDataRequestOperation _unityWebDataRequestOp;
|
private UnityWebDataRequestOperation _unityWebDataRequestOp;
|
||||||
private readonly PackageBundle _bundle;
|
private readonly PackageBundle _bundle;
|
||||||
private readonly DownloadFileOptions _options;
|
private readonly DownloadFileOptions _options;
|
||||||
private readonly bool _checkTimeout;
|
|
||||||
private readonly IWebDecryptionServices _decryptionServices;
|
private readonly IWebDecryptionServices _decryptionServices;
|
||||||
|
|
||||||
protected int _requestCount = 0;
|
protected int _requestCount = 0;
|
||||||
@@ -24,11 +23,10 @@ namespace YooAsset
|
|||||||
protected int _failedTryAgain;
|
protected int _failedTryAgain;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal DownloadEncryptAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options, bool checkTimeout, IWebDecryptionServices decryptionServices)
|
internal LoadWebEncryptAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options, IWebDecryptionServices decryptionServices)
|
||||||
{
|
{
|
||||||
_bundle = bundle;
|
_bundle = bundle;
|
||||||
_options = options;
|
_options = options;
|
||||||
_checkTimeout = checkTimeout;
|
|
||||||
_decryptionServices = decryptionServices;
|
_decryptionServices = decryptionServices;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
@@ -53,10 +51,8 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
string url = GetRequestURL();
|
string url = GetRequestURL();
|
||||||
_unityWebDataRequestOp = new UnityWebDataRequestOperation(url, _options.Timeout);
|
_unityWebDataRequestOp = new UnityWebDataRequestOperation(url, 0);
|
||||||
_unityWebDataRequestOp.StartOperation();
|
_unityWebDataRequestOp.StartOperation();
|
||||||
if (_checkTimeout == false)
|
|
||||||
_unityWebDataRequestOp.DontCheckTimeout();
|
|
||||||
_steps = ESteps.CheckRequest;
|
_steps = ESteps.CheckRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
internal class DownloadNormalAssetBundleOperation : DownloadAssetBundleOperation
|
internal class LoadWebNormalAssetBundleOperation : LoadWebAssetBundleOperation
|
||||||
{
|
{
|
||||||
protected enum ESteps
|
protected enum ESteps
|
||||||
{
|
{
|
||||||
@@ -13,18 +13,18 @@ namespace YooAsset
|
|||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private UnityAssetBundleRequestOperation _unityAssetBundleRequestOp;
|
|
||||||
private readonly PackageBundle _bundle;
|
private readonly PackageBundle _bundle;
|
||||||
private readonly DownloadFileOptions _options;
|
private readonly DownloadFileOptions _options;
|
||||||
private readonly bool _disableUnityWebCache;
|
private readonly bool _disableUnityWebCache;
|
||||||
|
private UnityAssetBundleRequestOperation _unityAssetBundleRequestOp;
|
||||||
|
|
||||||
protected int _requestCount = 0;
|
protected int _requestCount = 0;
|
||||||
protected float _tryAgainTimer;
|
protected float _tryAgainTimer;
|
||||||
protected int _failedTryAgain;
|
protected int _failedTryAgain;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
internal DownloadNormalAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options, bool disableUnityWebCache)
|
internal LoadWebNormalAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options, bool disableUnityWebCache)
|
||||||
{
|
{
|
||||||
_bundle = bundle;
|
_bundle = bundle;
|
||||||
_options = options;
|
_options = options;
|
||||||
@@ -43,7 +43,7 @@ namespace YooAsset
|
|||||||
if (_steps == ESteps.CreateRequest)
|
if (_steps == ESteps.CreateRequest)
|
||||||
{
|
{
|
||||||
string url = GetRequestURL();
|
string url = GetRequestURL();
|
||||||
_unityAssetBundleRequestOp = new UnityAssetBundleRequestOperation(_bundle, _disableUnityWebCache, url, _options.Timeout);
|
_unityAssetBundleRequestOp = new UnityAssetBundleRequestOperation(_bundle, _disableUnityWebCache, url);
|
||||||
_unityAssetBundleRequestOp.StartOperation();
|
_unityAssetBundleRequestOp.StartOperation();
|
||||||
_steps = ESteps.CheckRequest;
|
_steps = ESteps.CheckRequest;
|
||||||
}
|
}
|
||||||
@@ -3,7 +3,7 @@ using System.Reflection;
|
|||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
public static class PakcageInvokeBuilder
|
public static class PackageInvokeBuilder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 调用Editro类来执行构建资源包任务
|
/// 调用Editro类来执行构建资源包任务
|
||||||
@@ -32,7 +32,7 @@ namespace YooAsset
|
|||||||
#else
|
#else
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
public static class PakcageInvokeBuilder
|
public static class PackageInvokeBuilder
|
||||||
{
|
{
|
||||||
public static PackageInvokeBuildResult InvokeBuilder(PackageInvokeBuildParam buildParam)
|
public static PackageInvokeBuildResult InvokeBuilder(PackageInvokeBuildParam buildParam)
|
||||||
{
|
{
|
||||||
@@ -36,9 +36,9 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建下载器
|
/// 创建下载器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public FSDownloadFileOperation CreateDownloader(int failedTryAgain, int timeout)
|
public FSDownloadFileOperation CreateDownloader(int failedTryAgain)
|
||||||
{
|
{
|
||||||
DownloadFileOptions options = new DownloadFileOptions(failedTryAgain, timeout);
|
DownloadFileOptions options = new DownloadFileOptions(failedTryAgain);
|
||||||
options.ImportFilePath = _importFilePath;
|
options.ImportFilePath = _importFilePath;
|
||||||
return _fileSystem.DownloadFileAsync(Bundle, options);
|
return _fileSystem.DownloadFileAsync(Bundle, options);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,15 +34,16 @@ namespace YooAsset
|
|||||||
ClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options);
|
ClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options);
|
||||||
|
|
||||||
// 下载相关
|
// 下载相关
|
||||||
ResourceDownloaderOperation CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout);
|
ResourceDownloaderOperation CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain);
|
||||||
ResourceDownloaderOperation CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout);
|
ResourceDownloaderOperation CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain);
|
||||||
ResourceDownloaderOperation CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout);
|
ResourceDownloaderOperation CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain);
|
||||||
|
|
||||||
// 解压相关
|
// 解压相关
|
||||||
ResourceUnpackerOperation CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout);
|
ResourceUnpackerOperation CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain);
|
||||||
ResourceUnpackerOperation CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout);
|
ResourceUnpackerOperation CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain);
|
||||||
|
|
||||||
// 导入相关
|
// 导入相关
|
||||||
ResourceImporterOperation CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout);
|
ResourceImporterOperation CreateResourceImporterByFilePaths(string[] filePaths, int importingMaxNumber, int failedTryAgain);
|
||||||
|
ResourceImporterOperation CreateResourceImporterByFileInfos(ImportFileInfo[] fileInfos, int importingMaxNumber, int failedTryAgain);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,6 @@ namespace YooAsset
|
|||||||
private readonly string _packageName;
|
private readonly string _packageName;
|
||||||
private readonly int _downloadingMaxNumber;
|
private readonly int _downloadingMaxNumber;
|
||||||
private readonly int _failedTryAgain;
|
private readonly int _failedTryAgain;
|
||||||
private readonly int _timeout;
|
|
||||||
private readonly List<BundleInfo> _bundleInfoList;
|
private readonly List<BundleInfo> _bundleInfoList;
|
||||||
private readonly List<FSDownloadFileOperation> _downloaders = new List<FSDownloadFileOperation>(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> _removeList = new List<FSDownloadFileOperation>(MAX_LOADER_COUNT);
|
||||||
@@ -102,13 +101,12 @@ namespace YooAsset
|
|||||||
public DownloadFileBegin DownloadFileBeginCallback { set; get; }
|
public DownloadFileBegin DownloadFileBeginCallback { set; get; }
|
||||||
|
|
||||||
|
|
||||||
internal DownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
internal DownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
_packageName = packageName;
|
_packageName = packageName;
|
||||||
_bundleInfoList = downloadList;
|
_bundleInfoList = downloadList;
|
||||||
_downloadingMaxNumber = UnityEngine.Mathf.Clamp(downloadingMaxNumber, 1, MAX_LOADER_COUNT); ;
|
_downloadingMaxNumber = UnityEngine.Mathf.Clamp(downloadingMaxNumber, 1, MAX_LOADER_COUNT); ;
|
||||||
_failedTryAgain = failedTryAgain;
|
_failedTryAgain = failedTryAgain;
|
||||||
_timeout = timeout;
|
|
||||||
|
|
||||||
// 设置包裹名称 (fix #210)
|
// 设置包裹名称 (fix #210)
|
||||||
SetPackageName(packageName);
|
SetPackageName(packageName);
|
||||||
@@ -203,7 +201,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
int index = _bundleInfoList.Count - 1;
|
int index = _bundleInfoList.Count - 1;
|
||||||
var bundleInfo = _bundleInfoList[index];
|
var bundleInfo = _bundleInfoList[index];
|
||||||
var downloader = bundleInfo.CreateDownloader(_failedTryAgain, _timeout);
|
var downloader = bundleInfo.CreateDownloader(_failedTryAgain);
|
||||||
downloader.StartOperation();
|
downloader.StartOperation();
|
||||||
this.AddChildOperation(downloader);
|
this.AddChildOperation(downloader);
|
||||||
|
|
||||||
@@ -374,52 +372,52 @@ namespace YooAsset
|
|||||||
|
|
||||||
public sealed class ResourceDownloaderOperation : DownloaderOperation
|
public sealed class ResourceDownloaderOperation : DownloaderOperation
|
||||||
{
|
{
|
||||||
internal ResourceDownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
internal ResourceDownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
|
||||||
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建空的下载器
|
/// 创建空的下载器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static ResourceDownloaderOperation CreateEmptyDownloader(string packageName, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
internal static ResourceDownloaderOperation CreateEmptyDownloader(string packageName, int downloadingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||||
var operation = new ResourceDownloaderOperation(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(packageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public sealed class ResourceUnpackerOperation : DownloaderOperation
|
public sealed class ResourceUnpackerOperation : DownloaderOperation
|
||||||
{
|
{
|
||||||
internal ResourceUnpackerOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
internal ResourceUnpackerOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
|
||||||
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建空的解压器
|
/// 创建空的解压器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static ResourceUnpackerOperation CreateEmptyUnpacker(string packageName, int upackingMaxNumber, int failedTryAgain, int timeout)
|
internal static ResourceUnpackerOperation CreateEmptyUnpacker(string packageName, int upackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||||
var operation = new ResourceUnpackerOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue);
|
var operation = new ResourceUnpackerOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public sealed class ResourceImporterOperation : DownloaderOperation
|
public sealed class ResourceImporterOperation : DownloaderOperation
|
||||||
{
|
{
|
||||||
internal ResourceImporterOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
internal ResourceImporterOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain)
|
||||||
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建空的导入器
|
/// 创建空的导入器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static ResourceImporterOperation CreateEmptyImporter(string packageName, int upackingMaxNumber, int failedTryAgain, int timeout)
|
internal static ResourceImporterOperation CreateEmptyImporter(string packageName, int upackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||||
var operation = new ResourceImporterOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue);
|
var operation = new ResourceImporterOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,11 +107,11 @@ namespace YooAsset
|
|||||||
if (Status != EOperationStatus.Succeed)
|
if (Status != EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BundleInfo> downloadList = _impl.GetDownloadListByAll(_manifest);
|
List<BundleInfo> downloadList = _impl.GetDownloadListByAll(_manifest);
|
||||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,11 +127,11 @@ namespace YooAsset
|
|||||||
if (Status != EOperationStatus.Succeed)
|
if (Status != EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, new string[] { tag });
|
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, new string[] { tag });
|
||||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,11 +147,11 @@ namespace YooAsset
|
|||||||
if (Status != EOperationStatus.Succeed)
|
if (Status != EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, tags);
|
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, tags);
|
||||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,7 +167,7 @@ namespace YooAsset
|
|||||||
if (Status != EOperationStatus.Succeed)
|
if (Status != EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<AssetInfo> assetInfos = new List<AssetInfo>();
|
List<AssetInfo> assetInfos = new List<AssetInfo>();
|
||||||
@@ -175,7 +175,7 @@ namespace YooAsset
|
|||||||
assetInfos.Add(assetInfo);
|
assetInfos.Add(assetInfo);
|
||||||
|
|
||||||
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload);
|
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload);
|
||||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +191,7 @@ namespace YooAsset
|
|||||||
if (Status != EOperationStatus.Succeed)
|
if (Status != EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain, timeout);
|
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
|
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
|
||||||
@@ -202,7 +202,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload);
|
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload);
|
||||||
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace YooAsset
|
|||||||
buildParam.InvokeAssmeblyName = "YooAsset.Editor";
|
buildParam.InvokeAssmeblyName = "YooAsset.Editor";
|
||||||
buildParam.InvokeClassFullName = "YooAsset.Editor.AssetBundleSimulateBuilder";
|
buildParam.InvokeClassFullName = "YooAsset.Editor.AssetBundleSimulateBuilder";
|
||||||
buildParam.InvokeMethodName = "SimulateBuild";
|
buildParam.InvokeMethodName = "SimulateBuild";
|
||||||
return PakcageInvokeBuilder.InvokeBuilder(buildParam);
|
return PackageInvokeBuilder.InvokeBuilder(buildParam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -104,44 +104,50 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 下载相关
|
// 下载相关
|
||||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList = GetDownloadListByAll(ActiveManifest);
|
List<BundleInfo> downloadList = GetDownloadListByAll(ActiveManifest);
|
||||||
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList = GetDownloadListByTags(ActiveManifest, tags);
|
List<BundleInfo> downloadList = GetDownloadListByTags(ActiveManifest, tags);
|
||||||
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList = GetDownloadListByPaths(ActiveManifest, assetInfos, recursiveDownload);
|
List<BundleInfo> downloadList = GetDownloadListByPaths(ActiveManifest, assetInfos, recursiveDownload);
|
||||||
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解压相关
|
// 解压相关
|
||||||
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
|
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> unpcakList = GetUnpackListByAll(ActiveManifest);
|
List<BundleInfo> unpcakList = GetUnpackListByAll(ActiveManifest);
|
||||||
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain, int timeout)
|
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> unpcakList = GetUnpackListByTags(ActiveManifest, tags);
|
List<BundleInfo> unpcakList = GetUnpackListByTags(ActiveManifest, tags);
|
||||||
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 导入相关
|
// 导入相关
|
||||||
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
|
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
List<BundleInfo> importerList = GetImporterListByFilePaths(ActiveManifest, filePaths);
|
List<BundleInfo> importerList = GetImporterListByFilePaths(ActiveManifest, filePaths);
|
||||||
var operation = new ResourceImporterOperation(PackageName, importerList, importerMaxNumber, failedTryAgain, timeout);
|
var operation = new ResourceImporterOperation(PackageName, importerList, importingMaxNumber, failedTryAgain);
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
ResourceImporterOperation IPlayMode.CreateResourceImporterByFileInfos(ImportFileInfo[] fileInfos, int importingMaxNumber, int failedTryAgain)
|
||||||
|
{
|
||||||
|
List<BundleInfo> importerList = GetImporterListByFileInfos(ActiveManifest, fileInfos);
|
||||||
|
var operation = new ResourceImporterOperation(PackageName, importerList, importingMaxNumber, failedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@@ -419,11 +425,56 @@ namespace YooAsset
|
|||||||
if (manifest == null)
|
if (manifest == null)
|
||||||
return new List<BundleInfo>();
|
return new List<BundleInfo>();
|
||||||
|
|
||||||
List<BundleInfo> result = new List<BundleInfo>();
|
ImportFileInfo[] fileInfos = new ImportFileInfo[filePaths.Length];
|
||||||
foreach (var filePath in filePaths)
|
for (int i = 0; i < filePaths.Length; i++)
|
||||||
{
|
{
|
||||||
string fileName = System.IO.Path.GetFileName(filePath);
|
ImportFileInfo fileInfo = new ImportFileInfo();
|
||||||
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle))
|
fileInfo.FilePath = filePaths[i];
|
||||||
|
fileInfos[i] = fileInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GetImporterListByFileInfos(manifest, fileInfos);
|
||||||
|
}
|
||||||
|
public List<BundleInfo> GetImporterListByFileInfos(PackageManifest manifest, ImportFileInfo[] fileInfos)
|
||||||
|
{
|
||||||
|
if (manifest == null)
|
||||||
|
return new List<BundleInfo>();
|
||||||
|
|
||||||
|
List<BundleInfo> result = new List<BundleInfo>();
|
||||||
|
foreach (var fileInfo in fileInfos)
|
||||||
|
{
|
||||||
|
string filePath = fileInfo.FilePath;
|
||||||
|
if (string.IsNullOrEmpty(filePath))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
PackageBundle packageBundle = null;
|
||||||
|
if (string.IsNullOrEmpty(fileInfo.BundleName) == false)
|
||||||
|
{
|
||||||
|
if (manifest.TryGetPackageBundleByBundleName(fileInfo.BundleName, out packageBundle) == false)
|
||||||
|
{
|
||||||
|
YooLogger.Warning($"Not found package bundle, bundle name : {fileInfo.BundleName}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (string.IsNullOrEmpty(fileInfo.BundleGUID) == false)
|
||||||
|
{
|
||||||
|
if (manifest.TryGetPackageBundleByBundleGUID(fileInfo.BundleGUID, out packageBundle) == false)
|
||||||
|
{
|
||||||
|
YooLogger.Warning($"Not found package bundle, bundle guid : {fileInfo.BundleGUID}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string fileName = System.IO.Path.GetFileName(filePath);
|
||||||
|
if (manifest.TryGetPackageBundleByFileName(fileName, out packageBundle) == false)
|
||||||
|
{
|
||||||
|
YooLogger.Warning($"Not found package bundle, file name : {fileName}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (packageBundle != null)
|
||||||
{
|
{
|
||||||
var fileSystem = GetBelongFileSystem(packageBundle);
|
var fileSystem = GetBelongFileSystem(packageBundle);
|
||||||
if (fileSystem == null)
|
if (fileSystem == null)
|
||||||
@@ -435,10 +486,6 @@ namespace YooAsset
|
|||||||
result.Add(bundleInfo);
|
result.Add(bundleInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
YooLogger.Warning($"Not found package bundle, importer file path : {filePath}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -969,7 +969,7 @@ namespace YooAsset
|
|||||||
public ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _playModeImpl.CreateResourceDownloaderByAll(downloadingMaxNumber, failedTryAgain, timeout);
|
return _playModeImpl.CreateResourceDownloaderByAll(downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -982,7 +982,7 @@ namespace YooAsset
|
|||||||
public ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _playModeImpl.CreateResourceDownloaderByTags(new string[] { tag }, downloadingMaxNumber, failedTryAgain, timeout);
|
return _playModeImpl.CreateResourceDownloaderByTags(new string[] { tag }, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -995,7 +995,7 @@ namespace YooAsset
|
|||||||
public ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _playModeImpl.CreateResourceDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain, timeout);
|
return _playModeImpl.CreateResourceDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1011,11 +1011,11 @@ namespace YooAsset
|
|||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
var assetInfo = ConvertLocationToAssetInfo(location, null);
|
var assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||||
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
|
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
|
||||||
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain, timeout);
|
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
public ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
return CreateBundleDownloader(location, false, downloadingMaxNumber, failedTryAgain, timeout);
|
return CreateBundleDownloader(location, false, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1035,11 +1035,11 @@ namespace YooAsset
|
|||||||
var assetInfo = ConvertLocationToAssetInfo(location, null);
|
var assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||||
assetInfos.Add(assetInfo);
|
assetInfos.Add(assetInfo);
|
||||||
}
|
}
|
||||||
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos.ToArray(), recursiveDownload, downloadingMaxNumber, failedTryAgain, timeout);
|
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos.ToArray(), recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
return CreateBundleDownloader(locations, false, downloadingMaxNumber, failedTryAgain, timeout);
|
return CreateBundleDownloader(locations, false, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1054,11 +1054,11 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
|
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
|
||||||
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain, timeout);
|
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
return CreateBundleDownloader(assetInfo, false, downloadingMaxNumber, failedTryAgain, timeout);
|
return CreateBundleDownloader(assetInfo, false, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1072,11 +1072,11 @@ namespace YooAsset
|
|||||||
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain, timeout);
|
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout = 60)
|
||||||
{
|
{
|
||||||
return CreateBundleDownloader(assetInfos, false, downloadingMaxNumber, failedTryAgain, timeout);
|
return CreateBundleDownloader(assetInfos, false, downloadingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -1089,7 +1089,7 @@ namespace YooAsset
|
|||||||
public ResourceUnpackerOperation CreateResourceUnpacker(int unpackingMaxNumber, int failedTryAgain)
|
public ResourceUnpackerOperation CreateResourceUnpacker(int unpackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _playModeImpl.CreateResourceUnpackerByAll(unpackingMaxNumber, failedTryAgain, int.MaxValue);
|
return _playModeImpl.CreateResourceUnpackerByAll(unpackingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1101,7 +1101,7 @@ namespace YooAsset
|
|||||||
public ResourceUnpackerOperation CreateResourceUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain)
|
public ResourceUnpackerOperation CreateResourceUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _playModeImpl.CreateResourceUnpackerByTags(new string[] { tag }, unpackingMaxNumber, failedTryAgain, int.MaxValue);
|
return _playModeImpl.CreateResourceUnpackerByTags(new string[] { tag }, unpackingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -1113,7 +1113,7 @@ namespace YooAsset
|
|||||||
public ResourceUnpackerOperation CreateResourceUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain)
|
public ResourceUnpackerOperation CreateResourceUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _playModeImpl.CreateResourceUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain, int.MaxValue);
|
return _playModeImpl.CreateResourceUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -1128,7 +1128,20 @@ namespace YooAsset
|
|||||||
public ResourceImporterOperation CreateResourceImporter(string[] filePaths, int importerMaxNumber, int failedTryAgain)
|
public ResourceImporterOperation CreateResourceImporter(string[] filePaths, int importerMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _playModeImpl.CreateResourceImporterByFilePaths(filePaths, importerMaxNumber, failedTryAgain, int.MaxValue);
|
return _playModeImpl.CreateResourceImporterByFilePaths(filePaths, importerMaxNumber, failedTryAgain);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建资源导入器
|
||||||
|
/// 注意:资源信息里需要指定BundleName或BundleGUID!
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileInfos">资源信息列表</param>
|
||||||
|
/// <param name="importerMaxNumber">同时导入的最大文件数</param>
|
||||||
|
/// <param name="failedTryAgain">导入失败的重试次数</param>
|
||||||
|
public ResourceImporterOperation CreateResourceImporter(ImportFileInfo[] fileInfos, int importerMaxNumber, int failedTryAgain)
|
||||||
|
{
|
||||||
|
DebugCheckInitialize();
|
||||||
|
return _playModeImpl.CreateResourceImporterByFileInfos(fileInfos, importerMaxNumber, failedTryAgain);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
|
|||||||
string sourcePath = GetBuildinHashFilePath();
|
string sourcePath = GetBuildinHashFilePath();
|
||||||
string destPath = GetCacheHashFilePath();
|
string destPath = GetCacheHashFilePath();
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
||||||
_hashFileRequestOp = new UnityWebFileRequestOperation(url, destPath);
|
_hashFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60);
|
||||||
OperationSystem.StartOperation(_packageName, _hashFileRequestOp);
|
OperationSystem.StartOperation(_packageName, _hashFileRequestOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
|
|||||||
string sourcePath = GetBuildinManifestFilePath();
|
string sourcePath = GetBuildinManifestFilePath();
|
||||||
string destPath = GetCacheManifestFilePath();
|
string destPath = GetCacheManifestFilePath();
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
||||||
_manifestFileRequestOp = new UnityWebFileRequestOperation(url, destPath);
|
_manifestFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60);
|
||||||
OperationSystem.StartOperation(_packageName, _manifestFileRequestOp);
|
OperationSystem.StartOperation(_packageName, _manifestFileRequestOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public class GetBuildinPackageVersionOperation : GameAsyncOperation
|
|||||||
{
|
{
|
||||||
string filePath = GetBuildinPackageVersionFilePath();
|
string filePath = GetBuildinPackageVersionFilePath();
|
||||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||||
_versionFileRequestOp = new UnityWebTextRequestOperation(url);
|
_versionFileRequestOp = new UnityWebTextRequestOperation(url, 60);
|
||||||
OperationSystem.StartOperation(_packageName, _versionFileRequestOp);
|
OperationSystem.StartOperation(_packageName, _versionFileRequestOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,30 @@
|
|||||||
#if UNITY_WEBGL && DOUYINMINIGAME
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
|
|
||||||
internal class TTFSDownloadFileOperation : DefaultDownloadFileOperation
|
internal class TTFSDownloadFileOperation : FSDownloadFileOperation
|
||||||
{
|
{
|
||||||
private TiktokFileSystem _fileSystem;
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
CheckRequest,
|
||||||
|
TryAgain,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly TiktokFileSystem _fileSystem;
|
||||||
|
private readonly DownloadFileOptions _options;
|
||||||
|
private UnityWebCacheRequestOperation _unityWebCacheRequestOp;
|
||||||
|
private int _requestCount = 0;
|
||||||
|
private float _tryAgainTimer;
|
||||||
|
private int _failedTryAgain;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal TTFSDownloadFileOperation(TiktokFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
|
internal TTFSDownloadFileOperation(TiktokFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
|
_options = options;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
@@ -21,81 +35,75 @@ internal class TTFSDownloadFileOperation : DefaultDownloadFileOperation
|
|||||||
// 创建下载器
|
// 创建下载器
|
||||||
if (_steps == ESteps.CreateRequest)
|
if (_steps == ESteps.CreateRequest)
|
||||||
{
|
{
|
||||||
// 获取请求地址
|
string url = GetRequestURL();
|
||||||
_requestURL = GetRequestURL();
|
_unityWebCacheRequestOp = new UnityWebCacheRequestOperation(url);
|
||||||
|
_unityWebCacheRequestOp.StartOperation();
|
||||||
// 重置变量
|
|
||||||
ResetRequestFiled();
|
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
CreateWebRequest();
|
|
||||||
|
|
||||||
_steps = ESteps.CheckRequest;
|
_steps = ESteps.CheckRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测下载结果
|
// 检测下载结果
|
||||||
if (_steps == ESteps.CheckRequest)
|
if (_steps == ESteps.CheckRequest)
|
||||||
{
|
{
|
||||||
DownloadProgress = _webRequest.downloadProgress;
|
Progress = _unityWebCacheRequestOp.Progress;
|
||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
DownloadProgress = _unityWebCacheRequestOp.DownloadProgress;
|
||||||
Progress = DownloadProgress;
|
DownloadedBytes = (long)_unityWebCacheRequestOp.DownloadedBytes;
|
||||||
if (_webRequest.isDone == false)
|
if (_unityWebCacheRequestOp.IsDone == false)
|
||||||
{
|
|
||||||
CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// 检查网络错误
|
if (_unityWebCacheRequestOp.Status == EOperationStatus.Succeed)
|
||||||
if (CheckRequestResult())
|
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
|
|
||||||
|
//TODO 需要验证抖音插件请求器的下载进度
|
||||||
|
DownloadProgress = 1f;
|
||||||
|
DownloadedBytes = Bundle.FileSize;
|
||||||
|
Progress = 1f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.TryAgain;
|
if (_failedTryAgain > 0)
|
||||||
|
{
|
||||||
|
_steps = ESteps.TryAgain;
|
||||||
|
YooLogger.Warning($"Failed download : {_unityWebCacheRequestOp.URL} Try again !");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _unityWebCacheRequestOp.Error;
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注意:最终释放请求器
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新尝试下载
|
// 重新尝试下载
|
||||||
if (_steps == ESteps.TryAgain)
|
if (_steps == ESteps.TryAgain)
|
||||||
{
|
{
|
||||||
if (FailedTryAgain <= 0)
|
|
||||||
{
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
YooLogger.Error(Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_tryAgainTimer += Time.unscaledDeltaTime;
|
_tryAgainTimer += Time.unscaledDeltaTime;
|
||||||
if (_tryAgainTimer > 1f)
|
if (_tryAgainTimer > 1f)
|
||||||
{
|
{
|
||||||
FailedTryAgain--;
|
_tryAgainTimer = 0f;
|
||||||
|
_failedTryAgain--;
|
||||||
|
Progress = 0f;
|
||||||
|
DownloadProgress = 0f;
|
||||||
|
DownloadedBytes = 0;
|
||||||
_steps = ESteps.CreateRequest;
|
_steps = ESteps.CreateRequest;
|
||||||
YooLogger.Warning(Error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateWebRequest()
|
/// <summary>
|
||||||
|
/// 获取网络请求地址
|
||||||
|
/// </summary>
|
||||||
|
private string GetRequestURL()
|
||||||
{
|
{
|
||||||
//TODO : 抖音小游戏没有找到预下载方法
|
// 轮流返回请求地址
|
||||||
_webRequest = UnityWebRequest.Get(_requestURL);
|
_requestCount++;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
if (_requestCount % 2 == 0)
|
||||||
_webRequest.SendWebRequest();
|
return _options.FallbackURL;
|
||||||
}
|
else
|
||||||
private void DisposeWebRequest()
|
return _options.MainURL;
|
||||||
{
|
|
||||||
if (_webRequest != null)
|
|
||||||
{
|
|
||||||
//注意:引擎底层会自动调用Abort方法
|
|
||||||
_webRequest.Dispose();
|
|
||||||
_webRequest = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
#if UNITY_WEBGL && DOUYINMINIGAME
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
|
|
||||||
internal class TTFSLoadBundleOperation : FSLoadBundleOperation
|
internal class TTFSLoadBundleOperation : FSLoadBundleOperation
|
||||||
@@ -14,7 +13,7 @@ internal class TTFSLoadBundleOperation : FSLoadBundleOperation
|
|||||||
|
|
||||||
private readonly TiktokFileSystem _fileSystem;
|
private readonly TiktokFileSystem _fileSystem;
|
||||||
private readonly PackageBundle _bundle;
|
private readonly PackageBundle _bundle;
|
||||||
private DownloadAssetBundleOperation _downloadAssetBundleOp;
|
private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal TTFSLoadBundleOperation(TiktokFileSystem fileSystem, PackageBundle bundle)
|
internal TTFSLoadBundleOperation(TiktokFileSystem fileSystem, PackageBundle bundle)
|
||||||
@@ -33,54 +32,46 @@ internal class TTFSLoadBundleOperation : FSLoadBundleOperation
|
|||||||
|
|
||||||
if (_steps == ESteps.DownloadAssetBundle)
|
if (_steps == ESteps.DownloadAssetBundle)
|
||||||
{
|
{
|
||||||
if (_downloadAssetBundleOp == null)
|
if (_loadWebAssetBundleOp == null)
|
||||||
{
|
{
|
||||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
|
string mainRUL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
|
||||||
options.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName); ;
|
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
||||||
options.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||||
|
options.SetURL(mainRUL, fallbackURL);
|
||||||
|
|
||||||
if (_bundle.Encrypted)
|
if (_bundle.Encrypted)
|
||||||
{
|
{
|
||||||
_downloadAssetBundleOp = new DownloadEncryptAssetBundleOperation(false, _fileSystem.DecryptionServices, _bundle, options);
|
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices);
|
||||||
_downloadAssetBundleOp.StartOperation();
|
_loadWebAssetBundleOp.StartOperation();
|
||||||
AddChildOperation(_downloadAssetBundleOp);
|
AddChildOperation(_loadWebAssetBundleOp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_downloadAssetBundleOp = new DownloadTiktokAssetBundleOperation(_bundle, options);
|
_loadWebAssetBundleOp = new LoadTiktokAssetBundleOperation(_bundle, options);
|
||||||
_downloadAssetBundleOp.StartOperation();
|
_loadWebAssetBundleOp.StartOperation();
|
||||||
AddChildOperation(_downloadAssetBundleOp);
|
AddChildOperation(_loadWebAssetBundleOp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_downloadAssetBundleOp.UpdateOperation();
|
_loadWebAssetBundleOp.UpdateOperation();
|
||||||
DownloadProgress = _downloadAssetBundleOp.DownloadProgress;
|
DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
|
||||||
DownloadedBytes = (long)_downloadAssetBundleOp.DownloadedBytes;
|
DownloadedBytes = (long)_loadWebAssetBundleOp.DownloadedBytes;
|
||||||
Progress = DownloadProgress;
|
Progress = DownloadProgress;
|
||||||
if (_downloadAssetBundleOp.IsDone == false)
|
if (_loadWebAssetBundleOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_downloadAssetBundleOp.Status == EOperationStatus.Succeed)
|
if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
var assetBundle = _downloadAssetBundleOp.Result;
|
var assetBundle = _loadWebAssetBundleOp.Result;
|
||||||
if (assetBundle == null)
|
_steps = ESteps.Done;
|
||||||
{
|
Result = new TTAssetBundleResult(_fileSystem, _bundle, assetBundle);
|
||||||
_steps = ESteps.Done;
|
Status = EOperationStatus.Succeed;
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = $"{nameof(DownloadAssetBundleOperation)} loaded asset bundle is null !";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Result = new TTAssetBundleResult(_fileSystem, _bundle, assetBundle);
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _downloadAssetBundleOp.Error;
|
Error = _loadWebAssetBundleOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,126 +0,0 @@
|
|||||||
#if UNITY_WEBGL && DOUYINMINIGAME
|
|
||||||
using UnityEngine;
|
|
||||||
using TTSDK;
|
|
||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
internal class DownloadTiktokAssetBundleOperation : DownloadAssetBundleOperation
|
|
||||||
{
|
|
||||||
private ESteps _steps = ESteps.None;
|
|
||||||
|
|
||||||
internal DownloadTiktokAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
internal override void InternalStart()
|
|
||||||
{
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
}
|
|
||||||
internal override void InternalUpdate()
|
|
||||||
{
|
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
if (_steps == ESteps.CreateRequest)
|
|
||||||
{
|
|
||||||
// 获取请求地址
|
|
||||||
_requestURL = GetRequestURL();
|
|
||||||
|
|
||||||
// 重置变量
|
|
||||||
ResetRequestFiled();
|
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
CreateWebRequest();
|
|
||||||
|
|
||||||
_steps = ESteps.CheckRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检测下载结果
|
|
||||||
if (_steps == ESteps.CheckRequest)
|
|
||||||
{
|
|
||||||
DownloadProgress = _webRequest.downloadProgress;
|
|
||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
|
||||||
Progress = DownloadProgress;
|
|
||||||
if (_webRequest.isDone == false)
|
|
||||||
{
|
|
||||||
//TODO 需要验证抖音插件请求器的下载进度
|
|
||||||
//CheckRequestTimeout();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查网络错误
|
|
||||||
if (CheckRequestResult())
|
|
||||||
{
|
|
||||||
var downloadHanlder = (DownloadHandlerTTAssetBundle)_webRequest.downloadHandler;
|
|
||||||
AssetBundle assetBundle = downloadHanlder.assetBundle;
|
|
||||||
if (assetBundle == null)
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = "Download handler asset bundle object is null !";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Result = assetBundle;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
|
|
||||||
//TODO 需要验证抖音插件请求器的下载进度
|
|
||||||
DownloadProgress = 1f;
|
|
||||||
DownloadedBytes = Bundle.FileSize;
|
|
||||||
Progress = 1f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.TryAgain;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 注意:最终释放请求器
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 重新尝试下载
|
|
||||||
if (_steps == ESteps.TryAgain)
|
|
||||||
{
|
|
||||||
if (FailedTryAgain <= 0)
|
|
||||||
{
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
YooLogger.Error(Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_tryAgainTimer += Time.unscaledDeltaTime;
|
|
||||||
if (_tryAgainTimer > 1f)
|
|
||||||
{
|
|
||||||
FailedTryAgain--;
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
YooLogger.Warning(Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
internal override void InternalAbort()
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateWebRequest()
|
|
||||||
{
|
|
||||||
_webRequest = TTAssetBundle.GetAssetBundle(_requestURL);
|
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
|
||||||
_webRequest.SendWebRequest();
|
|
||||||
}
|
|
||||||
private void DisposeWebRequest()
|
|
||||||
{
|
|
||||||
if (_webRequest != null)
|
|
||||||
{
|
|
||||||
//注意:引擎底层会自动调用Abort方法
|
|
||||||
_webRequest.Dispose();
|
|
||||||
_webRequest = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class LoadTiktokAssetBundleOperation : LoadWebAssetBundleOperation
|
||||||
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
CheckRequest,
|
||||||
|
TryAgain,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly PackageBundle _bundle;
|
||||||
|
private readonly DownloadFileOptions _options;
|
||||||
|
private UnityTiktokAssetBundleRequestOperation _unityTiktokAssetBundleRequestOp;
|
||||||
|
|
||||||
|
private int _requestCount = 0;
|
||||||
|
private float _tryAgainTimer;
|
||||||
|
private int _failedTryAgain;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
|
internal LoadTiktokAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options)
|
||||||
|
{
|
||||||
|
_bundle = bundle;
|
||||||
|
_options = options;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 创建下载器
|
||||||
|
if (_steps == ESteps.CreateRequest)
|
||||||
|
{
|
||||||
|
string url = GetRequestURL();
|
||||||
|
_unityTiktokAssetBundleRequestOp = new UnityTiktokAssetBundleRequestOperation(_bundle, url);
|
||||||
|
_unityTiktokAssetBundleRequestOp.StartOperation();
|
||||||
|
AddChildOperation(_unityTiktokAssetBundleRequestOp);
|
||||||
|
_steps = ESteps.CheckRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测下载结果
|
||||||
|
if (_steps == ESteps.CheckRequest)
|
||||||
|
{
|
||||||
|
_unityTiktokAssetBundleRequestOp.UpdateOperation();
|
||||||
|
Progress = _unityTiktokAssetBundleRequestOp.Progress;
|
||||||
|
DownloadProgress = _unityTiktokAssetBundleRequestOp.DownloadProgress;
|
||||||
|
DownloadedBytes = (long)_unityTiktokAssetBundleRequestOp.DownloadedBytes;
|
||||||
|
if (_unityTiktokAssetBundleRequestOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_unityTiktokAssetBundleRequestOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
Result = _unityTiktokAssetBundleRequestOp.Result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_failedTryAgain > 0)
|
||||||
|
{
|
||||||
|
_steps = ESteps.TryAgain;
|
||||||
|
YooLogger.Warning($"Failed download : {_unityTiktokAssetBundleRequestOp.URL} Try again !");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _unityTiktokAssetBundleRequestOp.Error;
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重新尝试下载
|
||||||
|
if (_steps == ESteps.TryAgain)
|
||||||
|
{
|
||||||
|
_tryAgainTimer += Time.unscaledDeltaTime;
|
||||||
|
if (_tryAgainTimer > 1f)
|
||||||
|
{
|
||||||
|
_tryAgainTimer = 0f;
|
||||||
|
_failedTryAgain--;
|
||||||
|
Progress = 0f;
|
||||||
|
DownloadProgress = 0f;
|
||||||
|
DownloadedBytes = 0;
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取网络请求地址
|
||||||
|
/// </summary>
|
||||||
|
private string GetRequestURL()
|
||||||
|
{
|
||||||
|
// 轮流返回请求地址
|
||||||
|
_requestCount++;
|
||||||
|
if (_requestCount % 2 == 0)
|
||||||
|
return _options.FallbackURL;
|
||||||
|
else
|
||||||
|
return _options.MainURL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
#if UNITY_WEBGL && DOUYINMINIGAME
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
using UnityEngine;
|
||||||
|
using TTSDK;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class UnityTiktokAssetBundleRequestOperation : UnityWebRequestOperation
|
||||||
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
Download,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly PackageBundle _packageBundle;
|
||||||
|
private UnityWebRequestAsyncOperation _requestOperation;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 请求结果
|
||||||
|
/// </summary>
|
||||||
|
public AssetBundle Result { private set; get; }
|
||||||
|
|
||||||
|
internal UnityTiktokAssetBundleRequestOperation(PackageBundle bundle, string url) : base(url)
|
||||||
|
{
|
||||||
|
_packageBundle = bundle;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.CreateRequest)
|
||||||
|
{
|
||||||
|
CreateWebRequest();
|
||||||
|
_steps = ESteps.Download;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.Download)
|
||||||
|
{
|
||||||
|
DownloadProgress = _webRequest.downloadProgress;
|
||||||
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
|
Progress = _requestOperation.progress;
|
||||||
|
if (_requestOperation.isDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (CheckRequestResult())
|
||||||
|
{
|
||||||
|
var downloadHanlder = (DownloadHandlerTTAssetBundle)_webRequest.downloadHandler;
|
||||||
|
AssetBundle assetBundle = downloadHanlder.assetBundle;
|
||||||
|
if (assetBundle == null)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"URL : {_requestURL} Download handler asset bundle object is null !";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Result = assetBundle;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
|
||||||
|
//TODO 需要验证抖音插件请求器的下载进度
|
||||||
|
DownloadProgress = 1f;
|
||||||
|
DownloadedBytes = _packageBundle.FileSize;
|
||||||
|
Progress = 1f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注意:最终释放请求器
|
||||||
|
DisposeRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateWebRequest()
|
||||||
|
{
|
||||||
|
_webRequest = TTAssetBundle.GetAssetBundle(_requestURL);
|
||||||
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
|
_requestOperation = _webRequest.SendWebRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dbac28b7a131d1043af35b3c2dbe083f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -136,8 +136,9 @@ internal class TiktokFileSystem : IFileSystem
|
|||||||
}
|
}
|
||||||
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
||||||
{
|
{
|
||||||
options.MainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
|
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
|
||||||
options.FallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
||||||
|
options.SetURL(mainURL, fallbackURL);
|
||||||
var operation = new TTFSDownloadFileOperation(this, bundle, options);
|
var operation = new TTFSDownloadFileOperation(this, bundle, options);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,30 @@
|
|||||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
using WeChatWASM;
|
|
||||||
|
|
||||||
internal class WXFSDownloadFileOperation : DefaultDownloadFileOperation
|
internal class WXFSDownloadFileOperation : FSDownloadFileOperation
|
||||||
{
|
{
|
||||||
private WechatFileSystem _fileSystem;
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
CheckRequest,
|
||||||
|
TryAgain,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly WechatFileSystem _fileSystem;
|
||||||
|
private readonly DownloadFileOptions _options;
|
||||||
|
private UnityWebCacheRequestOperation _unityWebCacheRequestOp;
|
||||||
|
private int _requestCount = 0;
|
||||||
|
private float _tryAgainTimer;
|
||||||
|
private int _failedTryAgain;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal WXFSDownloadFileOperation(WechatFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
|
internal WXFSDownloadFileOperation(WechatFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
|
_options = options;
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
@@ -22,34 +35,25 @@ internal class WXFSDownloadFileOperation : DefaultDownloadFileOperation
|
|||||||
// 创建下载器
|
// 创建下载器
|
||||||
if (_steps == ESteps.CreateRequest)
|
if (_steps == ESteps.CreateRequest)
|
||||||
{
|
{
|
||||||
// 获取请求地址
|
string url = GetRequestURL();
|
||||||
_requestURL = GetRequestURL();
|
_unityWebCacheRequestOp = new UnityWebCacheRequestOperation(url);
|
||||||
|
_unityWebCacheRequestOp.SetRequestHeader("wechatminigame-preload", "1");
|
||||||
// 重置变量
|
_unityWebCacheRequestOp.StartOperation();
|
||||||
ResetRequestFiled();
|
AddChildOperation(_unityWebCacheRequestOp);
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
CreateWebRequest();
|
|
||||||
|
|
||||||
_steps = ESteps.CheckRequest;
|
_steps = ESteps.CheckRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检测下载结果
|
// 检测下载结果
|
||||||
if (_steps == ESteps.CheckRequest)
|
if (_steps == ESteps.CheckRequest)
|
||||||
{
|
{
|
||||||
DownloadProgress = _webRequest.downloadProgress;
|
_unityWebCacheRequestOp.UpdateOperation();
|
||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
Progress = _unityWebCacheRequestOp.Progress;
|
||||||
Progress = DownloadProgress;
|
DownloadProgress = _unityWebCacheRequestOp.DownloadProgress;
|
||||||
if (_webRequest.isDone == false)
|
DownloadedBytes = (long)_unityWebCacheRequestOp.DownloadedBytes;
|
||||||
{
|
if (_unityWebCacheRequestOp.IsDone == false)
|
||||||
//TODO 由于微信小游戏插件的问题,暂时不能判定超时!
|
|
||||||
// Issue : https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/108#
|
|
||||||
//CheckRequestTimeout();
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// 检查网络错误
|
if (_unityWebCacheRequestOp.Status == EOperationStatus.Succeed)
|
||||||
if (CheckRequestResult())
|
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
@@ -62,49 +66,48 @@ internal class WXFSDownloadFileOperation : DefaultDownloadFileOperation
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.TryAgain;
|
if (_failedTryAgain > 0)
|
||||||
|
{
|
||||||
|
_steps = ESteps.TryAgain;
|
||||||
|
YooLogger.Warning($"Failed download : {_unityWebCacheRequestOp.URL} Try again !");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _unityWebCacheRequestOp.Error;
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注意:最终释放请求器
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新尝试下载
|
// 重新尝试下载
|
||||||
if (_steps == ESteps.TryAgain)
|
if (_steps == ESteps.TryAgain)
|
||||||
{
|
{
|
||||||
if (FailedTryAgain <= 0)
|
|
||||||
{
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
YooLogger.Error(Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_tryAgainTimer += Time.unscaledDeltaTime;
|
_tryAgainTimer += Time.unscaledDeltaTime;
|
||||||
if (_tryAgainTimer > 1f)
|
if (_tryAgainTimer > 1f)
|
||||||
{
|
{
|
||||||
FailedTryAgain--;
|
_tryAgainTimer = 0f;
|
||||||
|
_failedTryAgain--;
|
||||||
|
Progress = 0f;
|
||||||
|
DownloadProgress = 0f;
|
||||||
|
DownloadedBytes = 0;
|
||||||
_steps = ESteps.CreateRequest;
|
_steps = ESteps.CreateRequest;
|
||||||
YooLogger.Warning(Error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CreateWebRequest()
|
/// <summary>
|
||||||
|
/// 获取网络请求地址
|
||||||
|
/// </summary>
|
||||||
|
private string GetRequestURL()
|
||||||
{
|
{
|
||||||
_webRequest = UnityWebRequest.Get(_requestURL);
|
// 轮流返回请求地址
|
||||||
_webRequest.SetRequestHeader("wechatminigame-preload", "1");
|
_requestCount++;
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
if (_requestCount % 2 == 0)
|
||||||
_webRequest.SendWebRequest();
|
return _options.FallbackURL;
|
||||||
}
|
else
|
||||||
private void DisposeWebRequest()
|
return _options.MainURL;
|
||||||
{
|
|
||||||
if (_webRequest != null)
|
|
||||||
{
|
|
||||||
//注意:引擎底层会自动调用Abort方法
|
|
||||||
_webRequest.Dispose();
|
|
||||||
_webRequest = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -12,9 +12,9 @@ internal class WXFSLoadBundleOperation : FSLoadBundleOperation
|
|||||||
|
|
||||||
private readonly WechatFileSystem _fileSystem;
|
private readonly WechatFileSystem _fileSystem;
|
||||||
private readonly PackageBundle _bundle;
|
private readonly PackageBundle _bundle;
|
||||||
private DownloadAssetBundleOperation _downloadAssetBundleOp;
|
private LoadWebAssetBundleOperation _loadWebAssetBundleOp;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
internal WXFSLoadBundleOperation(WechatFileSystem fileSystem, PackageBundle bundle)
|
internal WXFSLoadBundleOperation(WechatFileSystem fileSystem, PackageBundle bundle)
|
||||||
{
|
{
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
@@ -31,54 +31,46 @@ internal class WXFSLoadBundleOperation : FSLoadBundleOperation
|
|||||||
|
|
||||||
if (_steps == ESteps.DownloadAssetBundle)
|
if (_steps == ESteps.DownloadAssetBundle)
|
||||||
{
|
{
|
||||||
if (_downloadAssetBundleOp == null)
|
if (_loadWebAssetBundleOp == null)
|
||||||
{
|
{
|
||||||
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
|
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
|
||||||
options.MainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName); ;
|
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
||||||
options.FallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
|
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue);
|
||||||
|
options.SetURL(mainURL, fallbackURL);
|
||||||
|
|
||||||
if (_bundle.Encrypted)
|
if (_bundle.Encrypted)
|
||||||
{
|
{
|
||||||
_downloadAssetBundleOp = new DownloadEncryptAssetBundleOperation(false, _fileSystem.DecryptionServices, _bundle, options);
|
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices);
|
||||||
_downloadAssetBundleOp.StartOperation();
|
_loadWebAssetBundleOp.StartOperation();
|
||||||
AddChildOperation(_downloadAssetBundleOp);
|
AddChildOperation(_loadWebAssetBundleOp);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_downloadAssetBundleOp = new DownloadWechatAssetBundleOperation(_bundle, options);
|
_loadWebAssetBundleOp = new LoadWechatAssetBundleOperation(_bundle, options);
|
||||||
_downloadAssetBundleOp.StartOperation();
|
_loadWebAssetBundleOp.StartOperation();
|
||||||
AddChildOperation(_downloadAssetBundleOp);
|
AddChildOperation(_loadWebAssetBundleOp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_downloadAssetBundleOp.UpdateOperation();
|
_loadWebAssetBundleOp.UpdateOperation();
|
||||||
DownloadProgress = _downloadAssetBundleOp.DownloadProgress;
|
DownloadProgress = _loadWebAssetBundleOp.DownloadProgress;
|
||||||
DownloadedBytes = (long)_downloadAssetBundleOp.DownloadedBytes;
|
DownloadedBytes = (long)_loadWebAssetBundleOp.DownloadedBytes;
|
||||||
Progress = DownloadProgress;
|
Progress = DownloadProgress;
|
||||||
if (_downloadAssetBundleOp.IsDone == false)
|
if (_loadWebAssetBundleOp.IsDone == false)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_downloadAssetBundleOp.Status == EOperationStatus.Succeed)
|
if (_loadWebAssetBundleOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
var assetBundle = _downloadAssetBundleOp.Result;
|
var assetBundle = _loadWebAssetBundleOp.Result;
|
||||||
if (assetBundle == null)
|
_steps = ESteps.Done;
|
||||||
{
|
Result = new WXAssetBundleResult(_fileSystem, _bundle, assetBundle);
|
||||||
_steps = ESteps.Done;
|
Status = EOperationStatus.Succeed;
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = $"{nameof(DownloadAssetBundleOperation)} loaded asset bundle is null !";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Result = new WXAssetBundleResult(_fileSystem, _bundle, assetBundle);
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _downloadAssetBundleOp.Error;
|
Error = _loadWebAssetBundleOp.Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,128 +0,0 @@
|
|||||||
#if UNITY_WEBGL && WEIXINMINIGAME
|
|
||||||
using UnityEngine;
|
|
||||||
using WeChatWASM;
|
|
||||||
|
|
||||||
namespace YooAsset
|
|
||||||
{
|
|
||||||
internal class DownloadWechatAssetBundleOperation : DownloadAssetBundleOperation
|
|
||||||
{
|
|
||||||
private ESteps _steps = ESteps.None;
|
|
||||||
|
|
||||||
internal DownloadWechatAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options) : base(bundle, options)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
internal override void InternalStart()
|
|
||||||
{
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
}
|
|
||||||
internal override void InternalUpdate()
|
|
||||||
{
|
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
if (_steps == ESteps.CreateRequest)
|
|
||||||
{
|
|
||||||
// 获取请求地址
|
|
||||||
_requestURL = GetRequestURL();
|
|
||||||
|
|
||||||
// 重置变量
|
|
||||||
ResetRequestFiled();
|
|
||||||
|
|
||||||
// 创建下载器
|
|
||||||
CreateWebRequest();
|
|
||||||
|
|
||||||
_steps = ESteps.CheckRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检测下载结果
|
|
||||||
if (_steps == ESteps.CheckRequest)
|
|
||||||
{
|
|
||||||
DownloadProgress = _webRequest.downloadProgress;
|
|
||||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
|
||||||
Progress = DownloadProgress;
|
|
||||||
if (_webRequest.isDone == false)
|
|
||||||
{
|
|
||||||
//TODO 由于微信小游戏插件的问题,暂时不能判定超时!
|
|
||||||
// Issue : https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/108#
|
|
||||||
//CheckRequestTimeout();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查网络错误
|
|
||||||
if (CheckRequestResult())
|
|
||||||
{
|
|
||||||
var downloadHanlder = (DownloadHandlerWXAssetBundle)_webRequest.downloadHandler;
|
|
||||||
AssetBundle assetBundle = downloadHanlder.assetBundle;
|
|
||||||
if (assetBundle == null)
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
Error = "Download handler asset bundle object is null !";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
Result = assetBundle;
|
|
||||||
Status = EOperationStatus.Succeed;
|
|
||||||
|
|
||||||
//TODO 解决微信小游戏插件问题
|
|
||||||
// Issue : https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/108#
|
|
||||||
DownloadProgress = 1f;
|
|
||||||
DownloadedBytes = Bundle.FileSize;
|
|
||||||
Progress = 1f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_steps = ESteps.TryAgain;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 注意:最终释放请求器
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 重新尝试下载
|
|
||||||
if (_steps == ESteps.TryAgain)
|
|
||||||
{
|
|
||||||
if (FailedTryAgain <= 0)
|
|
||||||
{
|
|
||||||
Status = EOperationStatus.Failed;
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
YooLogger.Error(Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
_tryAgainTimer += Time.unscaledDeltaTime;
|
|
||||||
if (_tryAgainTimer > 1f)
|
|
||||||
{
|
|
||||||
FailedTryAgain--;
|
|
||||||
_steps = ESteps.CreateRequest;
|
|
||||||
YooLogger.Warning(Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
internal override void InternalAbort()
|
|
||||||
{
|
|
||||||
_steps = ESteps.Done;
|
|
||||||
DisposeWebRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CreateWebRequest()
|
|
||||||
{
|
|
||||||
_webRequest = WXAssetBundle.GetAssetBundle(_requestURL);
|
|
||||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
|
||||||
_webRequest.SendWebRequest();
|
|
||||||
}
|
|
||||||
private void DisposeWebRequest()
|
|
||||||
{
|
|
||||||
if (_webRequest != null)
|
|
||||||
{
|
|
||||||
//注意:引擎底层会自动调用Abort方法
|
|
||||||
_webRequest.Dispose();
|
|
||||||
_webRequest = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class LoadWechatAssetBundleOperation : LoadWebAssetBundleOperation
|
||||||
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
CheckRequest,
|
||||||
|
TryAgain,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly PackageBundle _bundle;
|
||||||
|
private readonly DownloadFileOptions _options;
|
||||||
|
private UnityWechatAssetBundleRequestOperation _unityWechatAssetBundleRequestOp;
|
||||||
|
|
||||||
|
private int _requestCount = 0;
|
||||||
|
private float _tryAgainTimer;
|
||||||
|
private int _failedTryAgain;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
|
||||||
|
internal LoadWechatAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options)
|
||||||
|
{
|
||||||
|
_bundle = bundle;
|
||||||
|
_options = options;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// 创建下载器
|
||||||
|
if (_steps == ESteps.CreateRequest)
|
||||||
|
{
|
||||||
|
string url = GetRequestURL();
|
||||||
|
_unityWechatAssetBundleRequestOp = new UnityWechatAssetBundleRequestOperation(_bundle, url);
|
||||||
|
_unityWechatAssetBundleRequestOp.StartOperation();
|
||||||
|
AddChildOperation(_unityWechatAssetBundleRequestOp);
|
||||||
|
_steps = ESteps.CheckRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测下载结果
|
||||||
|
if (_steps == ESteps.CheckRequest)
|
||||||
|
{
|
||||||
|
_unityWechatAssetBundleRequestOp.UpdateOperation();
|
||||||
|
Progress = _unityWechatAssetBundleRequestOp.Progress;
|
||||||
|
DownloadProgress = _unityWechatAssetBundleRequestOp.DownloadProgress;
|
||||||
|
DownloadedBytes = (long)_unityWechatAssetBundleRequestOp.DownloadedBytes;
|
||||||
|
if (_unityWechatAssetBundleRequestOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_unityWechatAssetBundleRequestOp.Status == EOperationStatus.Succeed)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
Result = _unityWechatAssetBundleRequestOp.Result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_failedTryAgain > 0)
|
||||||
|
{
|
||||||
|
_steps = ESteps.TryAgain;
|
||||||
|
YooLogger.Warning($"Failed download : {_unityWechatAssetBundleRequestOp.URL} Try again !");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = _unityWechatAssetBundleRequestOp.Error;
|
||||||
|
YooLogger.Error(Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重新尝试下载
|
||||||
|
if (_steps == ESteps.TryAgain)
|
||||||
|
{
|
||||||
|
_tryAgainTimer += Time.unscaledDeltaTime;
|
||||||
|
if (_tryAgainTimer > 1f)
|
||||||
|
{
|
||||||
|
_tryAgainTimer = 0f;
|
||||||
|
_failedTryAgain--;
|
||||||
|
Progress = 0f;
|
||||||
|
DownloadProgress = 0f;
|
||||||
|
DownloadedBytes = 0;
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal override void InternalAbort()
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
if (_unityWechatAssetBundleRequestOp != null)
|
||||||
|
_unityWechatAssetBundleRequestOp.AbortOperation();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取网络请求地址
|
||||||
|
/// </summary>
|
||||||
|
protected string GetRequestURL()
|
||||||
|
{
|
||||||
|
// 轮流返回请求地址
|
||||||
|
_requestCount++;
|
||||||
|
if (_requestCount % 2 == 0)
|
||||||
|
return _options.FallbackURL;
|
||||||
|
else
|
||||||
|
return _options.MainURL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
#if UNITY_WEBGL && WEIXINMINIGAME
|
||||||
|
using UnityEngine.Networking;
|
||||||
|
using UnityEngine;
|
||||||
|
using WeChatWASM;
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class UnityWechatAssetBundleRequestOperation : UnityWebRequestOperation
|
||||||
|
{
|
||||||
|
protected enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
CreateRequest,
|
||||||
|
Download,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly PackageBundle _packageBundle;
|
||||||
|
private UnityWebRequestAsyncOperation _requestOperation;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 请求结果
|
||||||
|
/// </summary>
|
||||||
|
public AssetBundle Result { private set; get; }
|
||||||
|
|
||||||
|
internal UnityWechatAssetBundleRequestOperation(PackageBundle bundle, string url) : base(url)
|
||||||
|
{
|
||||||
|
_packageBundle = bundle;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.CreateRequest;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.CreateRequest)
|
||||||
|
{
|
||||||
|
CreateWebRequest();
|
||||||
|
_steps = ESteps.Download;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.Download)
|
||||||
|
{
|
||||||
|
DownloadProgress = _webRequest.downloadProgress;
|
||||||
|
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||||
|
Progress = _requestOperation.progress;
|
||||||
|
if (_requestOperation.isDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (CheckRequestResult())
|
||||||
|
{
|
||||||
|
var downloadHanlder = (DownloadHandlerWXAssetBundle)_webRequest.downloadHandler;
|
||||||
|
AssetBundle assetBundle = downloadHanlder.assetBundle;
|
||||||
|
if (assetBundle == null)
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
Error = $"URL : {_requestURL} Download handler asset bundle object is null !";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Result = assetBundle;
|
||||||
|
Status = EOperationStatus.Succeed;
|
||||||
|
|
||||||
|
//TODO 解决微信小游戏插件问题
|
||||||
|
// Issue : https://github.com/wechat-miniprogram/minigame-unity-webgl-transform/issues/108#
|
||||||
|
DownloadProgress = 1f;
|
||||||
|
DownloadedBytes = _packageBundle.FileSize;
|
||||||
|
Progress = 1f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = EOperationStatus.Failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注意:最终释放请求器
|
||||||
|
DisposeRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CreateWebRequest()
|
||||||
|
{
|
||||||
|
_webRequest = WXAssetBundle.GetAssetBundle(_requestURL);
|
||||||
|
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||||
|
_requestOperation = _webRequest.SendWebRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8dd1f15e52120ad409285fa3e21c7d30
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -151,8 +151,9 @@ internal class WechatFileSystem : IFileSystem
|
|||||||
}
|
}
|
||||||
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options)
|
||||||
{
|
{
|
||||||
options.MainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
|
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
|
||||||
options.FallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
||||||
|
options.SetURL(mainURL, fallbackURL);
|
||||||
var operation = new WXFSDownloadFileOperation(this, bundle, options);
|
var operation = new WXFSDownloadFileOperation(this, bundle, options);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 4ce11d98eccfa4b44bf2c82f7d87d105
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
using YooAsset;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 文件偏移加密方式
|
||||||
|
/// </summary>
|
||||||
|
public class TestFileOffsetEncryption : IEncryptionServices
|
||||||
|
{
|
||||||
|
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
// 说明:对TestRes3资源目录进行加密
|
||||||
|
if (fileInfo.BundleName.Contains("_testres3_"))
|
||||||
|
{
|
||||||
|
int offset = 32;
|
||||||
|
byte[] fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
|
||||||
|
var encryptedData = new byte[fileData.Length + offset];
|
||||||
|
Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length);
|
||||||
|
|
||||||
|
EncryptResult result = new EncryptResult();
|
||||||
|
result.Encrypted = true;
|
||||||
|
result.EncryptedData = encryptedData;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EncryptResult result = new EncryptResult();
|
||||||
|
result.Encrypted = false;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源文件偏移解密类
|
||||||
|
/// </summary>
|
||||||
|
public class TestFileOffsetDecryption : IDecryptionServices
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 同步方式获取解密的资源包对象
|
||||||
|
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||||
|
/// </summary>
|
||||||
|
DecryptResult IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
DecryptResult decryptResult = new DecryptResult();
|
||||||
|
decryptResult.ManagedStream = null;
|
||||||
|
decryptResult.Result = AssetBundle.LoadFromFile(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
|
||||||
|
return decryptResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异步方式获取解密的资源包对象
|
||||||
|
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||||
|
/// </summary>
|
||||||
|
DecryptResult IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
DecryptResult decryptResult = new DecryptResult();
|
||||||
|
decryptResult.ManagedStream = null;
|
||||||
|
decryptResult.CreateRequest = AssetBundle.LoadFromFileAsync(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
|
||||||
|
return decryptResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 后备方式获取解密的资源包对象
|
||||||
|
/// </summary>
|
||||||
|
DecryptResult IDecryptionServices.LoadAssetBundleFallback(DecryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
return new DecryptResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取解密的字节数据
|
||||||
|
/// </summary>
|
||||||
|
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取解密的文本数据
|
||||||
|
/// </summary>
|
||||||
|
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ulong GetFileOffset()
|
||||||
|
{
|
||||||
|
return 32;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 174e56f3a30d7fd4e80bde43ba267631
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
using YooAsset;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源文件解密流
|
||||||
|
/// </summary>
|
||||||
|
public class BundleStream : FileStream
|
||||||
|
{
|
||||||
|
public const byte KEY = 64;
|
||||||
|
|
||||||
|
public BundleStream(string path, FileMode mode, FileAccess access, FileShare share) : base(path, mode, access, share)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public BundleStream(string path, FileMode mode) : base(path, mode)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int Read(byte[] array, int offset, int count)
|
||||||
|
{
|
||||||
|
var index = base.Read(array, offset, count);
|
||||||
|
for (int i = 0; i < array.Length; i++)
|
||||||
|
{
|
||||||
|
array[i] ^= KEY;
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 文件流加密方式
|
||||||
|
/// </summary>
|
||||||
|
public class TestFileStreamEncryption : IEncryptionServices
|
||||||
|
{
|
||||||
|
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
// 说明:对TestRes3资源目录进行加密
|
||||||
|
if (fileInfo.BundleName.Contains("_testres3_"))
|
||||||
|
{
|
||||||
|
var fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
|
||||||
|
for (int i = 0; i < fileData.Length; i++)
|
||||||
|
{
|
||||||
|
fileData[i] ^= BundleStream.KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
EncryptResult result = new EncryptResult();
|
||||||
|
result.Encrypted = true;
|
||||||
|
result.EncryptedData = fileData;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
EncryptResult result = new EncryptResult();
|
||||||
|
result.Encrypted = false;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 资源文件流解密类
|
||||||
|
/// </summary>
|
||||||
|
public class TestFileStreamDecryption : IDecryptionServices
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 同步方式获取解密的资源包对象
|
||||||
|
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||||
|
/// </summary>
|
||||||
|
DecryptResult IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||||
|
DecryptResult decryptResult = new DecryptResult();
|
||||||
|
decryptResult.ManagedStream = bundleStream;
|
||||||
|
decryptResult.Result = AssetBundle.LoadFromStream(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
|
||||||
|
return decryptResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 异步方式获取解密的资源包对象
|
||||||
|
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
||||||
|
/// </summary>
|
||||||
|
DecryptResult IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||||
|
DecryptResult decryptResult = new DecryptResult();
|
||||||
|
decryptResult.ManagedStream = bundleStream;
|
||||||
|
decryptResult.CreateRequest = AssetBundle.LoadFromStreamAsync(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
|
||||||
|
return decryptResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 后备方式获取解密的资源包对象
|
||||||
|
/// </summary>
|
||||||
|
DecryptResult IDecryptionServices.LoadAssetBundleFallback(DecryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
return new DecryptResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取解密的字节数据
|
||||||
|
/// </summary>
|
||||||
|
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取解密的文本数据
|
||||||
|
/// </summary>
|
||||||
|
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static uint GetManagedReadBufferSize()
|
||||||
|
{
|
||||||
|
return 1024;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// WebGL平台解密类
|
||||||
|
/// 注意:WebGL平台支持内存解密
|
||||||
|
/// </summary>
|
||||||
|
public class TestWebFileMemoryDecryption : IWebDecryptionServices
|
||||||
|
{
|
||||||
|
public WebDecryptResult LoadAssetBundle(WebDecryptFileInfo fileInfo)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
byte[] copyData = new byte[fileInfo.FileData.Length];
|
||||||
|
Buffer.BlockCopy(fileInfo.FileData, 0, copyData, 0, fileInfo.FileData.Length);
|
||||||
|
|
||||||
|
for (int i = 0; i < copyData.Length; i++)
|
||||||
|
{
|
||||||
|
copyData[i] ^= BundleStream.KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
WebDecryptResult decryptResult = new WebDecryptResult();
|
||||||
|
decryptResult.Result = AssetBundle.LoadFromMemory(copyData);
|
||||||
|
return decryptResult;
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (int i = 0; i < fileInfo.FileData.Length; i++)
|
||||||
|
{
|
||||||
|
fileInfo.FileData[i] ^= BundleStream.KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
WebDecryptResult decryptResult = new WebDecryptResult();
|
||||||
|
decryptResult.Result = AssetBundle.LoadFromMemory(fileInfo.FileData);
|
||||||
|
return decryptResult;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: d264e4255e837db41900a9a54bd828f4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -89,7 +89,7 @@ public class T0_InitYooAssets : IPrebuildSetup, IPostBuildCleanup
|
|||||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(panelGroup, collector1);
|
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(panelGroup, collector1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 预制体
|
// 预制体(构建到一个AB)
|
||||||
var prefabGroup = YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(testPackage, "PrefabGroup");
|
var prefabGroup = YooAsset.Editor.AssetBundleCollectorSettingData.CreateGroup(testPackage, "PrefabGroup");
|
||||||
{
|
{
|
||||||
var collector1 = new YooAsset.Editor.AssetBundleCollector();
|
var collector1 = new YooAsset.Editor.AssetBundleCollector();
|
||||||
@@ -169,14 +169,30 @@ public class T0_InitYooAssets : IPrebuildSetup, IPostBuildCleanup
|
|||||||
collector1.CollectorGUID = "e082d492b9da65e499cee3495be3645d"; //TestRes3/music目录
|
collector1.CollectorGUID = "e082d492b9da65e499cee3495be3645d"; //TestRes3/music目录
|
||||||
collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
|
collector1.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
|
||||||
collector1.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
|
collector1.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
|
||||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(referenceGroup, collector1);
|
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(encryptGroup, collector1);
|
||||||
|
|
||||||
var collector2 = new YooAsset.Editor.AssetBundleCollector();
|
var collector2 = new YooAsset.Editor.AssetBundleCollector();
|
||||||
collector2.CollectPath = "";
|
collector2.CollectPath = "";
|
||||||
collector2.CollectorGUID = "8c5a1726d94498e4cbe30f5f510cc796"; //TestRes3/prefab目录
|
collector2.CollectorGUID = "8c5a1726d94498e4cbe30f5f510cc796"; //TestRes3/prefab目录
|
||||||
collector2.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
|
collector2.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
|
||||||
collector2.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
|
collector2.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
|
||||||
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(referenceGroup, collector2);
|
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(encryptGroup, collector2);
|
||||||
|
|
||||||
|
var collector3 = new YooAsset.Editor.AssetBundleCollector();
|
||||||
|
collector3.CollectPath = "";
|
||||||
|
collector3.CollectorGUID = "401af1ca0abf3ae4594631e5f71bfe27"; //TestRes3/unpack目录
|
||||||
|
collector3.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
|
||||||
|
collector3.AssetTags = "unpack";
|
||||||
|
collector3.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
|
||||||
|
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(encryptGroup, collector3);
|
||||||
|
|
||||||
|
var collector4 = new YooAsset.Editor.AssetBundleCollector();
|
||||||
|
collector4.CollectPath = "";
|
||||||
|
collector4.CollectorGUID = "35f454fb80a715047bcf0ce30c7c4f18"; //TestRes3/import目录
|
||||||
|
collector4.CollectorType = YooAsset.Editor.ECollectorType.MainAssetCollector;
|
||||||
|
collector4.AssetTags = "import";
|
||||||
|
collector4.PackRuleName = nameof(YooAsset.Editor.PackSeparately);
|
||||||
|
YooAsset.Editor.AssetBundleCollectorSettingData.CreateCollector(encryptGroup, collector4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static void CreateRawBundlePackageCollector()
|
private static void CreateRawBundlePackageCollector()
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class T1_TestEditorFileSystem : IPrebuildSetup, IPostBuildCleanup
|
|||||||
simulateParams.InvokeAssmeblyName = "YooAsset.Test.Editor";
|
simulateParams.InvokeAssmeblyName = "YooAsset.Test.Editor";
|
||||||
simulateParams.InvokeClassFullName = "TestPackageBuilder";
|
simulateParams.InvokeClassFullName = "TestPackageBuilder";
|
||||||
simulateParams.InvokeMethodName = "BuildPackage";
|
simulateParams.InvokeMethodName = "BuildPackage";
|
||||||
var simulateResult = PakcageInvokeBuilder.InvokeBuilder(simulateParams);
|
var simulateResult = PackageInvokeBuilder.InvokeBuilder(simulateParams);
|
||||||
UnityEditor.EditorPrefs.SetString(ASSET_BUNDLE_PACKAGE_ROOT_KEY, simulateResult.PackageRootDirectory);
|
UnityEditor.EditorPrefs.SetString(ASSET_BUNDLE_PACKAGE_ROOT_KEY, simulateResult.PackageRootDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ public class T1_TestEditorFileSystem : IPrebuildSetup, IPostBuildCleanup
|
|||||||
simulateParams.InvokeAssmeblyName = "YooAsset.Test.Editor";
|
simulateParams.InvokeAssmeblyName = "YooAsset.Test.Editor";
|
||||||
simulateParams.InvokeClassFullName = "TestPackageBuilder";
|
simulateParams.InvokeClassFullName = "TestPackageBuilder";
|
||||||
simulateParams.InvokeMethodName = "BuildPackage";
|
simulateParams.InvokeMethodName = "BuildPackage";
|
||||||
var simulateResult = PakcageInvokeBuilder.InvokeBuilder(simulateParams);
|
var simulateResult = PackageInvokeBuilder.InvokeBuilder(simulateParams);
|
||||||
UnityEditor.EditorPrefs.SetString(RAW_BUNDLE_PACKAGE_ROOT_KEY, simulateResult.PackageRootDirectory);
|
UnityEditor.EditorPrefs.SetString(RAW_BUNDLE_PACKAGE_ROOT_KEY, simulateResult.PackageRootDirectory);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ using YooAsset;
|
|||||||
|
|
||||||
public class T2_TestBuldinFileSystem : IPrebuildSetup, IPostBuildCleanup
|
public class T2_TestBuldinFileSystem : IPrebuildSetup, IPostBuildCleanup
|
||||||
{
|
{
|
||||||
private const string ASSET_BUNDLE_PACKAGE_ROOT_KEY = "T2_ASSET_BUNDLE_PACKAGE_ROOT_KEY";
|
public const string ASSET_BUNDLE_PACKAGE_ROOT_KEY = "T2_ASSET_BUNDLE_PACKAGE_ROOT_KEY";
|
||||||
private const string RAW_BUNDLE_PACKAGE_ROOT_KEY = "T2_RAW_BUNDLE_PACKAGE_ROOT_KEY";
|
public const string RAW_BUNDLE_PACKAGE_ROOT_KEY = "T2_RAW_BUNDLE_PACKAGE_ROOT_KEY";
|
||||||
|
|
||||||
void IPrebuildSetup.Setup()
|
void IPrebuildSetup.Setup()
|
||||||
{
|
{
|
||||||
@@ -24,7 +24,7 @@ public class T2_TestBuldinFileSystem : IPrebuildSetup, IPostBuildCleanup
|
|||||||
buildParams.InvokeAssmeblyName = "YooAsset.Test.Editor";
|
buildParams.InvokeAssmeblyName = "YooAsset.Test.Editor";
|
||||||
buildParams.InvokeClassFullName = "TestPackageBuilder";
|
buildParams.InvokeClassFullName = "TestPackageBuilder";
|
||||||
buildParams.InvokeMethodName = "BuildPackage";
|
buildParams.InvokeMethodName = "BuildPackage";
|
||||||
var simulateResult = PakcageInvokeBuilder.InvokeBuilder(buildParams);
|
var simulateResult = PackageInvokeBuilder.InvokeBuilder(buildParams);
|
||||||
UnityEditor.EditorPrefs.SetString(ASSET_BUNDLE_PACKAGE_ROOT_KEY, simulateResult.PackageRootDirectory);
|
UnityEditor.EditorPrefs.SetString(ASSET_BUNDLE_PACKAGE_ROOT_KEY, simulateResult.PackageRootDirectory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ public class T2_TestBuldinFileSystem : IPrebuildSetup, IPostBuildCleanup
|
|||||||
buildParams.InvokeAssmeblyName = "YooAsset.Test.Editor";
|
buildParams.InvokeAssmeblyName = "YooAsset.Test.Editor";
|
||||||
buildParams.InvokeClassFullName = "TestPackageBuilder";
|
buildParams.InvokeClassFullName = "TestPackageBuilder";
|
||||||
buildParams.InvokeMethodName = "BuildPackage";
|
buildParams.InvokeMethodName = "BuildPackage";
|
||||||
var simulateResult = PakcageInvokeBuilder.InvokeBuilder(buildParams);
|
var simulateResult = PackageInvokeBuilder.InvokeBuilder(buildParams);
|
||||||
UnityEditor.EditorPrefs.SetString(RAW_BUNDLE_PACKAGE_ROOT_KEY, simulateResult.PackageRootDirectory);
|
UnityEditor.EditorPrefs.SetString(RAW_BUNDLE_PACKAGE_ROOT_KEY, simulateResult.PackageRootDirectory);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ using UnityEngine;
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 测试加载加密文件
|
||||||
|
/// </summary>
|
||||||
public class TestBundleEncryption
|
public class TestBundleEncryption
|
||||||
{
|
{
|
||||||
public IEnumerator RuntimeTester()
|
public IEnumerator RuntimeTester()
|
||||||
@@ -39,245 +42,27 @@ public class TestBundleEncryption
|
|||||||
Assert.IsNotNull(audioSource.clip);
|
Assert.IsNotNull(audioSource.clip);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 试听三秒钟
|
yield return new WaitForSeconds(1f);
|
||||||
yield return new WaitForSeconds(3f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/* 资源代码流程
|
||||||
/// 文件流加密方式
|
* 内置文件解压(加载器)
|
||||||
/// </summary>
|
BuildinFileSystem::LoadBundleFile()
|
||||||
public class TestFileStreamEncryption : IEncryptionServices
|
|
||||||
{
|
{
|
||||||
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
_unpackFileSystem.LoadBundleFile(bundle);
|
||||||
{
|
|
||||||
// 说明:对TestRes3资源目录进行加密
|
|
||||||
if (fileInfo.BundleName.Contains("_testres3_"))
|
|
||||||
{
|
|
||||||
var fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
|
|
||||||
for (int i = 0; i < fileData.Length; i++)
|
|
||||||
{
|
|
||||||
fileData[i] ^= BundleStream.KEY;
|
|
||||||
}
|
|
||||||
|
|
||||||
EncryptResult result = new EncryptResult();
|
|
||||||
result.Encrypted = true;
|
|
||||||
result.EncryptedData = fileData;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
EncryptResult result = new EncryptResult();
|
|
||||||
result.Encrypted = false;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
UnpackFileSystem::LoadAssetBundleOperation()
|
||||||
/// <summary>
|
|
||||||
/// 文件偏移加密方式
|
|
||||||
/// </summary>
|
|
||||||
public class TestFileOffsetEncryption : IEncryptionServices
|
|
||||||
{
|
{
|
||||||
public EncryptResult Encrypt(EncryptFileInfo fileInfo)
|
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
|
||||||
{
|
_unpackFileSystem.DownloadFileAsync(_bundle, options);
|
||||||
// 说明:对TestRes3资源目录进行加密
|
|
||||||
if (fileInfo.BundleName.Contains("_testres3_"))
|
|
||||||
{
|
|
||||||
int offset = 32;
|
|
||||||
byte[] fileData = File.ReadAllBytes(fileInfo.FileLoadPath);
|
|
||||||
var encryptedData = new byte[fileData.Length + offset];
|
|
||||||
Buffer.BlockCopy(fileData, 0, encryptedData, offset, fileData.Length);
|
|
||||||
|
|
||||||
EncryptResult result = new EncryptResult();
|
|
||||||
result.Encrypted = true;
|
|
||||||
result.EncryptedData = encryptedData;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
EncryptResult result = new EncryptResult();
|
|
||||||
result.Encrypted = false;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
UnpackFileSystem::DownloadFileAsync()
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 资源文件解密流
|
|
||||||
/// </summary>
|
|
||||||
public class BundleStream : FileStream
|
|
||||||
{
|
{
|
||||||
public const byte KEY = 64;
|
//RemoteServices返回内置文件路径
|
||||||
|
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
|
||||||
public BundleStream(string path, FileMode mode, FileAccess access, FileShare share) : base(path, mode, access, share)
|
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
||||||
{
|
options.SetURL(mainURL, fallbackURL);
|
||||||
}
|
return new DownloadPackageBundleOperation(bundle, options);
|
||||||
public BundleStream(string path, FileMode mode) : base(path, mode)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Read(byte[] array, int offset, int count)
|
|
||||||
{
|
|
||||||
var index = base.Read(array, offset, count);
|
|
||||||
for (int i = 0; i < array.Length; i++)
|
|
||||||
{
|
|
||||||
array[i] ^= KEY;
|
|
||||||
}
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
/// <summary>
|
|
||||||
/// 资源文件流解密类
|
|
||||||
/// </summary>
|
|
||||||
public class TestFileStreamDecryption : IDecryptionServices
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 同步方式获取解密的资源包对象
|
|
||||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
|
||||||
/// </summary>
|
|
||||||
DecryptResult IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo)
|
|
||||||
{
|
|
||||||
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
||||||
DecryptResult decryptResult = new DecryptResult();
|
|
||||||
decryptResult.ManagedStream = bundleStream;
|
|
||||||
decryptResult.Result = AssetBundle.LoadFromStream(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
|
|
||||||
return decryptResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 异步方式获取解密的资源包对象
|
|
||||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
|
||||||
/// </summary>
|
|
||||||
DecryptResult IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo)
|
|
||||||
{
|
|
||||||
BundleStream bundleStream = new BundleStream(fileInfo.FileLoadPath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
|
||||||
DecryptResult decryptResult = new DecryptResult();
|
|
||||||
decryptResult.ManagedStream = bundleStream;
|
|
||||||
decryptResult.CreateRequest = AssetBundle.LoadFromStreamAsync(bundleStream, fileInfo.FileLoadCRC, GetManagedReadBufferSize());
|
|
||||||
return decryptResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 后备方式获取解密的资源包对象
|
|
||||||
/// </summary>
|
|
||||||
DecryptResult IDecryptionServices.LoadAssetBundleFallback(DecryptFileInfo fileInfo)
|
|
||||||
{
|
|
||||||
return new DecryptResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取解密的字节数据
|
|
||||||
/// </summary>
|
|
||||||
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
|
|
||||||
{
|
|
||||||
throw new System.NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取解密的文本数据
|
|
||||||
/// </summary>
|
|
||||||
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
|
|
||||||
{
|
|
||||||
throw new System.NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static uint GetManagedReadBufferSize()
|
|
||||||
{
|
|
||||||
return 1024;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 资源文件偏移解密类
|
|
||||||
/// </summary>
|
|
||||||
public class TestFileOffsetDecryption : IDecryptionServices
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 同步方式获取解密的资源包对象
|
|
||||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
|
||||||
/// </summary>
|
|
||||||
DecryptResult IDecryptionServices.LoadAssetBundle(DecryptFileInfo fileInfo)
|
|
||||||
{
|
|
||||||
DecryptResult decryptResult = new DecryptResult();
|
|
||||||
decryptResult.ManagedStream = null;
|
|
||||||
decryptResult.Result = AssetBundle.LoadFromFile(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
|
|
||||||
return decryptResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 异步方式获取解密的资源包对象
|
|
||||||
/// 注意:加载流对象在资源包对象释放的时候会自动释放
|
|
||||||
/// </summary>
|
|
||||||
DecryptResult IDecryptionServices.LoadAssetBundleAsync(DecryptFileInfo fileInfo)
|
|
||||||
{
|
|
||||||
DecryptResult decryptResult = new DecryptResult();
|
|
||||||
decryptResult.ManagedStream = null;
|
|
||||||
decryptResult.CreateRequest = AssetBundle.LoadFromFileAsync(fileInfo.FileLoadPath, fileInfo.FileLoadCRC, GetFileOffset());
|
|
||||||
return decryptResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 后备方式获取解密的资源包对象
|
|
||||||
/// </summary>
|
|
||||||
DecryptResult IDecryptionServices.LoadAssetBundleFallback(DecryptFileInfo fileInfo)
|
|
||||||
{
|
|
||||||
return new DecryptResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取解密的字节数据
|
|
||||||
/// </summary>
|
|
||||||
byte[] IDecryptionServices.ReadFileData(DecryptFileInfo fileInfo)
|
|
||||||
{
|
|
||||||
throw new System.NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取解密的文本数据
|
|
||||||
/// </summary>
|
|
||||||
string IDecryptionServices.ReadFileText(DecryptFileInfo fileInfo)
|
|
||||||
{
|
|
||||||
throw new System.NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ulong GetFileOffset()
|
|
||||||
{
|
|
||||||
return 32;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// WebGL平台解密类
|
|
||||||
/// 注意:WebGL平台支持内存解密
|
|
||||||
/// </summary>
|
|
||||||
public class TestWebFileStreamDecryption : IWebDecryptionServices
|
|
||||||
{
|
|
||||||
public WebDecryptResult LoadAssetBundle(WebDecryptFileInfo fileInfo)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
byte[] copyData = new byte[fileInfo.FileData.Length];
|
|
||||||
Buffer.BlockCopy(fileInfo.FileData, 0, copyData, 0, fileInfo.FileData.Length);
|
|
||||||
|
|
||||||
for (int i = 0; i < copyData.Length; i++)
|
|
||||||
{
|
|
||||||
copyData[i] ^= BundleStream.KEY;
|
|
||||||
}
|
|
||||||
|
|
||||||
WebDecryptResult decryptResult = new WebDecryptResult();
|
|
||||||
decryptResult.Result = AssetBundle.LoadFromMemory(copyData);
|
|
||||||
return decryptResult;
|
|
||||||
*/
|
|
||||||
|
|
||||||
for (int i = 0; i < fileInfo.FileData.Length; i++)
|
|
||||||
{
|
|
||||||
fileInfo.FileData[i] ^= BundleStream.KEY;
|
|
||||||
}
|
|
||||||
|
|
||||||
WebDecryptResult decryptResult = new WebDecryptResult();
|
|
||||||
decryptResult.Result = AssetBundle.LoadFromMemory(fileInfo.FileData);
|
|
||||||
return decryptResult;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using YooAsset;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 测试内置文件解压
|
||||||
|
/// </summary>
|
||||||
|
public class TestBundleUnpacker
|
||||||
|
{
|
||||||
|
public IEnumerator RuntimeTester()
|
||||||
|
{
|
||||||
|
ResourcePackage package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
|
||||||
|
Assert.IsNotNull(package);
|
||||||
|
|
||||||
|
var resourceUnpacker = package.CreateResourceUnpacker("unpack", 10, 1);
|
||||||
|
Assert.AreEqual(resourceUnpacker.TotalDownloadCount, 2);
|
||||||
|
|
||||||
|
yield return resourceUnpacker;
|
||||||
|
Assert.AreEqual(EOperationStatus.Succeed, resourceUnpacker.Status);
|
||||||
|
|
||||||
|
// 等待一秒
|
||||||
|
yield return new WaitForSeconds(1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 资源代码流程
|
||||||
|
* 内置文件解压(解压器)
|
||||||
|
BundleInfo::CreateDownloader()
|
||||||
|
{
|
||||||
|
return _buildFileSystem.DownloadFileAsync(Bundle, options);
|
||||||
|
}
|
||||||
|
BuildinFileSystem::DownloadFileAsync()
|
||||||
|
{
|
||||||
|
options.ImportFilePath = xxxxxx;
|
||||||
|
_unpackFileSystem.DownloadFileAsync(bundle, options);
|
||||||
|
}
|
||||||
|
UnpackFileSystem::DownloadFileAsync()
|
||||||
|
{
|
||||||
|
string mainURL = ConvertToWWWPath(options.ImportFilePath);
|
||||||
|
options.SetURL(mainURL, mainURL);
|
||||||
|
return new DownloadPackageBundleOperation(bundle, options);
|
||||||
|
}
|
||||||
|
*/
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5e56d0784f1af504c821e67a5ba81862
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -3,18 +3,143 @@ using System.IO;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
using UnityEngine.U2D;
|
||||||
using UnityEngine.TestTools;
|
using UnityEngine.TestTools;
|
||||||
|
using NUnit.Framework;
|
||||||
using YooAsset;
|
using YooAsset;
|
||||||
|
|
||||||
public class T3_TestCacheFileSystem : IPrebuildSetup, IPostBuildCleanup
|
public class T3_TestCacheFileSystem : IPrebuildSetup, IPostBuildCleanup
|
||||||
{
|
{
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Cleanup()
|
public void Cleanup()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
}
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator A_InitializePackage()
|
||||||
|
{
|
||||||
|
// 清空旧的缓存目录
|
||||||
|
string projectPath = Path.GetDirectoryName(Application.dataPath);
|
||||||
|
string cacheRoot = $"{projectPath}/yoo";
|
||||||
|
Directory.Delete(cacheRoot, true);
|
||||||
|
|
||||||
|
// 拷贝打包资源到本地服务器
|
||||||
|
{
|
||||||
|
string packageRoot = string.Empty;
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
packageRoot = UnityEditor.EditorPrefs.GetString(T2_TestBuldinFileSystem.ASSET_BUNDLE_PACKAGE_ROOT_KEY);
|
||||||
|
#endif
|
||||||
|
if (Directory.Exists(packageRoot) == false)
|
||||||
|
throw new Exception($"Not found package root : {packageRoot}");
|
||||||
|
|
||||||
|
string testServerDirectory = "C://xampp/htdocs/CDN/Android/Test";
|
||||||
|
CopyDirectory(packageRoot, testServerDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始化资源包 ASSET_BUNDLE
|
||||||
|
{
|
||||||
|
var package = YooAssets.CreatePackage(TestDefine.AssetBundlePackageName);
|
||||||
|
|
||||||
|
// 初始化资源包
|
||||||
|
var initParams = new HostPlayModeParameters();
|
||||||
|
var fileDecryption = new TestFileStreamDecryption();
|
||||||
|
var manifestProcess = new TestProcessManifest();
|
||||||
|
|
||||||
|
string hostServerIP = "http://127.0.0.1/CDN/Android/Test/";
|
||||||
|
var remoteServices = new TestRemoteServices(hostServerIP);
|
||||||
|
initParams.BuildinFileSystemParameters = null;
|
||||||
|
initParams.CacheFileSystemParameters = FileSystemParameters.CreateDefaultCacheFileSystemParameters(remoteServices, fileDecryption);
|
||||||
|
initParams.CacheFileSystemParameters.AddParameter(FileSystemParametersDefine.MANIFEST_SERVICES, manifestProcess);
|
||||||
|
var initializeOp = package.InitializeAsync(initParams);
|
||||||
|
yield return initializeOp;
|
||||||
|
if (initializeOp.Status != EOperationStatus.Succeed)
|
||||||
|
Debug.LogError(initializeOp.Error);
|
||||||
|
Assert.AreEqual(EOperationStatus.Succeed, initializeOp.Status);
|
||||||
|
|
||||||
|
// 请求资源版本
|
||||||
|
var requetVersionOp = package.RequestPackageVersionAsync();
|
||||||
|
yield return requetVersionOp;
|
||||||
|
if (requetVersionOp.Status != EOperationStatus.Succeed)
|
||||||
|
Debug.LogError(requetVersionOp.Error);
|
||||||
|
Assert.AreEqual(EOperationStatus.Succeed, requetVersionOp.Status);
|
||||||
|
|
||||||
|
// 更新资源清单
|
||||||
|
var updateManifestOp = package.UpdatePackageManifestAsync(requetVersionOp.PackageVersion);
|
||||||
|
yield return updateManifestOp;
|
||||||
|
if (updateManifestOp.Status != EOperationStatus.Succeed)
|
||||||
|
Debug.LogError(updateManifestOp.Error);
|
||||||
|
Assert.AreEqual(EOperationStatus.Succeed, updateManifestOp.Status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private class TestRemoteServices : IRemoteServices
|
||||||
|
{
|
||||||
|
private readonly string _localServerRoot;
|
||||||
|
|
||||||
|
public TestRemoteServices(string localServerRoot)
|
||||||
|
{
|
||||||
|
_localServerRoot = localServerRoot;
|
||||||
|
}
|
||||||
|
string IRemoteServices.GetRemoteMainURL(string fileName)
|
||||||
|
{
|
||||||
|
return $"{_localServerRoot}/{fileName}";
|
||||||
|
}
|
||||||
|
string IRemoteServices.GetRemoteFallbackURL(string fileName)
|
||||||
|
{
|
||||||
|
return $"{_localServerRoot}/{fileName}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator B1_TestBundlePlaying()
|
||||||
|
{
|
||||||
|
var tester = new TestBundlePlaying();
|
||||||
|
yield return tester.RuntimeTester();
|
||||||
|
}
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator B2_TestBundleImporter()
|
||||||
|
{
|
||||||
|
var tester = new TestBundleImporter();
|
||||||
|
yield return tester.RuntimeTester();
|
||||||
|
}
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator B3_TestBundleDownloader()
|
||||||
|
{
|
||||||
|
var tester = new TestBundleDownloader();
|
||||||
|
yield return tester.RuntimeTester();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CopyDirectory(string sourceDir, string targetDir)
|
||||||
|
{
|
||||||
|
// 检查源目录是否存在
|
||||||
|
if (!Directory.Exists(sourceDir))
|
||||||
|
{
|
||||||
|
throw new DirectoryNotFoundException($"源目录不存在: {sourceDir}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 创建目标目录(如果不存在)
|
||||||
|
Directory.CreateDirectory(targetDir);
|
||||||
|
|
||||||
|
// 拷贝所有文件
|
||||||
|
foreach (string file in Directory.GetFiles(sourceDir))
|
||||||
|
{
|
||||||
|
string fileName = Path.GetFileName(file);
|
||||||
|
string destFile = Path.Combine(targetDir, fileName);
|
||||||
|
File.Copy(file, destFile, true); // true 表示覆盖已存在文件
|
||||||
|
}
|
||||||
|
|
||||||
|
// 递归拷贝子目录
|
||||||
|
foreach (string subDir in Directory.GetDirectories(sourceDir))
|
||||||
|
{
|
||||||
|
string dirName = Path.GetFileName(subDir);
|
||||||
|
string newTargetDir = Path.Combine(targetDir, dirName);
|
||||||
|
CopyDirectory(subDir, newTargetDir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using YooAsset;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 测试远端文件下载
|
||||||
|
/// </summary>
|
||||||
|
public class TestBundleDownloader
|
||||||
|
{
|
||||||
|
public IEnumerator RuntimeTester()
|
||||||
|
{
|
||||||
|
ResourcePackage package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
|
||||||
|
Assert.IsNotNull(package);
|
||||||
|
|
||||||
|
var downloader = package.CreateResourceDownloader(10, 1);
|
||||||
|
if (downloader.TotalDownloadCount == 0)
|
||||||
|
{
|
||||||
|
Assert.Fail($"Test downloader not found any file !");
|
||||||
|
}
|
||||||
|
|
||||||
|
downloader.BeginDownload();
|
||||||
|
downloader.DownloadFinishCallback = (DownloaderFinishData data) =>
|
||||||
|
{
|
||||||
|
if (data.Succeed == false)
|
||||||
|
Assert.Fail($"Test downloader failed ! {downloader.Error}");
|
||||||
|
};
|
||||||
|
|
||||||
|
// 等待一秒
|
||||||
|
yield return new WaitForSeconds(1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 资源代码流程
|
||||||
|
* 远端文件下载(下载器)
|
||||||
|
CacheFileSystem::DownloadFileAsync()
|
||||||
|
{
|
||||||
|
//RemoteServices返回CDN文件路径
|
||||||
|
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
|
||||||
|
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
||||||
|
options.SetURL(mainURL, fallbackURL);
|
||||||
|
return new DownloadPackageBundleOperation(bundle, options);
|
||||||
|
}
|
||||||
|
*/
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6d1ca2e6dac603a459531fb09e61fd31
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using YooAsset;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 测试本地文件导入
|
||||||
|
/// </summary>
|
||||||
|
public class TestBundleImporter
|
||||||
|
{
|
||||||
|
public IEnumerator RuntimeTester()
|
||||||
|
{
|
||||||
|
ResourcePackage package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
|
||||||
|
Assert.IsNotNull(package);
|
||||||
|
|
||||||
|
string packageRoot = UnityEditor.EditorPrefs.GetString(T2_TestBuldinFileSystem.ASSET_BUNDLE_PACKAGE_ROOT_KEY);
|
||||||
|
DirectoryInfo packageDir = new DirectoryInfo(packageRoot);
|
||||||
|
string fileRoot = $"{packageDir.Parent.FullName}/OutputCache";
|
||||||
|
|
||||||
|
ImportFileInfo fileInfoA = new ImportFileInfo();
|
||||||
|
fileInfoA.FilePath = $"{fileRoot}/assets_samples_test_sample_testres3_import_prefab_importa.bundle.encrypt";
|
||||||
|
fileInfoA.BundleName = "assets_samples_test_sample_testres3_import_prefab_importa.bundle";
|
||||||
|
|
||||||
|
ImportFileInfo fileInfoB = new ImportFileInfo();
|
||||||
|
fileInfoB.FilePath = $"{fileRoot}/assets_samples_test_sample_testres3_import_prefab_importb.bundle.encrypt";
|
||||||
|
fileInfoB.BundleName = "assets_samples_test_sample_testres3_import_prefab_importb.bundle";
|
||||||
|
|
||||||
|
ImportFileInfo[] importInfos = { fileInfoA, fileInfoB };
|
||||||
|
var unpacker = package.CreateResourceImporter(importInfos, 10, 1);
|
||||||
|
Assert.AreEqual(unpacker.TotalDownloadCount, 2);
|
||||||
|
|
||||||
|
unpacker.BeginDownload();
|
||||||
|
yield return unpacker;
|
||||||
|
Assert.AreEqual(EOperationStatus.Succeed, unpacker.Status);
|
||||||
|
|
||||||
|
// 等待一秒
|
||||||
|
yield return new WaitForSeconds(1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 资源代码流程
|
||||||
|
* 本地文件导入(导入器)
|
||||||
|
BundleInfo::CreateDownloader()
|
||||||
|
{
|
||||||
|
options.ImportFilePath = _importFilePath;
|
||||||
|
return _cacheFileSystem.DownloadFileAsync(Bundle, options);
|
||||||
|
}
|
||||||
|
CacheFileSystem::DownloadFileAsync()
|
||||||
|
{
|
||||||
|
string mainURL = ConvertToWWWPath(options.ImportFilePath);
|
||||||
|
options.SetURL(mainURL, mainURL);
|
||||||
|
return new DownloadPackageBundleOperation(bundle, options);
|
||||||
|
}
|
||||||
|
*/
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 84a2bd73c962d0a4c9c3373ee8cd5380
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using YooAsset;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 测试边玩边下
|
||||||
|
/// </summary>
|
||||||
|
public class TestBundlePlaying
|
||||||
|
{
|
||||||
|
public IEnumerator RuntimeTester()
|
||||||
|
{
|
||||||
|
ResourcePackage package = YooAssets.GetPackage(TestDefine.AssetBundlePackageName);
|
||||||
|
Assert.IsNotNull(package);
|
||||||
|
|
||||||
|
if (package.IsNeedDownloadFromRemote("panel_a") == false)
|
||||||
|
{
|
||||||
|
Assert.Fail("Load bundle is already existed !");
|
||||||
|
}
|
||||||
|
if (package.IsNeedDownloadFromRemote("panel_b") == false)
|
||||||
|
{
|
||||||
|
Assert.Fail("Load bundle is already existed !");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 测试异步加载
|
||||||
|
{
|
||||||
|
var assetsHandle = package.LoadAssetAsync<GameObject>("panel_a");
|
||||||
|
yield return assetsHandle;
|
||||||
|
Assert.AreEqual(EOperationStatus.Succeed, assetsHandle.Status);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 测试同步加载
|
||||||
|
{
|
||||||
|
// 验证失败结果
|
||||||
|
UnityEngine.TestTools.LogAssert.ignoreFailingMessages = true;
|
||||||
|
var assetsHandle = package.LoadAssetSync<GameObject>("panel_b");
|
||||||
|
yield return assetsHandle;
|
||||||
|
Assert.AreEqual(EOperationStatus.Failed, assetsHandle.Status);
|
||||||
|
UnityEngine.TestTools.LogAssert.ignoreFailingMessages = false;
|
||||||
|
|
||||||
|
// 清理加载器
|
||||||
|
assetsHandle.Release();
|
||||||
|
package.UnloadUnusedAssetsAsync();
|
||||||
|
|
||||||
|
// 验证成功结果
|
||||||
|
yield return new WaitForSeconds(1f);
|
||||||
|
assetsHandle = package.LoadAssetSync<GameObject>("panel_b");
|
||||||
|
yield return assetsHandle;
|
||||||
|
Assert.AreEqual(EOperationStatus.Succeed, assetsHandle.Status);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 等待一秒
|
||||||
|
yield return new WaitForSeconds(1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 资源代码流程
|
||||||
|
* 远端文件下载(加载器)
|
||||||
|
CacheFileSystem::LoadBundleFile()
|
||||||
|
{
|
||||||
|
_cacheFileSystem.LoadBundleFile(bundle);
|
||||||
|
}
|
||||||
|
CacheFileSystem::LoadAssetBundleOperation()
|
||||||
|
{
|
||||||
|
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue, 60);
|
||||||
|
_cacheFileSystem.DownloadFileAsync(_bundle, options);
|
||||||
|
}
|
||||||
|
CacheFileSystem::DownloadFileAsync()
|
||||||
|
{
|
||||||
|
//RemoteServices返回CDN文件路径
|
||||||
|
string mainURL = RemoteServices.GetRemoteMainURL(bundle.FileName);
|
||||||
|
string fallbackURL = RemoteServices.GetRemoteFallbackURL(bundle.FileName);
|
||||||
|
options.SetURL(mainURL, fallbackURL);
|
||||||
|
return new DownloadPackageBundleOperation(bundle, options);
|
||||||
|
}
|
||||||
|
*/
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6db248f26f2eaaa4282a7bbdf709c321
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
public class TestDefine
|
public class TestDefine
|
||||||
{
|
{
|
||||||
public const string AssetBundlePackageName = "AssetBundlePackage";
|
public const string AssetBundlePackageName = "AssetBundleTestPackage";
|
||||||
public const string RawBundlePackageName = "RawBundlePackage";
|
public const string RawBundlePackageName = "RawBundleTestPackage";
|
||||||
}
|
}
|
||||||
@@ -35,6 +35,7 @@ public class TestLoadPanel
|
|||||||
|
|
||||||
Assert.IsNotNull(instantiateOp.Result);
|
Assert.IsNotNull(instantiateOp.Result);
|
||||||
TestLogger.Log(this, instantiateOp.Result.name);
|
TestLogger.Log(this, instantiateOp.Result.name);
|
||||||
|
GameObject.Destroy(instantiateOp.Result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,6 +42,7 @@ public class TestLoadPrefab
|
|||||||
|
|
||||||
Assert.IsNotNull(instantiateOp.Result);
|
Assert.IsNotNull(instantiateOp.Result);
|
||||||
TestLogger.Log(this, instantiateOp.Result.name);
|
TestLogger.Log(this, instantiateOp.Result.name);
|
||||||
|
GameObject.Destroy(instantiateOp.Result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 同步加载指定预制体
|
// 同步加载指定预制体
|
||||||
@@ -57,6 +58,7 @@ public class TestLoadPrefab
|
|||||||
|
|
||||||
Assert.IsNotNull(instantiateOp.Result);
|
Assert.IsNotNull(instantiateOp.Result);
|
||||||
TestLogger.Log(this, instantiateOp.Result.name);
|
TestLogger.Log(this, instantiateOp.Result.name);
|
||||||
|
GameObject.Destroy(instantiateOp.Result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,10 +36,6 @@ SpriteAtlas:
|
|||||||
bindAsDefault: 1
|
bindAsDefault: 1
|
||||||
isAtlasV2: 0
|
isAtlasV2: 0
|
||||||
cachedData: {fileID: 0}
|
cachedData: {fileID: 0}
|
||||||
packedSpriteRenderDataKeys:
|
|
||||||
- 379c45e0c5ba5e54e8df03f52e4c7680: 21300000
|
|
||||||
- fcab35236e33438448805a9211b0cc19: 21300000
|
|
||||||
- 3b8db7241fc8ff54e9dea6fc64cfd7e5: 21300000
|
|
||||||
m_MasterAtlas: {fileID: 0}
|
m_MasterAtlas: {fileID: 0}
|
||||||
m_PackedSprites:
|
m_PackedSprites:
|
||||||
- {fileID: 21300000, guid: 379c45e0c5ba5e54e8df03f52e4c7680, type: 3}
|
- {fileID: 21300000, guid: 379c45e0c5ba5e54e8df03f52e4c7680, type: 3}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8125b69e669e19e41a4c67896f1f98b0
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 80285bcc262cc36488d96950c2a07504
|
||||||
|
TextScriptImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 35f454fb80a715047bcf0ce30c7c4f18
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user