public void TransitionToEntry() { #if UNITY_EDITOR if (ignoreEntryCall) { return; } #endif // If no entry scene has been set, just try to find the current scene if (EntryScene == null) { SceneModel model = scenes.Find((x) => x.SceneAssetPath == SceneManager.GetActiveScene().path); ActiveScene = model; Evaluate(); return; } // Check if the scene is already active if (SceneManagerExtensions.IsSceneLoadedByPath(EntryScene.SceneAssetPath)) { ActiveScene = EntryScene; // it's already active, so do the starting evaluation Evaluate(); return; } TransitionToScene(EntryScene); }
private static void LoadEntrySceneOnPlayMode() { IEnumerable <SceneManagerController> controllers = Common.Editors.AssetDatabaseExtensions.GetAssetsOfType <SceneManagerController>(); playModeController = null; wasEntryOpened = false; SceneManagerController controllerToUse = controllers.FirstOrDefault((x) => x.useOnPlay); if (controllerToUse == null || controllerToUse.EntryScene == null) { return; } playModeController = controllerToUse; playModeController.ignoreEntryCall = true; SceneManager.sceneLoaded -= SceneManager_sceneLoaded; SceneManager.sceneLoaded += SceneManager_sceneLoaded; if (!SceneManagerExtensions.IsSceneLoadedByPath(controllerToUse.EntryScene.SceneAssetPath)) { SceneManager.LoadScene(controllerToUse.EntryScene.SceneName); } }
private Activity GetCurrentPreloadedActivityInEditor() { IList <string> loadedScenes = SceneManagerExtensions.GetLoadedScenes(); //Startup scene and Utilitary scenes should be ignored. They should not //be in any activity. Configuration configuration = Configuration.Get(); loadedScenes.Remove(R.S.Scene.ToString(configuration.StartingScene)); foreach (R.E.Scene scene in configuration.UtilitaryScenes) { loadedScenes.Remove(R.S.Scene.ToString(scene)); } //If any activity scenes matches the currently loaded scenes, then this is //the current activity. foreach (Activity activity in AssetsExtensions.FindAssets <Activity>()) { bool hasAllScenesLoaded = true; foreach (string scene in activity.GetScenes()) { hasAllScenesLoaded &= loadedScenes.Contains(scene); } if (hasAllScenesLoaded) { return(activity); } } return(null); }
private Activity GetCurrentPreloadedActivityInEditor() { foreach (Activity activity in AssetsExtensions.FindAssets <Activity>()) { bool hasAllScenesLoaded = true; if (activity.Scene != R.E.Scene.None) { hasAllScenesLoaded &= SceneManagerExtensions.IsSceneLoaded(R.S.Scene.ToString(activity.Scene)); } foreach (Fragment fragment in activity.Fragments) { if (fragment.Scene != R.E.Scene.None) { hasAllScenesLoaded &= SceneManagerExtensions.IsSceneLoaded(R.S.Scene.ToString(fragment.Scene)); } } foreach (Menu menu in activity.Menus) { if (menu.Scene != R.E.Scene.None) { hasAllScenesLoaded &= SceneManagerExtensions.IsSceneLoaded(R.S.Scene.ToString(menu.Scene)); } } if (hasAllScenesLoaded) { return(activity); } } return(null); }
/// <summary> /// Changes the lighting GI workflow of a scene asset /// </summary> /// <param name="workflow"></param> /// <param name="targetSceneAsset"></param> private void ChangeSceneLightingGIWorkflow(SceneAsset targetSceneAsset, Lightmapping.GIWorkflowMode workflow) { var originalSelection = Selection.activeObject; var originalContext = Selection.activeContext; var originalScene = EditorSceneManager.GetActiveScene(); // Find the scene we are on so we can change back to it later string newScenePath = AssetDatabase.GetAssetPath(targetSceneAsset); var newScene = EditorSceneManager.GetSceneByPath(newScenePath); // Get the scene reference of the target scene bool requireSceneLoad = !SceneManagerExtensions.IsSceneLoaded(newScene); // If the scene we are going to change lightmaps on is loaded and dirty, warn the user any changes will be saved if (!requireSceneLoad && newScene.isDirty) { if (!EditorUtility.DisplayDialog("Confirm changing GI Lighting Workflow", $"By changing the GI lighting workflow on \"{newScene.name}\" it will have to be saved, do you want to continue?", "Continue", "Cancel")) { return; } } // If the scene we are trying to change isn't loaded load it if (requireSceneLoad) { EditorSceneManager.OpenScene(newScenePath, OpenSceneMode.Additive); } var loadedScene = EditorSceneManager.GetSceneByPath(newScenePath); // Change active scenes to the target so we can change the settings bool requireSceneChange = originalScene != newScene; if (requireSceneChange) { EditorSceneManager.SetActiveScene(loadedScene); } // Change the lightmap workflow Lightmapping.giWorkflowMode = workflow; EditorSceneManager.SaveScene(loadedScene); // Change back to the original scene if (requireSceneChange) { EditorSceneManager.SetActiveScene(originalScene); } // If we loaded the scene unload it when we're done if (requireSceneLoad) { EditorSceneManager.CloseScene(loadedScene, true); } Selection.SetActiveObjectWithContext(originalSelection, originalContext); }
private bool CheckSceneLoadedScene(SceneField scene) { if (SceneManagerExtensions.IsSceneLoaded(scene)) { Debug.LogWarning($"Scene {scene.SceneName} is already loaded... Skipping"); return(true); } Debug.LogWarning($"Scene {scene.SceneName} is not loaded... Loading"); return(false); }
private void ClientSceneReady(NetworkConnection connection, SceneReadyMessage message) { Scene?scene = SceneManagerExtensions.GetSceneByPathOrName(message.sceneNameOrPath); if (scene == null) { Debug.LogWarning($"Scene {message.sceneNameOrPath} not loaded on server despite client readying it"); return; } PlayerForConnection(connection).MoveToScene(scene.Value); }
private void ClientChangeScene(string sceneNameOrPath, SceneOperation sceneOperation) { if (clientSceneLoadOperation != null) { Debug.LogWarning($"Scene load operation already in progress!"); } switch (sceneOperation) { case SceneOperation.Normal: clientSceneLoadOperation = SceneManager.LoadSceneAsync(sceneNameOrPath); break; case SceneOperation.LoadAdditive: if (SceneManagerExtensions.GetSceneByPathOrName(sceneNameOrPath) == null) { Debug.Log($"Starting to load scene {sceneNameOrPath}"); clientSceneLoadOperation = SceneManager.LoadSceneAsync(sceneNameOrPath, LoadSceneMode.Additive); } else { Debug.Log($"Scene {sceneNameOrPath} already loaded, skipping"); } break; case SceneOperation.UnloadAdditive: if (SceneManagerExtensions.GetSceneByPathOrName(sceneNameOrPath) != null) { Debug.Log($"Starting to unload scene {sceneNameOrPath}"); clientSceneLoadOperation = SceneManager.UnloadSceneAsync(sceneNameOrPath, UnloadSceneOptions.UnloadAllEmbeddedSceneObjects); clientSceneLoadOperation.completed += op => clientSceneLoadOperation = null; } else { Debug.Log($"Scene {sceneNameOrPath} already unloaded, skipping"); } // The rest of the logic is really only applicable to loading. return; } if (clientSceneLoadOperation != null) { clientSceneLoadOperation.allowSceneActivation = false; } StartCoroutine(NotifyServerWhenSceneReady(sceneNameOrPath)); }
private IEnumerator WaitForSceneToLoadThenMovePlayer(string sceneNameOrPath, GameObject player) { yield return(loadAllScenesCoroutine); // This scene should be loaded by the above. Scene?scene = SceneManagerExtensions.GetSceneByPathOrName(sceneNameOrPath); if (SceneManager.SetActiveScene(scene.Value)) { SceneManager.MoveGameObjectToScene(player, scene.Value); Debug.Log($"Moved host player to {sceneNameOrPath}"); } else { Debug.LogWarning($"Failed to change active scene to {sceneNameOrPath}"); } }
private IEnumerator WaitForSceneActivationThenSetActive(string sceneNameOrPath) { if (clientSceneLoadOperation != null) { clientSceneLoadOperation.allowSceneActivation = true; yield return(clientSceneLoadOperation); clientSceneLoadOperation = null; } Scene scene = SceneManagerExtensions.GetSceneByPathOrName(sceneNameOrPath).Value; if (!SceneManager.SetActiveScene(scene)) { Debug.LogWarning($"Failed to activate scene {sceneNameOrPath}"); } SceneManager.MoveGameObjectToScene(NetworkClient.connection.identity.gameObject, scene); }
private IEnumerator LoadSceneAsync() { if (string.IsNullOrEmpty(sceneName)) { Debug.LogWarning("[SceneLoade] Define the level name"); yield break; } isLoading = true; if (destroyObjectsBeforeLoading) { Destroy(objectsToDestroy); } yield return(SceneManagerExtensions.LoadSceneAsync(sceneName, loadMode)); if (destroySelfWhenDone) { Destroy(gameObject); } isLoading = false; }
public void Load() { if (isLoading) { Debug.LogWarning("[SceneLoader] Already loading"); return; } if (!async) { if (destroyObjectsBeforeLoading) { Destroy(objectsToDestroy); } SceneManagerExtensions.LoadScene(sceneName, loadMode); if (destroySelfWhenDone) { Destroy(gameObject); } } else { StartCoroutine(LoadSceneAsync()); } }
public async Task LoadScenesAsync(IProgress <float> progress = null) { if (currentlyLoadingTask) { throw new ScenesAlreadyLoadingException(); } currentlyLoadingTask = true; var thisScene = SceneManagerExtensions.GetLoadedSceneContainingGameObject(this.gameObject); OnSceneLoadStart?.Invoke(thisScene); await Cysharp.Threading.Tasks.UniTask.DelayFrame(1); try { Debug.Log( $"Scene: '{SceneManagerExtensions.GetLoadedSceneContainingGameObject(this.gameObject).name}' is loading with format: '{LoadFormat}'"); // If the scenes are already loaded nothing needs to be done if (AllScenesLoaded) { Debug.Log( $"Scene: '{SceneManagerExtensions.GetLoadedSceneContainingGameObject(this.gameObject).name}' has all its children loaded so is cancelled"); return; } // Report 0 progress initially progress?.Report(0); if (!Application.isPlaying) { // In edit mode scenes need to be loaded using different method LoadScenesEditor(); } else { switch (LoadFormat) { case LoadFormat.Sequential: LoadScenesSyncronously(); progress?.Report(1); // Finished when syncrounously is done break; case LoadFormat.SequentialAsync: await LoadScenesSequentialAync(progress); break; case LoadFormat.SimultaneousAsync: await LoadScenesSimultaneousAsync(progress); break; default: throw new ArgumentOutOfRangeException(); } } // If the game is running and a scene was just loaded we need to wait until the next frame to set it as active if (Application.isPlaying) { await Cysharp.Threading.Tasks.UniTask.DelayFrame(0, PlayerLoopTiming.PostLateUpdate); } if (!ActiveSceneNull) { Debug.Log($"Setting scene {NewActiveScene.ScenePath} as active"); if (!SceneManagerExtensions.IsSceneLoaded(NewActiveScene)) { throw new ActiveSceneNotReadyException(); } SceneManager.SetActiveScene(SceneManager.GetSceneByName(NewActiveScene)); } else { Debug.Log($"Scene {NewActiveScene.ScenePath} is null and cannot be set as active"); } } finally { currentlyLoadingTask = false; OnSceneLoadComplete?.Invoke(thisScene); } }