Skip to content

Quickstart

Collapsed Plug edited this page Aug 5, 2022 · 6 revisions

Install dependencies

These plugins are required:

If you install UniSwitcher using UPM, they will be included automatically.

[NOTE]
If you have been using these plugins from the "Plugins" folder, you will run into issues
because they and the ones that UniSwitcher pulls via UPM clash with each other.
If this happens, you will need to remove the dependency from the "Plugins" folder.

Enable UniSwitcher in your Project

If you have not used Zenject in this project, follow the next steps:

  1. In all the scenes, place Scene Context by [GameObject] > [Zenject] > [Scene Context].
    You don't have to do anything on it - place it and leave it.
  2. Create Project Context in Resources folder.

After that, or if you already are using Zenject, start from here:

  1. Attach UniSwitcherInstaller to Project Context as a component.
    The component comes pre-filled with the default implementations of UniSwitcher components.
  2. Drag that component in the Mono Installers list in the Project Context component.
  3. Copy the following into a new file. This is where you write your Scene definitions!
    using UniSwitcher.Domain;
    
    public class Scene: BaseScene
    {
        ///////////////////////////////////////
        // WRITE YOUR SCENE DEFINITION HERE! //
        ///////////////////////////////////////
    
        private Scene(string rawValue) : base(rawValue)
        { }
    }
  4. In the file above, you will want to add the Scenes that are in your game like this; it should be a static property:
    public static Scene FirstScene => new Scene("Assets/Scenes/SampleScene.unity");

Change the Scene

To access the scene-changing ability of UniSwitcher, you need to use Switcher.

This class is an abstract class extending MonoBehaviour, so you can attach the script as a component on your GameObject.

public class SceneController: Switcher
{
    // This is a MonoBehaviour - you can use Unity event methods such as Start and Update
}

In this class, PerformSceneTransition, ChangeScene, and several other methods are provided.
To change the scene, call this:

PerformSceneTransition(
  ChangeScene(Scene.FirstScene)
);