mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00: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");
|
if (LogFilter.Debug) Debug.Log("Unloading Subscenes");
|
||||||
|
|
||||||
foreach (string sceneName in 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);
|
yield return SceneManager.UnloadSceneAsync(sceneName);
|
||||||
if (LogFilter.Debug) Debug.Log($"Unloaded {sceneName}");
|
if (LogFilter.Debug) Debug.Log($"Unloaded {sceneName}");
|
||||||
|
@ -850,25 +850,28 @@ internal void ClientChangeScene(string newSceneName, SceneOperation sceneOperati
|
|||||||
loadingSceneAsync = SceneManager.LoadSceneAsync(newSceneName);
|
loadingSceneAsync = SceneManager.LoadSceneAsync(newSceneName);
|
||||||
break;
|
break;
|
||||||
case SceneOperation.LoadAdditive:
|
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);
|
loadingSceneAsync = SceneManager.LoadSceneAsync(newSceneName, LoadSceneMode.Additive);
|
||||||
else
|
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;
|
Transport.activeTransport.enabled = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SceneOperation.UnloadAdditive:
|
case SceneOperation.UnloadAdditive:
|
||||||
if (SceneManager.GetSceneByName(newSceneName).IsValid())
|
// 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) != null)
|
if (SceneManager.GetSceneByName(newSceneName).IsValid() || SceneManager.GetSceneByPath(newSceneName).IsValid())
|
||||||
loadingSceneAsync = SceneManager.UnloadSceneAsync(newSceneName, UnloadSceneOptions.UnloadAllEmbeddedSceneObjects);
|
loadingSceneAsync = SceneManager.UnloadSceneAsync(newSceneName, UnloadSceneOptions.UnloadAllEmbeddedSceneObjects);
|
||||||
else
|
|
||||||
Transport.activeTransport.enabled = true;
|
|
||||||
}
|
|
||||||
else
|
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;
|
Transport.activeTransport.enabled = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user