Skip to content

Instantly share code, notes, and snippets.

@vrobel
Last active August 29, 2015 14:03
Show Gist options
  • Save vrobel/6120c07f1c57b29cc770 to your computer and use it in GitHub Desktop.
Save vrobel/6120c07f1c57b29cc770 to your computer and use it in GitHub Desktop.
Multiple SceneManagers in one Scene
using System.Collections.Generic;
using UnityEngine;
//All SceneManagers that I want to keep in one scene needs te extend this class.
//I had to fix it in designer generated code which is poor, or it can be copy pasted to each Scene class.
//Add all root GameObjects for each scene so they will get enabled when scene is activated
public class CoexistiveSceneManager : SceneManager
{
public List<GameObject> SceneRoots;
public override void Setup()
{
base.Setup();
SetSceneRoots(false);
}
public override void OnLoaded()
{
base.OnLoaded();
SetSceneRoots(true);
}
public override void Unload()
{
base.Unload();
SetSceneRoots(false);
}
private void SetSceneRoots(bool value)
{
foreach (var sceneRoot in SceneRoots)
{
sceneRoot.SetActive(value);
}
}
}
public class LevelSelectScene : LevelSelectSceneBase {
public override System.Collections.IEnumerator Load(UpdateProgressDelegate progress) {
// Use the controllers to create the game.
yield break;
}
public override void Setup() {
base.Setup();
}
// Replaced autogenerated commands from SwitchGameAndLevel to SwitchGame.
public override void Back()
{
GameManager.SwitchGame<PackSelectScene>((container) => { container._PackSelectSceneSettings = _BackTransition; });
}
}
https://www.dropbox.com/s/ngwojkkbyde6k47/SceneManager%20design.jpg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment