mirror of https://github.com/tuyoogame/YooAsset
update file system
parent
e4d69d869b
commit
0cdcfe7f52
|
@ -153,7 +153,10 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
var downloader = DownloadCenter.DownloadFileAsync(bundle, param);
|
var downloader = DownloadCenter.DownloadFileAsync(bundle, param);
|
||||||
downloader.Reference(); //增加下载器的引用计数
|
downloader.Reference(); //增加下载器的引用计数
|
||||||
return downloader;
|
|
||||||
|
// 注意:将下载器进行包裹,可以避免父类任务终止的时候,连带子任务里的下载器也一起被终止!
|
||||||
|
var wrapper = new DownloadFileWrapper(downloader);
|
||||||
|
return wrapper;
|
||||||
}
|
}
|
||||||
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
|
||||||
{
|
{
|
||||||
|
|
|
@ -54,18 +54,19 @@ namespace YooAsset
|
||||||
|
|
||||||
if (_steps == ESteps.DownloadFile)
|
if (_steps == ESteps.DownloadFile)
|
||||||
{
|
{
|
||||||
// 注意:下载的异步任务由管理器驱动
|
|
||||||
// 注意:不加到子任务列表里,防止Abort的时候将下载器直接关闭!
|
|
||||||
// 注意:边玩边下下载器引用计数没有Release
|
// 注意:边玩边下下载器引用计数没有Release
|
||||||
if (_downloadFileOp == null)
|
if (_downloadFileOp == null)
|
||||||
{
|
{
|
||||||
DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
|
DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
|
||||||
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, downloadParam);
|
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, downloadParam);
|
||||||
|
_downloadFileOp.StartOperation();
|
||||||
|
AddChildOperation(_downloadFileOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsWaitForAsyncComplete)
|
if (IsWaitForAsyncComplete)
|
||||||
_downloadFileOp.WaitForAsyncComplete();
|
_downloadFileOp.WaitForAsyncComplete();
|
||||||
|
|
||||||
|
_downloadFileOp.UpdateOperation();
|
||||||
DownloadProgress = _downloadFileOp.DownloadProgress;
|
DownloadProgress = _downloadFileOp.DownloadProgress;
|
||||||
DownloadedBytes = _downloadFileOp.DownloadedBytes;
|
DownloadedBytes = _downloadFileOp.DownloadedBytes;
|
||||||
if (_downloadFileOp.IsDone == false)
|
if (_downloadFileOp.IsDone == false)
|
||||||
|
@ -271,18 +272,19 @@ namespace YooAsset
|
||||||
|
|
||||||
if (_steps == ESteps.DownloadFile)
|
if (_steps == ESteps.DownloadFile)
|
||||||
{
|
{
|
||||||
// 注意:下载的异步任务由管理器驱动
|
|
||||||
// 注意:不加到子任务列表里,防止Abort的时候将下载器直接关闭!
|
|
||||||
// 注意:边玩边下下载器引用计数没有Release
|
// 注意:边玩边下下载器引用计数没有Release
|
||||||
if (_downloadFileOp == null)
|
if (_downloadFileOp == null)
|
||||||
{
|
{
|
||||||
DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
|
DownloadParam downloadParam = new DownloadParam(int.MaxValue, 60);
|
||||||
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, downloadParam);
|
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, downloadParam);
|
||||||
|
_downloadFileOp.StartOperation();
|
||||||
|
AddChildOperation(_downloadFileOp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsWaitForAsyncComplete)
|
if (IsWaitForAsyncComplete)
|
||||||
_downloadFileOp.WaitForAsyncComplete();
|
_downloadFileOp.WaitForAsyncComplete();
|
||||||
|
|
||||||
|
_downloadFileOp.UpdateOperation();
|
||||||
DownloadProgress = _downloadFileOp.DownloadProgress;
|
DownloadProgress = _downloadFileOp.DownloadProgress;
|
||||||
DownloadedBytes = _downloadFileOp.DownloadedBytes;
|
DownloadedBytes = _downloadFileOp.DownloadedBytes;
|
||||||
if (_downloadFileOp.IsDone == false)
|
if (_downloadFileOp.IsDone == false)
|
||||||
|
|
|
@ -166,12 +166,6 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
internal override void InternalWaitForAsyncComplete()
|
internal override void InternalWaitForAsyncComplete()
|
||||||
{
|
{
|
||||||
//TODO 防止下载器挂起陷入无限死循环!
|
|
||||||
if (_steps == ESteps.None)
|
|
||||||
{
|
|
||||||
InternalStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
//TODO 如果是导入或解压本地文件,执行等待完毕
|
//TODO 如果是导入或解压本地文件,执行等待完毕
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using System.Collections.Generic;
|
using System.IO;
|
||||||
using System.IO;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
using UnityEngine.Networking;
|
||||||
|
|
||||||
|
@ -186,12 +185,6 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
internal override void InternalWaitForAsyncComplete()
|
internal override void InternalWaitForAsyncComplete()
|
||||||
{
|
{
|
||||||
//TODO 防止下载器挂起陷入无限死循环!
|
|
||||||
if (_steps == ESteps.None)
|
|
||||||
{
|
|
||||||
InternalStart();
|
|
||||||
}
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
//TODO 如果是导入或解压本地文件,执行等待完毕
|
//TODO 如果是导入或解压本地文件,执行等待完毕
|
||||||
|
|
|
@ -34,11 +34,19 @@ namespace YooAsset
|
||||||
DownloadedBytes = 0;
|
DownloadedBytes = 0;
|
||||||
DownloadProgress = 0;
|
DownloadProgress = 0;
|
||||||
}
|
}
|
||||||
public void Release()
|
|
||||||
|
/// <summary>
|
||||||
|
/// 减少引用计数
|
||||||
|
/// </summary>
|
||||||
|
public virtual void Release()
|
||||||
{
|
{
|
||||||
RefCount--;
|
RefCount--;
|
||||||
}
|
}
|
||||||
public void Reference()
|
|
||||||
|
/// <summary>
|
||||||
|
/// 增加引用计数
|
||||||
|
/// </summary>
|
||||||
|
public virtual void Reference()
|
||||||
{
|
{
|
||||||
RefCount++;
|
RefCount++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Networking;
|
|
||||||
|
|
||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
|
||||||
|
namespace YooAsset
|
||||||
|
{
|
||||||
|
internal class DownloadFileWrapper : FSDownloadFileOperation
|
||||||
|
{
|
||||||
|
private enum ESteps
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Download,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly FSDownloadFileOperation _downloadFileOp;
|
||||||
|
private ESteps _steps = ESteps.None;
|
||||||
|
|
||||||
|
internal DownloadFileWrapper(FSDownloadFileOperation downloadFileOp) : base(downloadFileOp.Bundle)
|
||||||
|
{
|
||||||
|
_downloadFileOp = downloadFileOp;
|
||||||
|
}
|
||||||
|
internal override void InternalStart()
|
||||||
|
{
|
||||||
|
_steps = ESteps.Download;
|
||||||
|
}
|
||||||
|
internal override void InternalUpdate()
|
||||||
|
{
|
||||||
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (_steps == ESteps.Download)
|
||||||
|
{
|
||||||
|
if (IsWaitForAsyncComplete)
|
||||||
|
_downloadFileOp.WaitForAsyncComplete();
|
||||||
|
|
||||||
|
if (_downloadFileOp.Status == EOperationStatus.None)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_downloadFileOp.UpdateOperation();
|
||||||
|
Progress = _downloadFileOp.Progress;
|
||||||
|
DownloadedBytes = _downloadFileOp.DownloadedBytes;
|
||||||
|
DownloadProgress = _downloadFileOp.DownloadProgress;
|
||||||
|
if (_downloadFileOp.IsDone == false)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
Status = _downloadFileOp.Status;
|
||||||
|
Error = _downloadFileOp.Error;
|
||||||
|
HttpCode = _downloadFileOp.HttpCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
internal override void InternalWaitForAsyncComplete()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
if (ExecuteWhileDone())
|
||||||
|
{
|
||||||
|
_steps = ESteps.Done;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Release()
|
||||||
|
{
|
||||||
|
_downloadFileOp.Release();
|
||||||
|
}
|
||||||
|
public override void Reference()
|
||||||
|
{
|
||||||
|
_downloadFileOp.Reference();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8088863fc7dfbd441bc897380cd7b97f
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -113,7 +113,6 @@ namespace YooAsset
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置包裹名称
|
/// 设置包裹名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="packageName"></param>
|
|
||||||
internal void SetPackageName(string packageName)
|
internal void SetPackageName(string packageName)
|
||||||
{
|
{
|
||||||
_packageName = packageName;
|
_packageName = packageName;
|
||||||
|
@ -224,6 +223,13 @@ namespace YooAsset
|
||||||
if (IsDone)
|
if (IsDone)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
//TODO 防止异步操作被挂起陷入无限死循环!
|
||||||
|
// 例如:文件解压任务或者文件导入任务!
|
||||||
|
if (Status == EOperationStatus.None)
|
||||||
|
{
|
||||||
|
StartOperation();
|
||||||
|
}
|
||||||
|
|
||||||
IsWaitForAsyncComplete = true;
|
IsWaitForAsyncComplete = true;
|
||||||
InternalWaitForAsyncComplete();
|
InternalWaitForAsyncComplete();
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ namespace YooAsset
|
||||||
/// 当开始下载某个文件
|
/// 当开始下载某个文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
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, int timeout)
|
||||||
{
|
{
|
||||||
|
@ -204,6 +204,9 @@ 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, _timeout);
|
||||||
|
downloader.StartOperation();
|
||||||
|
this.AddChildOperation(downloader);
|
||||||
|
|
||||||
_downloaders.Add(downloader);
|
_downloaders.Add(downloader);
|
||||||
_bundleInfoList.RemoveAt(index);
|
_bundleInfoList.RemoveAt(index);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue