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); }
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); } }