[HOWTO] How To Use Different Loading Screens With Scene Transition Manager
Posted: Fri Feb 19, 2021 4:09 pm
Pixel Crushers assets share a save system.
This save system can use an optional scene transition manager -- for example, to fade out the old scene, optionally show an intermediate loading scene, and then fade in the new scene. The scene transition manager should be on the same GameObject as the Save System component, which means it survives scene changes, allowing it to manage the transition from the old scene to the new scene.
SceneTransitionManager is an abstract class; you can implement it however you like. The default implementation is called StandardSceneTransitionManager. On your StandardSceneTransitionManager, you can set a single optional loading scene name.
If you want to change the loading scene on a per-scene basis, or even select a random loading scene, you can add a script like this to each scene:
If you want more control, the methods in StandardSceneTransitionManager are virtual, so you can override them to do whatever you want.
This save system can use an optional scene transition manager -- for example, to fade out the old scene, optionally show an intermediate loading scene, and then fade in the new scene. The scene transition manager should be on the same GameObject as the Save System component, which means it survives scene changes, allowing it to manage the transition from the old scene to the new scene.
SceneTransitionManager is an abstract class; you can implement it however you like. The default implementation is called StandardSceneTransitionManager. On your StandardSceneTransitionManager, you can set a single optional loading scene name.
If you want to change the loading scene on a per-scene basis, or even select a random loading scene, you can add a script like this to each scene:
SetRandomLoadingScreen.cs
Code: Select all
using UnityEngine;
using PixelCrushers;
public class SetRandomLoadingScreen : MonoBehaviour
{
public string[] loadingSceneNames; //<-- Set scene names in inspector.
private void Start()
{
string loadingSceneName = loadingSceneNames[Random.Range(0, loadingSceneNames.Length)];
(SaveSystem.sceneTransitionManager as StandardSceneTransitionManager).loadingSceneName = loadingSceneName;
}
}