style : resource manager

pull/342/head
何冠峰 2024-08-13 10:10:43 +08:00
parent e5f5241879
commit 22cb3c3942
3 changed files with 12 additions and 14 deletions

View File

@ -23,7 +23,7 @@ namespace YooAsset
add add
{ {
if (IsValidWithWarning == false) if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(SceneHandle)} is invalid"); throw new System.Exception($"{nameof(SceneHandle)} is invalid !");
if (Provider.IsDone) if (Provider.IsDone)
value.Invoke(this); value.Invoke(this);
else else
@ -32,7 +32,7 @@ namespace YooAsset
remove remove
{ {
if (IsValidWithWarning == false) if (IsValidWithWarning == false)
throw new System.Exception($"{nameof(SceneHandle)} is invalid"); throw new System.Exception($"{nameof(SceneHandle)} is invalid !");
_callback -= value; _callback -= value;
} }
} }
@ -168,13 +168,12 @@ namespace YooAsset
} }
// 卸载子场景 // 卸载子场景
// 注意:如果场景正在加载过程,必须等待加载完成后才可以卸载该场景。
{ {
var operation = new UnloadSceneOperation(Provider); var operation = new UnloadSceneOperation(Provider);
OperationSystem.StartOperation(packageName, operation); OperationSystem.StartOperation(packageName, operation);
return operation; return operation;
} }
} }
} }
} }

View File

@ -14,14 +14,13 @@ namespace YooAsset
CheckError, CheckError,
PrepareDone, PrepareDone,
UnLoadScene, UnLoadScene,
Checking,
Done, Done,
} }
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
private readonly string _error; private readonly string _error;
private readonly ProviderOperation _provider; private readonly ProviderOperation _provider;
private AsyncOperation _asyncOp; private AsyncOperation _asyncOp = null;
internal UnloadSceneOperation(string error) internal UnloadSceneOperation(string error)
{ {
@ -95,17 +94,17 @@ namespace YooAsset
} }
if (_steps == ESteps.UnLoadScene) if (_steps == ESteps.UnLoadScene)
{
if (_asyncOp == null)
{ {
_asyncOp = SceneManager.UnloadSceneAsync(_provider.SceneObject); _asyncOp = SceneManager.UnloadSceneAsync(_provider.SceneObject);
_provider.ResourceMgr.UnloadSubScene(_provider.SceneName); _provider.ResourceMgr.UnloadSubScene(_provider.SceneName);
_steps = ESteps.Checking;
} }
if (_steps == ESteps.Checking)
{
Progress = _asyncOp.progress; Progress = _asyncOp.progress;
if (_asyncOp.isDone == false) if (_asyncOp.isDone == false)
return; return;
_provider.ResourceMgr.TryUnloadUnusedAsset(_provider.MainAssetInfo); _provider.ResourceMgr.TryUnloadUnusedAsset(_provider.MainAssetInfo);
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;

View File

@ -130,7 +130,7 @@ namespace YooAsset
long downloadBytes = _cachedDownloadBytes; long downloadBytes = _cachedDownloadBytes;
foreach (var downloader in _downloaders) foreach (var downloader in _downloaders)
{ {
downloadBytes += (long)downloader.DownloadedBytes; downloadBytes += downloader.DownloadedBytes;
if (downloader.IsDone == false) if (downloader.IsDone == false)
continue; continue;
@ -145,7 +145,7 @@ namespace YooAsset
// 下载成功 // 下载成功
_removeList.Add(downloader); _removeList.Add(downloader);
_cachedDownloadCount++; _cachedDownloadCount++;
_cachedDownloadBytes += (long)downloader.DownloadedBytes; _cachedDownloadBytes += downloader.DownloadedBytes;
} }
// 移除已经完成的下载器(无论成功或失败) // 移除已经完成的下载器(无论成功或失败)