diff --git a/Assets/YooAsset/Runtime/ResourceManager/Handle/SceneHandle.cs b/Assets/YooAsset/Runtime/ResourceManager/Handle/SceneHandle.cs index 156d820..bdeaab3 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Handle/SceneHandle.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Handle/SceneHandle.cs @@ -100,29 +100,21 @@ namespace YooAsset if (IsValidWithWarning == false) return false; - // 注意:当场景挂起操作执行之后无法中途取消! - if (SceneObject.IsValid()) + if (Provider is DatabaseSceneProvider) { - if (Provider is DatabaseSceneProvider) - { - var temp = Provider as DatabaseSceneProvider; - return temp.UnSuspendLoad(); - } - else if (Provider is BundledSceneProvider) - { - var temp = Provider as BundledSceneProvider; - return temp.UnSuspendLoad(); - } - else - { - throw new System.NotImplementedException(); - } + var provider = Provider as DatabaseSceneProvider; + provider.UnSuspendLoad(); + } + else if (Provider is BundledSceneProvider) + { + var provider = Provider as BundledSceneProvider; + provider.UnSuspendLoad(); } else { - YooLogger.Warning($"Scene is invalid : {SceneObject.name}"); - return false; + throw new System.NotImplementedException(); } + return true; } /// diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSceneProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSceneProvider.cs index 1666c64..eda5771 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSceneProvider.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSceneProvider.cs @@ -9,14 +9,14 @@ namespace YooAsset internal sealed class BundledSceneProvider : ProviderBase { public readonly LoadSceneMode SceneMode; - private readonly bool _suspendLoad; private AsyncOperation _asyncOperation; + private bool _suspendLoadMode; public BundledSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo) { SceneMode = sceneMode; SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath); - _suspendLoad = suspendLoad; + _suspendLoadMode = suspendLoad; } internal override void InternalOnStart() { @@ -80,7 +80,7 @@ namespace YooAsset _asyncOperation = SceneManager.LoadSceneAsync(MainAssetInfo.AssetPath, SceneMode); if (_asyncOperation != null) { - _asyncOperation.allowSceneActivation = !_suspendLoad; + _asyncOperation.allowSceneActivation = !_suspendLoadMode; _asyncOperation.priority = 100; SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1); _steps = ESteps.Checking; @@ -106,6 +106,13 @@ namespace YooAsset } else { + // 注意:在业务层中途可以取消挂起 + if (_asyncOperation.allowSceneActivation == false) + { + if (_suspendLoadMode == false) + _asyncOperation.allowSceneActivation = true; + } + Progress = _asyncOperation.progress; if (_asyncOperation.isDone == false) return; @@ -128,13 +135,12 @@ namespace YooAsset /// /// 解除场景加载挂起操作 /// - public bool UnSuspendLoad() + public void UnSuspendLoad() { - if (_asyncOperation == null) - return false; - - _asyncOperation.allowSceneActivation = true; - return true; + if (IsDone == false) + { + _suspendLoadMode = false; + } } } } \ No newline at end of file diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSceneProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSceneProvider.cs index d7c5e4a..11b55fd 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSceneProvider.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSceneProvider.cs @@ -9,14 +9,14 @@ namespace YooAsset internal sealed class DatabaseSceneProvider : ProviderBase { public readonly LoadSceneMode SceneMode; - private readonly bool _suspendLoad; + private bool _suspendLoadMode; private AsyncOperation _asyncOperation; public DatabaseSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo) { SceneMode = sceneMode; SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath); - _suspendLoad = suspendLoad; + _suspendLoadMode = suspendLoad; } internal override void InternalOnStart() { @@ -69,7 +69,7 @@ namespace YooAsset _asyncOperation = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters); if (_asyncOperation != null) { - _asyncOperation.allowSceneActivation = !_suspendLoad; + _asyncOperation.allowSceneActivation = !_suspendLoadMode; _asyncOperation.priority = 100; SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1); _steps = ESteps.Checking; @@ -95,6 +95,13 @@ namespace YooAsset } else { + // 注意:在业务层中途可以取消挂起 + if (_asyncOperation.allowSceneActivation == false) + { + if (_suspendLoadMode == false) + _asyncOperation.allowSceneActivation = true; + } + Progress = _asyncOperation.progress; if (_asyncOperation.isDone == false) return; @@ -118,13 +125,12 @@ namespace YooAsset /// /// 解除场景加载挂起操作 /// - public bool UnSuspendLoad() + public void UnSuspendLoad() { - if (_asyncOperation == null) - return false; - - _asyncOperation.allowSceneActivation = true; - return true; + if (IsDone == false) + { + _suspendLoadMode = false; + } } } } \ No newline at end of file