Set the scene to be active.
private void Update() { for (int i = 0; i < sceneLoaderList.Count; i++) { SceneLoader loader = sceneLoaderList[i]; bool loaded = loader.Update(); if (loaded) { SceneDefine.SCENE_ID id = loader.SceneID; UnityScene unityScene = UnitySceneManager.GetSceneByName(loader.Name); SceneBase scene = GameObject.Find(unityScene.name).GetComponent <SceneBase>(); sceneList.Add(scene); sceneLoaderList.RemoveAt(i); UnitySceneManager.SetActiveScene(unityScene); scene.Setup(id, unityScene); break; } } for (int i = 0; i < sceneList.Count; i++) { // アンロード処理 if (sceneList[i] == null) { sceneList.RemoveAt(i); break; } } }
private static IEnumerator LoadInternal(LoadContext context) { if (context == null) { yield break; } var scene = UnitySceneManager.GetSceneByName(context.NextScene.Name); if (!scene.isLoaded) { yield return(UnitySceneManager.LoadSceneAsync(context.NextScene.Name, LoadSceneMode.Additive)); } UnitySceneManager.SetActiveScene(UnitySceneManager.GetSceneByName(context.NextScene.Name)); var sceneContext = FindSceneContext(context.NextScene.Name); if (sceneContext == null) { yield break; } yield return(new WaitUntil(() => sceneContext.Initialized)); var sceneSettings = sceneContext.Container.TryResolve <SceneSettings>(); if (sceneSettings != null) { sceneSettings.Subs.ForEach(x => context.AddAdditiveScene(x)); } context.NextScene.Lifecycles = sceneContext.Container.ResolveAll <ISceneLifecycle>(); }
public void SetCurrentScene(SceneName sceneName) { var scene = UnitySceneManager.GetSceneByName(sceneName.ToString()); UnitySceneManager.SetActiveScene(scene); loadedSceneNames.Add(sceneName.ToString()); }
private void Start() { // 最初に再生したシーンを設定する。 UnityScene unityScene = UnitySceneManager.GetActiveScene(); string unitySceneName = unityScene.name; SceneBase scene = GameObject.Find(unitySceneName).GetComponent <SceneBase>(); scene.Setup(GetSceneID(ref unitySceneName), unityScene); sceneList.Add(scene); UnitySceneManager.SetActiveScene(unityScene); }
private async UniTask Load(string sceneName, Action <DiContainer> extraBindings) { var currentScene = UnitySceneManager.GetActiveScene(); await LoadAdditive(sceneName, extraBindings); var nextScene = UnitySceneManager.GetSceneByName(sceneName); UnitySceneManager.SetActiveScene(nextScene); await UnitySceneManager.UnloadSceneAsync(currentScene); }
/// <summary> /// シーンをアクティブする。 /// </summary> /// <param name="id"></param> public static void SetActiveScene(SceneDefine.SCENE_ID id) { List <SceneBase> sceneList = Instance.sceneList; for (int i = 0; i < sceneList.Count; i++) { if (sceneList[i].SceneID == id) { UnitySceneManager.SetActiveScene(sceneList[i].UnityScene); break; } } }
private void OnLoadSceneSuccess(object sender, GameFramework.Scene.LoadSceneSuccessEventArgs e) { m_MainCamera = Camera.main; if (SceneManager.GetActiveScene() == m_GameFrameworkScene) { Scene scene = SceneManager.GetSceneByName(GetSceneName(e.SceneAssetName)); if (!scene.IsValid()) { Log.Error("Loaded scene '{0}' is invalid.", e.SceneAssetName); return; } SceneManager.SetActiveScene(scene); } m_EventComponent.Fire(this, LoadSceneSuccessEventArgs.Create(e)); }
private void OnLoadSceneSuccess(object sender, GameFramework.Scene.LoadSceneSuccessEventArgs e) { m_MainCamera = Camera.main; if (SceneManager.GetActiveScene() == m_GameFrameworkScene) { Scene scene = SceneManager.GetSceneByName(GetSceneName(e.SceneAssetName)); if (!scene.IsValid()) { Log.Error("Loaded scene '{0}' is invalid.", e.SceneAssetName); return; } SceneManager.SetActiveScene(scene); } if (m_EnableLoadSceneSuccessEvent) { _eventComponent.Fire(this, ReferencePool.Acquire <LoadSceneSuccessEventArgs>().Fill(e)); } }
//加载场景成功的回调 private void OnLoadSceneSuccess(object sender, GameFramework.Scene.LoadSceneSuccessEventArgs e) { m_MainCamera = Camera.main; //获取主相机 if (SceneManager.GetActiveScene() == m_GFScene) //如果当前是框架所在场景 { Scene scene = SceneManager.GetSceneByName(GetSceneName(e.SceneAssetName)); //获取加载成功的场景 if (!scene.IsValid()) //加载的场景不合法 { Log.Error("[SceneComponent.OnLoadSceneSuccess] Loaded scene '{0}' is invalid.", e.SceneAssetName); return; } SceneManager.SetActiveScene(scene); //激活场景 } if (m_EnableLoadSceneSuccessEvent) { m_EventComponent.Fire(this, ReferencePool.Acquire <LoadSceneSuccessEventArgs>().Fill(e)); } }
/// <summary> /// 生成所有场景的Prefab资源 /// </summary> public static void GenLightmapPrefabAll() { EditorSceneManager.SaveOpenScenes(); AssetDatabase.SaveAssets(); string[] sceneDirs = new[] { "Assets/AllResources/scene-s/" }; string curScenePath = EditorSceneManager.GetActiveScene().path; foreach (string sceneDir in sceneDirs) { string[] sceneArr = Directory.GetFiles(sceneDir, "*.unity", SearchOption.AllDirectories); if (sceneArr == null || sceneArr.Length <= 0) { continue; } int index = 0; foreach (string scenePath in sceneArr) { EditorUtility.DisplayProgressBar("生成Lightmap Prefab", "正在打包生成资源,请等待...", index / (float)sceneArr.Length); Scene curScene = EditorSceneManager.OpenScene(scenePath.Replace("\\", "/")); SceneManager.SetActiveScene(curScene); genBakeLightmapAndPrefab(true); index++; } } EditorUtility.ClearProgressBar(); //还原打包前打开的场景 EditorSceneManager.OpenScene(curScenePath); EditorSceneManager.SaveOpenScenes(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Debug.Log("已完成打包" + System.DateTime.Now.ToString("HH:mm:ss")); EditorUtility.DisplayDialog("提示", "已完成批量打包!" + System.DateTime.Now.ToString("HH:mm:ss"), "OK"); }
/* Make sure this scene is unique, since the loader will actually load it * when in-game */ private System.Collections.IEnumerator makeSceneUnique() { Scene[] scenes; AsyncOp op; int mainIdx; scenes = new Scene[SceneMng.sceneCount]; mainIdx = -1; for (int i = 0; i < scenes.Length; i++) { scenes[i] = SceneMng.GetSceneAt(i); if (scenes[i].name == this.GameOverSceneName) { mainIdx = i; } } if (mainIdx == -1) { throw new System.Exception($"Didn't find the expected scene ({this.GameOverSceneName})"); } for (int i = 0; i < scenes.Length; i++) { if (i == mainIdx) { continue; } op = SceneMng.UnloadSceneAsync(scenes[i]); yield return(op); } SceneMng.SetActiveScene(scenes[mainIdx]); yield return(SceneMng.LoadSceneAsync( "scenes/000-game-controller/bg-scenes/GameOverBG", SceneMode.Additive)); yield return(runGameOverAnim()); }
IEnumerator DoLoadScene(string toScene, LoadSceneMode mode, bool unloadCurrent) { isLoading = true; //about to change scene if (sceneChangeStartCallback != null) { sceneChangeStartCallback(); } //play out transitions for (int i = 0; i < mTransitions.Count; i++) { yield return(mTransitions[i].Out()); } //wait for scene add to finish while (mSceneAddRout != null) { yield return(null); } //unload added scenes UnloadAddedScenes(); //wait for scene remove to finish while (mSceneRemoveRout != null) { yield return(null); } //scene is about to change if (sceneChangeCallback != null) { sceneChangeCallback(toScene); } bool doLoad = true; if (mode == LoadSceneMode.Additive) { bool isCurSceneRoot = _rootScene == mCurScene; //special case if we are loading the same scene we first instantiated, but is not the root if (!isCurSceneRoot && mFirstSceneLoaded == mCurScene) { mode = LoadSceneMode.Single; } else { //unload current scene if it's not the root //Debug.Log("unload: "+mCurScene); if (unloadCurrent && !isCurSceneRoot) { var sync = UnitySceneManager.UnloadSceneAsync(mCurScene); if (sync != null) { while (!sync.isDone) { yield return(null); } } } //load only if it doesn't exist doLoad = !UnitySceneManager.GetSceneByName(toScene).IsValid(); } } //load if (doLoad) { var sync = UnitySceneManager.LoadSceneAsync(toScene, mode); //something went wrong if (sync == null) { isLoading = false; yield break; } while (!sync.isDone) { yield return(null); } } else { yield return(null); } mCurScene = UnitySceneManager.GetSceneByName(toScene); UnitySceneManager.SetActiveScene(mCurScene); if (sceneChangePostCallback != null) { sceneChangePostCallback(); } //play in transitions for (int i = 0; i < mTransitions.Count; i++) { yield return(mTransitions[i].In()); } isLoading = false; if (sceneChangeEndCallback != null) { sceneChangeEndCallback(); } }
IEnumerator DoLoadScene(string toScene, LoadSceneMode mode, bool unloadCurrent) { isLoading = true; //make sure the scene is not paused Resume(); //play out transitions for (int i = 0; i < mTransitions.Count; i++) { yield return(mTransitions[i].Out()); } //scene is about to change if (sceneChangeCallback != null) { sceneChangeCallback(toScene); } bool doLoad = true; if (mode == LoadSceneMode.Additive) { //Debug.Log("unload: "+mCurScene); if (unloadCurrent && mCurScene != mRootScene) { UnitySceneManager.UnloadScene(mCurScene); //unload added scenes UnloadAddedScenes(); } //load only if it doesn't exist doLoad = !UnitySceneManager.GetSceneByName(toScene).IsValid(); } else { //single mode removes all other scenes ClearAddSceneData(); } //load if (doLoad) { var sync = UnitySceneManager.LoadSceneAsync(toScene, mode); while (!sync.isDone) { yield return(null); } } else { yield return(null); } mCurScene = UnitySceneManager.GetSceneByName(toScene); UnitySceneManager.SetActiveScene(mCurScene); if (sceneChangePostCallback != null) { sceneChangePostCallback(); } //play in transitions for (int i = 0; i < mTransitions.Count; i++) { yield return(mTransitions[i].In()); } isLoading = false; }
/// <summary> /// 设置活动场景 /// </summary> /// <param name="sceneAssetName"></param> /// <returns></returns> public bool SetActiveScene(string sceneAssetName) { return(SceneManager.SetActiveScene(SceneManager.GetSceneByPath(sceneAssetName))); }