mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
fix: Check SceneManager GetSceneByName and GetSceneByPath (#1684)
* fix: Check SceneManager GetSceneByName and GetSceneByPath * Fix example too.
This commit is contained in:
parent
55e075c872
commit
e7cfd5a498
@ -45,7 +45,7 @@ IEnumerator UnloadScenes()
|
||||
if (LogFilter.Debug) Debug.Log("Unloading Subscenes");
|
||||
|
||||
foreach (string sceneName in subScenes)
|
||||
if (SceneManager.GetSceneByName(sceneName).IsValid())
|
||||
if (SceneManager.GetSceneByName(sceneName).IsValid() || SceneManager.GetSceneByPath(sceneName).IsValid())
|
||||
{
|
||||
yield return SceneManager.UnloadSceneAsync(sceneName);
|
||||
if (LogFilter.Debug) Debug.Log($"Unloaded {sceneName}");
|
||||
|
@ -850,25 +850,28 @@ internal void ClientChangeScene(string newSceneName, SceneOperation sceneOperati
|
||||
loadingSceneAsync = SceneManager.LoadSceneAsync(newSceneName);
|
||||
break;
|
||||
case SceneOperation.LoadAdditive:
|
||||
if (!SceneManager.GetSceneByName(newSceneName).IsValid())
|
||||
// Ensure additive scene is not already loaded on client by name or path
|
||||
// since we don't know which was passed in the Scene message
|
||||
if (!SceneManager.GetSceneByName(newSceneName).IsValid() && !SceneManager.GetSceneByPath(newSceneName).IsValid())
|
||||
loadingSceneAsync = SceneManager.LoadSceneAsync(newSceneName, LoadSceneMode.Additive);
|
||||
else
|
||||
{
|
||||
Debug.LogWarningFormat("Scene {0} is already loaded", newSceneName);
|
||||
Debug.LogWarning($"Scene {newSceneName} is already loaded");
|
||||
|
||||
// Re-enable the transport that we disabled before entering this switch
|
||||
Transport.activeTransport.enabled = true;
|
||||
}
|
||||
break;
|
||||
case SceneOperation.UnloadAdditive:
|
||||
if (SceneManager.GetSceneByName(newSceneName).IsValid())
|
||||
{
|
||||
if (SceneManager.GetSceneByName(newSceneName) != null)
|
||||
// Ensure additive scene is actually loaded on client by name or path
|
||||
// since we don't know which was passed in the Scene message
|
||||
if (SceneManager.GetSceneByName(newSceneName).IsValid() || SceneManager.GetSceneByPath(newSceneName).IsValid())
|
||||
loadingSceneAsync = SceneManager.UnloadSceneAsync(newSceneName, UnloadSceneOptions.UnloadAllEmbeddedSceneObjects);
|
||||
else
|
||||
Transport.activeTransport.enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Cannot unload the active scene with UnloadAdditive operation");
|
||||
Debug.LogWarning($"Cannot unload {newSceneName} with UnloadAdditive operation");
|
||||
|
||||
// Re-enable the transport that we disabled before entering this switch
|
||||
Transport.activeTransport.enabled = true;
|
||||
}
|
||||
break;
|
||||
|
Loading…
Reference in New Issue
Block a user