SceneHandler¶
In this tutorial, we will learn how to set up Scene Handler in our scene and how to transition between scenes.
Scene Handler is a mechanic contained in MAGES.Utilities module which enables scene transition. With the Scene Handler tool, developers can switch between scenes easily and effortlessly.
How to set up Scene Handler¶
The first is to create an empty scene and add the SCENE_MANAGEMENT component to your newly created scene. Create an empty gameobject with the name SceneHandler and Add the SceneHandler component to your object.
After that, you need to add the CameraFadeManagement component to a gameobject. We encourage you to add it on the InterfaceManagement gameobject.
Your next step is to edit the “Scene in Build” in Build Settings. In order to access Build Settings you need to go to File → Build Settings. After clicking Build Settings, a window will appear
Finally, we have to add all the scenes that we will perform a transition. We need to open each scene, and when they are loaded in the editor, press the “Add Open Scenes” button from the Build Settings window.
How to use Scene Handler¶
In this step we will write the method call to make a scene transition with and without fade.
In order to do a scene transition with fade, the method you can use is called SwitchScene and its members are a string for the name of the Scene that you are going to transition at, a Vector3 for the camera position and a Quaternion for the camera rotation. You can access this method from the MAGES.Utilities.SceneHandler.
using MAGES.Utilities
public class SceneChangerScriot : MonoBehaviour
{
private public Start(){
//Switches to the "Second_Scene" scene, with the given camera position and rotation
SceneHandler.Get.SwitchScene("Second_Scene",new Vector3(1,1,1),Quaternion.Euler(0f, 90f, 0f));
}
}
Below is an example of scene transitioning between the first scene and the second scene.
Another helpful method is the AddScene. With this function you can add a scene when none is there (without the fade-out effect). Usually, it will be the first scene. This function only has one member. A string for the name of the Scene that you are going to add.
using MAGES.Utilities
public class SceneChangerScriot : MonoBehaviour
{
private public Start(){
//Adds the "First_Scene" without a fade-out effect
SceneHandler.Get.AddScene("First_Scene");
}
}