mirror of https://github.com/tuyoogame/YooAsset
update asset system
parent
ac88fd5cf6
commit
824d1c1501
|
@ -75,7 +75,7 @@ namespace YooAsset
|
|||
{
|
||||
if (IsValidWithWarning == false)
|
||||
return 0;
|
||||
return Provider.GetLoadProgress();
|
||||
return Provider.Progress;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -89,6 +89,8 @@ namespace YooAsset
|
|||
// 2. 检测服务器下载结果
|
||||
if (_steps == ESteps.CheckDownload)
|
||||
{
|
||||
DownloadProgress = _downloader.DownloadProgress;
|
||||
DownloadedBytes = _downloader.DownloadedBytes;
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
|
@ -116,6 +118,8 @@ namespace YooAsset
|
|||
// 4.检测内置文件解压结果
|
||||
if (_steps == ESteps.CheckUnpack)
|
||||
{
|
||||
DownloadProgress = _unpacker.DownloadProgress;
|
||||
DownloadedBytes = _unpacker.DownloadedBytes;
|
||||
if (_unpacker.IsDone() == false)
|
||||
return;
|
||||
|
||||
|
@ -146,6 +150,10 @@ namespace YooAsset
|
|||
}
|
||||
#endif
|
||||
|
||||
// 设置下载进度
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize;
|
||||
|
||||
// Load assetBundle file
|
||||
var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod;
|
||||
if (loadMethod == EBundleLoadMethod.Normal)
|
||||
|
@ -307,36 +315,5 @@ namespace YooAsset
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取下载报告
|
||||
/// </summary>
|
||||
public override DownloadReport GetDownloadReport()
|
||||
{
|
||||
if (_downloader != null)
|
||||
{
|
||||
DownloadReport report = new DownloadReport();
|
||||
report.Progress = _downloader.DownloadProgress;
|
||||
report.TotalSize = MainBundleInfo.Bundle.FileSize;
|
||||
report.DownloadedBytes = (long)_downloader.DownloadedBytes;
|
||||
return report;
|
||||
}
|
||||
else if(_unpacker != null)
|
||||
{
|
||||
DownloadReport report = new DownloadReport();
|
||||
report.Progress = _unpacker.DownloadProgress;
|
||||
report.TotalSize = MainBundleInfo.Bundle.FileSize;
|
||||
report.DownloadedBytes = (long)_unpacker.DownloadedBytes;
|
||||
return report;
|
||||
}
|
||||
else
|
||||
{
|
||||
DownloadReport report = new DownloadReport();
|
||||
report.Progress = 1f;
|
||||
report.TotalSize = MainBundleInfo.Bundle.FileSize;
|
||||
report.DownloadedBytes = MainBundleInfo.Bundle.FileSize;
|
||||
return report;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -76,6 +76,8 @@ namespace YooAsset
|
|||
// 2. 检测服务器下载结果
|
||||
if (_steps == ESteps.CheckDownload)
|
||||
{
|
||||
DownloadProgress = _downloader.DownloadProgress;
|
||||
DownloadedBytes = _downloader.DownloadedBytes;
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
|
@ -106,6 +108,10 @@ namespace YooAsset
|
|||
}
|
||||
#endif
|
||||
|
||||
// 设置下载进度
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize;
|
||||
|
||||
// Load assetBundle file
|
||||
var loadMethod = (EBundleLoadMethod)MainBundleInfo.Bundle.LoadMethod;
|
||||
if (loadMethod == EBundleLoadMethod.Normal)
|
||||
|
@ -171,6 +177,8 @@ namespace YooAsset
|
|||
// 6. 检测AssetBundle加载结果
|
||||
if (_steps == ESteps.CheckLoadWebFile)
|
||||
{
|
||||
DownloadProgress = _webRequest.downloadProgress;
|
||||
DownloadedBytes = _webRequest.downloadedBytes;
|
||||
if (_webRequest.isDone == false)
|
||||
return;
|
||||
|
||||
|
@ -226,36 +234,5 @@ namespace YooAsset
|
|||
YooLogger.Error($"WebGL platform not support {nameof(WaitForAsyncComplete)} ! Use the async load method instead of the sync load method !");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取下载报告
|
||||
/// </summary>
|
||||
public override DownloadReport GetDownloadReport()
|
||||
{
|
||||
if (_downloader != null)
|
||||
{
|
||||
DownloadReport report = new DownloadReport();
|
||||
report.Progress = _downloader.DownloadProgress;
|
||||
report.TotalSize = MainBundleInfo.Bundle.FileSize;
|
||||
report.DownloadedBytes = (long)_downloader.DownloadedBytes;
|
||||
return report;
|
||||
}
|
||||
else if (_webRequest != null)
|
||||
{
|
||||
DownloadReport report = new DownloadReport();
|
||||
report.Progress = _webRequest.downloadProgress;
|
||||
report.TotalSize = MainBundleInfo.Bundle.FileSize;
|
||||
report.DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||
return report;
|
||||
}
|
||||
else
|
||||
{
|
||||
DownloadReport report = new DownloadReport();
|
||||
report.Progress = 1f;
|
||||
report.TotalSize = MainBundleInfo.Bundle.FileSize;
|
||||
report.DownloadedBytes = MainBundleInfo.Bundle.FileSize;
|
||||
return report;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,6 +47,8 @@ namespace YooAsset
|
|||
private readonly List<ProviderBase> _providers = new List<ProviderBase>(100);
|
||||
internal AssetBundle CacheBundle { set; get; }
|
||||
internal string FileLoadPath { set; get; }
|
||||
internal float DownloadProgress { set; get; }
|
||||
internal ulong DownloadedBytes { set; get; }
|
||||
|
||||
|
||||
public BundleLoaderBase(AssetSystemImpl impl, BundleInfo bundleInfo)
|
||||
|
@ -164,10 +166,5 @@ namespace YooAsset
|
|||
/// 主线程等待异步操作完毕
|
||||
/// </summary>
|
||||
public abstract void WaitForAsyncComplete();
|
||||
|
||||
/// <summary>
|
||||
/// 获取下载报告
|
||||
/// </summary>
|
||||
public abstract DownloadReport GetDownloadReport();
|
||||
}
|
||||
}
|
|
@ -72,6 +72,8 @@ namespace YooAsset
|
|||
// 2. 检测下载结果
|
||||
if (_steps == ESteps.CheckDownload)
|
||||
{
|
||||
DownloadProgress = _downloader.DownloadProgress;
|
||||
DownloadedBytes = _downloader.DownloadedBytes;
|
||||
if (_downloader.IsDone() == false)
|
||||
return;
|
||||
|
||||
|
@ -99,6 +101,8 @@ namespace YooAsset
|
|||
// 4. 检测解压结果
|
||||
if (_steps == ESteps.CheckUnpack)
|
||||
{
|
||||
DownloadProgress = _unpacker.DownloadProgress;
|
||||
DownloadedBytes = _unpacker.DownloadedBytes;
|
||||
if (_unpacker.IsDone() == false)
|
||||
return;
|
||||
|
||||
|
@ -117,6 +121,10 @@ namespace YooAsset
|
|||
// 5. 检测结果
|
||||
if (_steps == ESteps.CheckFile)
|
||||
{
|
||||
// 设置下载进度
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = (ulong)MainBundleInfo.Bundle.FileSize;
|
||||
|
||||
_steps = ESteps.Done;
|
||||
if (File.Exists(FileLoadPath))
|
||||
{
|
||||
|
@ -167,36 +175,5 @@ namespace YooAsset
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取下载报告
|
||||
/// </summary>
|
||||
public override DownloadReport GetDownloadReport()
|
||||
{
|
||||
if (_downloader != null)
|
||||
{
|
||||
DownloadReport report = new DownloadReport();
|
||||
report.Progress = _downloader.DownloadProgress;
|
||||
report.TotalSize = MainBundleInfo.Bundle.FileSize;
|
||||
report.DownloadedBytes = (long)_downloader.DownloadedBytes;
|
||||
return report;
|
||||
}
|
||||
else if (_unpacker != null)
|
||||
{
|
||||
DownloadReport report = new DownloadReport();
|
||||
report.Progress = _unpacker.DownloadProgress;
|
||||
report.TotalSize = MainBundleInfo.Bundle.FileSize;
|
||||
report.DownloadedBytes = (long)_unpacker.DownloadedBytes;
|
||||
return report;
|
||||
}
|
||||
else
|
||||
{
|
||||
DownloadReport report = new DownloadReport();
|
||||
report.Progress = 1f;
|
||||
report.TotalSize = MainBundleInfo.Bundle.FileSize;
|
||||
report.DownloadedBytes = MainBundleInfo.Bundle.FileSize;
|
||||
return report;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -90,6 +90,7 @@ namespace YooAsset
|
|||
// 3. 检测加载结果
|
||||
if (Status == EStatus.Checking)
|
||||
{
|
||||
Progress = _cacheRequest.progress;
|
||||
if (_cacheRequest != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
|
@ -118,11 +119,5 @@ namespace YooAsset
|
|||
InvokeCompletion();
|
||||
}
|
||||
}
|
||||
public override float GetLoadProgress()
|
||||
{
|
||||
if (_cacheRequest == null)
|
||||
return 0;
|
||||
return _cacheRequest.progress;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -40,12 +40,13 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public override DownloadReport GetDownloadReport()
|
||||
{
|
||||
DownloadReport result = OwnerBundle.GetDownloadReport();
|
||||
foreach (var bundleLoader in DependBundleGroup.DependBundles)
|
||||
DownloadReport result = new DownloadReport();
|
||||
result.TotalSize = (ulong)OwnerBundle.MainBundleInfo.Bundle.FileSize;
|
||||
result.DownloadedBytes = OwnerBundle.DownloadedBytes;
|
||||
foreach (var dependBundle in DependBundleGroup.DependBundles)
|
||||
{
|
||||
var report = bundleLoader.GetDownloadReport();
|
||||
result.TotalSize += report.TotalSize;
|
||||
result.DownloadedBytes += report.DownloadedBytes;
|
||||
result.TotalSize += (ulong)dependBundle.MainBundleInfo.Bundle.FileSize;
|
||||
result.DownloadedBytes += dependBundle.DownloadedBytes;
|
||||
}
|
||||
result.Progress = result.DownloadedBytes / result.TotalSize;
|
||||
return result;
|
||||
|
|
|
@ -84,6 +84,7 @@ namespace YooAsset
|
|||
// 3. 检测加载结果
|
||||
if (Status == EStatus.Checking)
|
||||
{
|
||||
Progress = _asyncOp.progress;
|
||||
if (_asyncOp.isDone)
|
||||
{
|
||||
if (SceneObject.IsValid() && _activateOnLoad)
|
||||
|
@ -99,11 +100,5 @@ namespace YooAsset
|
|||
}
|
||||
}
|
||||
}
|
||||
public override float GetLoadProgress()
|
||||
{
|
||||
if (_asyncOp == null)
|
||||
return 0;
|
||||
return _asyncOp.progress;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -79,6 +79,7 @@ namespace YooAsset
|
|||
// 3. 检测加载结果
|
||||
if (Status == EStatus.Checking)
|
||||
{
|
||||
Progress = _cacheRequest.progress;
|
||||
if (_cacheRequest != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
|
@ -107,11 +108,5 @@ namespace YooAsset
|
|||
InvokeCompletion();
|
||||
}
|
||||
}
|
||||
public override float GetLoadProgress()
|
||||
{
|
||||
if (_cacheRequest == null)
|
||||
return 0;
|
||||
return _cacheRequest.progress;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -52,6 +52,7 @@ namespace YooAsset
|
|||
// 2. 检测加载结果
|
||||
if (Status == EStatus.Checking)
|
||||
{
|
||||
Progress = _asyncOp.progress;
|
||||
if (_asyncOp.isDone)
|
||||
{
|
||||
if (SceneObject.IsValid() && _activateOnLoad)
|
||||
|
@ -68,11 +69,5 @@ namespace YooAsset
|
|||
}
|
||||
#endif
|
||||
}
|
||||
public override float GetLoadProgress()
|
||||
{
|
||||
if (_asyncOp == null)
|
||||
return 0;
|
||||
return _asyncOp.progress;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -63,6 +63,11 @@ namespace YooAsset
|
|||
/// </summary>
|
||||
public string LastError { protected set; get; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 加载进度
|
||||
/// </summary>
|
||||
public float Progress { protected set; get; } = 0f;
|
||||
|
||||
/// <summary>
|
||||
/// 引用计数
|
||||
/// </summary>
|
||||
|
@ -109,17 +114,6 @@ namespace YooAsset
|
|||
IsDestroyed = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取加载进度
|
||||
/// </summary>
|
||||
public virtual float GetLoadProgress()
|
||||
{
|
||||
if (IsDone)
|
||||
return 1f;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取下载进度
|
||||
/// </summary>
|
||||
|
@ -227,6 +221,9 @@ namespace YooAsset
|
|||
private TaskCompletionSource<object> _taskCompletionSource;
|
||||
protected void InvokeCompletion()
|
||||
{
|
||||
// 进度百分百完成
|
||||
Progress = 1f;
|
||||
|
||||
// 注意:创建临时列表是为了防止外部逻辑在回调函数内创建或者释放资源句柄。
|
||||
List<OperationHandleBase> tempers = new List<OperationHandleBase>(_handles);
|
||||
foreach (var hande in tempers)
|
||||
|
|
|
@ -11,17 +11,17 @@ namespace YooAsset
|
|||
/// <summary>
|
||||
/// 需要下载的总字节数
|
||||
/// </summary>
|
||||
public long TotalSize;
|
||||
public ulong TotalSize;
|
||||
|
||||
/// <summary>
|
||||
/// 已经下载的字节数
|
||||
/// </summary>
|
||||
public long DownloadedBytes;
|
||||
public ulong DownloadedBytes;
|
||||
|
||||
public static DownloadReport CreateDefaultReport()
|
||||
{
|
||||
DownloadReport report = new DownloadReport();
|
||||
report.Progress = 1f;
|
||||
report.Progress = 0f;
|
||||
report.TotalSize = 0;
|
||||
report.DownloadedBytes = 0;
|
||||
return report;
|
||||
|
|
Loading…
Reference in New Issue