Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigathema blank scene is now unloaded when scene loaded #16

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Threading;
using Cysharp.Threading.Tasks;
using UnityEngine.SceneManagement;

namespace MackySoft.Navigathena.SceneManagement
{
internal sealed class NavigathenaBlankSceneIdentifier : ISceneIdentifier
{

public static readonly NavigathenaBlankSceneIdentifier Instance = new NavigathenaBlankSceneIdentifier();

public ISceneHandle CreateHandle ()
{
return NavigathenaBlankSceneHandle.Instance;
}

sealed class NavigathenaBlankSceneHandle : ISceneHandle
{

public static readonly NavigathenaBlankSceneHandle Instance = new NavigathenaBlankSceneHandle();

const string kSceneName = "Navigathena Blank";

public UniTask<Scene> Load (IProgress<float> progress = null, CancellationToken cancellationToken = default)
{
if (SceneManager.GetSceneByName(kSceneName).IsValid())
{
return UniTask.FromResult(SceneManager.GetSceneByName(kSceneName));
}
return UniTask.FromResult(SceneManager.CreateScene(kSceneName));
}

public async UniTask Unload (IProgress<float> progress = null, CancellationToken cancellationToken = default)
{
Scene scene = SceneManager.GetSceneByName(kSceneName);
if (!scene.isLoaded && !scene.IsValid())
{
return;
}

await SceneManager.UnloadSceneAsync(kSceneName)
.ToUniTask(progress, cancellationToken: cancellationToken);
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ async UniTask TryFinalizeAndUnloadCurrentScene (SceneHistoryEntry currentSceneEn
// NOTE: If the current scene is the only scene, create an empty scene to prevent an exception from being thrown when unloading.
if (SceneManager.sceneCount < 2)
{
SceneManager.CreateScene("Navigathena Blank");
await NavigathenaBlankSceneIdentifier.Instance.CreateHandle().Load(cancellationToken: cancellationToken);
}

await m_CurrentSceneState.Value.Handle.Unload(m_SceneProgressFactory.CreateProgress(progressDataStore, progress), cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public static async UniTask<SceneState> LoadSceneAndGetEntryPoint (ISceneIdentif
Scene loadedScene = await sceneHandle.Load(sceneProgressFactory.CreateProgress(progressDataStore, progress), cancellationToken);
cancellationToken.ThrowIfCancellationRequested();

await NavigathenaBlankSceneIdentifier.Instance.CreateHandle().Unload(cancellationToken: cancellationToken);
cancellationToken.ThrowIfCancellationRequested();

var sceneEntryPoint = loadedScene.GetComponentInScene<ISceneEntryPoint>(true);
return new SceneState(scene, sceneHandle, sceneEntryPoint);
}
Expand Down
Loading