From ccc9c2f3ede60991a3317ba90419b96c54435232 Mon Sep 17 00:00:00 2001 From: godzzz Date: Fri, 17 May 2024 23:33:19 +0400 Subject: [PATCH] [v0.1.14] Test allowSceneActivation usage --- Runtime/Operations/SceneLoadOperation.cs | 13 +++++++++---- package.json | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Runtime/Operations/SceneLoadOperation.cs b/Runtime/Operations/SceneLoadOperation.cs index 2288f1b..8f82ab6 100644 --- a/Runtime/Operations/SceneLoadOperation.cs +++ b/Runtime/Operations/SceneLoadOperation.cs @@ -7,6 +7,7 @@ using Depra.Loading.Operations; using Depra.Scenes.Definitions; using UnityEngine.SceneManagement; +using AsyncOperation = UnityEngine.AsyncOperation; namespace Depra.Scenes.Operations { @@ -16,6 +17,7 @@ public sealed class SceneLoadOperation : ILoadingOperation private readonly OperationDescription _description; private readonly IExpectant _externalActivationExpectant; + private AsyncOperation _operation; private Expectant _loadingExpectant; private IExpectant _activationExpectant; @@ -37,16 +39,17 @@ public async Task Load(ProgressCallback onProgress, CancellationToken token) SetupActivation(); } - var operation = SceneManager.LoadSceneAsync(_desiredScene.DisplayName, _desiredScene.LoadMode); - if (operation == null) + _operation = SceneManager.LoadSceneAsync(_desiredScene.DisplayName, _desiredScene.LoadMode); + if (_operation == null) { onProgress?.Invoke(1); return; } - while (operation.isDone == false) + _operation.allowSceneActivation = false; + while (_operation.isDone == false) { - onProgress?.Invoke(operation.progress); + onProgress?.Invoke(_operation.progress); await Task.Yield(); } @@ -76,6 +79,7 @@ private void OnSceneLoaded(Scene scene, LoadSceneMode mode) private void Activate() { + _operation.allowSceneActivation = true; var scene = SceneManager.GetSceneByName(_desiredScene.DisplayName); SceneManager.SetActiveScene(scene); Dispose(); @@ -83,6 +87,7 @@ private void Activate() private void Dispose() { + _operation = null; _loadingExpectant?.Dispose(); _activationExpectant?.Dispose(); } diff --git a/package.json b/package.json index 9d443ff..010d222 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.depra.scenes", - "version": "0.1.13", + "version": "0.1.14", "displayName": "Depra.Scenes", "description": "", "unity": "2022.3",