-
Notifications
You must be signed in to change notification settings - Fork 0
Reverse Usage Lookup
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.
Call PerformSceneTransition on ChangeScene:
PerformSceneTransition(ChangeScene(new Scene("path/to/your/scene.unity")));Call PerformSceneTransition on AddScene:
PerformSceneTransition(AddScene(new Scene("path/to/your/scene.unity")));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;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;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");
...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()
);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.
Call HideProgressBar().
PerformSceneTransition(
AddScene(new Scene("path/to/your/scene.unity"))
.HideProgressBar()
);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 triggeringPerformSceneTransitionand the start of your transition effect, not the actual scene switch.
Append .Forget(Debug.LogException) to the call. These warnings are because PerformSceneTransition is an async, UniTask method.
Also, adding it is recommended since you can safely log exceptions should one get thrown.
PerformSceneTransition(new MyScene("path/to/scene.unity")).Forget(Debug.LogException);More reverse usage lookup is TODO.