Skip to content

Reverse Usage Lookup

Collapsed Plug edited this page Nov 28, 2021 · 15 revisions

First of all, follow the quickstart; The quickstart gets you ready to use UniSwitcher.
If you are having trouble, check if you have followed everything on that instructions.

This page assumes you have done that, and your IScene implementation is called Scene in your project.

Change the Scene to another

Call PerformSceneTransition on ChangeScene:

 PerformSceneTransition(ChangeScene(new Scene("path/to/your/scene.unity")));

Additively load a scene

Call PerformSceneTransition on AddScene:

PerformSceneTransition(AddScene(new Scene("path/to/your/scene.unity")));

Pass value to the destination scene

Put your data in the second argument - it will be available as an [Inject] variable for the scripts in the next Scene.

PerformSceneTransition(AddScene(new Scene("path/to/your/scene.unity"), new YourRandomData(12345)));

// In the scripts on the next Scene, if you write this, your data will appear in the property `_data`.
[Inject] private YourRandomData _data;

I want to playtest the Scene directly that requires data but it crashes

If you directly playtest the Scene that requires data from another Scene, you may experience an immediate crash.
The crash is because of the [Inject] attribute.
If you want to test a scene directly, use the [InjectOptional] attribute instead.

// This will prevent your Scene from crashing if playtested directly, but the `_data` will be `null.`
// You'll want to provide your test data somewhere instead.
[InjectOptional] private YourRandomData _data;

I don't want to type the path to my Scene every time!

You can add static members to your Scene class (the IScene implementation.)

public MyScene: IScene {
  public MyScene Scene1 => new MyScene("Assets/path/to/scene.unity");
  ...

Transition to the next Scene with a transition effect

For this to work, you must have a transition effect installed.
If you use the default UniSwitcherInstaller, you will automatically use the sample implementation of the UniSwitcher transition effect Assets/Plugins/UniSwitcher/Sample/Prefab/Transition Background.prefab.

You can even implement your own!!

After that, call WithTransitionEffect() on ChangeScene.

PerformSceneTransition(
    AddScene(new Scene("path/to/your/scene.unity"))
        .WithTransitionEffect()
);

Show Progress Bar

For this to work, you must implement a progress bar using ProgressDisplayController,
which must be referenced from the Switcher's sceneProgressBarController.

As long as it is referenced from the Switcher, the progress bar will automatically appear for all the transitions.

My progress bar is showing even on Additive scene load, and I don't want it

Call HideProgressBar().

PerformSceneTransition(
    AddScene(new Scene("path/to/your/scene.unity"))
        .HideProgressBar()
);

I want to delay the transition after triggering it

Use After on ChangeScene.

PerformSceneTransition(
    AddScene(new Scene("path/to/your/scene.unity"))
        .After(5) // after 5 seconds
);

[NOTE]
The interval you specify is the one between the time of triggering PerformSceneTransition and the start of your transition effect, not the actual scene switch.

More reverse usage lookup is TODO

Clone this wiki locally