Skip to content

Commit

Permalink
[v0.1.14] Test allowSceneActivation usage
Browse files Browse the repository at this point in the history
  • Loading branch information
g0dzZz-coder committed May 17, 2024
1 parent bc89dc5 commit ccc9c2f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions Runtime/Operations/SceneLoadOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Depra.Loading.Operations;
using Depra.Scenes.Definitions;
using UnityEngine.SceneManagement;
using AsyncOperation = UnityEngine.AsyncOperation;

namespace Depra.Scenes.Operations
{
Expand All @@ -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;

Expand All @@ -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();
}

Expand Down Expand Up @@ -76,13 +79,15 @@ private void OnSceneLoaded(Scene scene, LoadSceneMode mode)

private void Activate()
{
_operation.allowSceneActivation = true;
var scene = SceneManager.GetSceneByName(_desiredScene.DisplayName);
SceneManager.SetActiveScene(scene);
Dispose();
}

private void Dispose()
{
_operation = null;
_loadingExpectant?.Dispose();
_activationExpectant?.Dispose();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.depra.scenes",
"version": "0.1.13",
"version": "0.1.14",
"displayName": "Depra.Scenes",
"description": "",
"unity": "2022.3",
Expand Down

0 comments on commit ccc9c2f

Please sign in to comment.