diff --git a/Assets/YooAsset/Runtime/ResourceManager/Handle/SceneHandle.cs b/Assets/YooAsset/Runtime/ResourceManager/Handle/SceneHandle.cs index b26914f..7b093ac 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Handle/SceneHandle.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Handle/SceneHandle.cs @@ -23,7 +23,7 @@ namespace YooAsset add { if (IsValidWithWarning == false) - throw new System.Exception($"{nameof(SceneHandle)} is invalid"); + throw new System.Exception($"{nameof(SceneHandle)} is invalid !"); if (Provider.IsDone) value.Invoke(this); else @@ -32,7 +32,7 @@ namespace YooAsset remove { if (IsValidWithWarning == false) - throw new System.Exception($"{nameof(SceneHandle)} is invalid"); + throw new System.Exception($"{nameof(SceneHandle)} is invalid !"); _callback -= value; } } @@ -168,13 +168,12 @@ namespace YooAsset } // 卸载子场景 + // 注意:如果场景正在加载过程,必须等待加载完成后才可以卸载该场景。 { var operation = new UnloadSceneOperation(Provider); OperationSystem.StartOperation(packageName, operation); return operation; } } - - } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadSceneOperation.cs b/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadSceneOperation.cs index c367bf5..a815cf2 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadSceneOperation.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Operation/UnloadSceneOperation.cs @@ -14,14 +14,13 @@ namespace YooAsset CheckError, PrepareDone, UnLoadScene, - Checking, Done, } private ESteps _steps = ESteps.None; private readonly string _error; private readonly ProviderOperation _provider; - private AsyncOperation _asyncOp; + private AsyncOperation _asyncOp = null; internal UnloadSceneOperation(string error) { @@ -96,16 +95,16 @@ namespace YooAsset if (_steps == ESteps.UnLoadScene) { - _asyncOp = SceneManager.UnloadSceneAsync(_provider.SceneObject); - _provider.ResourceMgr.UnloadSubScene(_provider.SceneName); - _steps = ESteps.Checking; - } + if (_asyncOp == null) + { + _asyncOp = SceneManager.UnloadSceneAsync(_provider.SceneObject); + _provider.ResourceMgr.UnloadSubScene(_provider.SceneName); + } - if (_steps == ESteps.Checking) - { Progress = _asyncOp.progress; if (_asyncOp.isDone == false) return; + _provider.ResourceMgr.TryUnloadUnusedAsset(_provider.MainAssetInfo); _steps = ESteps.Done; Status = EOperationStatus.Succeed; diff --git a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs index a2cee5f..f713f1e 100644 --- a/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs +++ b/Assets/YooAsset/Runtime/ResourcePackage/Operation/DownloaderOperation.cs @@ -130,7 +130,7 @@ namespace YooAsset long downloadBytes = _cachedDownloadBytes; foreach (var downloader in _downloaders) { - downloadBytes += (long)downloader.DownloadedBytes; + downloadBytes += downloader.DownloadedBytes; if (downloader.IsDone == false) continue; @@ -145,7 +145,7 @@ namespace YooAsset // 下载成功 _removeList.Add(downloader); _cachedDownloadCount++; - _cachedDownloadBytes += (long)downloader.DownloadedBytes; + _cachedDownloadBytes += downloader.DownloadedBytes; } // 移除已经完成的下载器(无论成功或失败)