🌍Scene System

System that handles scene load operations

How it works

_Loader scene is Application enter point and holder of all persistant singletons, shows custom splash screen. for example GameResources (that contains information about skins and configs) can be here. But remember to use DontDestroyOnLoad(gameObject) so they will not disappear after scene load!

How to add new scenes

Simply create new scenes in project, add it to build settings, but leave _Loader at first as possble index = 0 (some SDKs requires to replace scenes on top of all project scenes -> then you need to leave _Loader after SDK scenes).

API

public static SceneSystem Instance;

public static Scene SingleActiveScene;
public static Scene SinglePreviousScene;

/// on/off logs from SceneSystem
public bool verboseLogs;

/// UnityAction, invokes when scene is full ready to be used
/// You can use it to enable AI or activate play timer and etc.
/// If loadScreen was - event executed on start of loadScreen disappear.
/// In all, this event invokes only when <see cref="Initialization"/> completed (if no initialization running - instantly as soon as scene loads)
public static UnityEvent OnSceneFullReady = new();
public static UnityEvent OnSingleModeSceneStartLoading = new();

// Use LoadScene to change scenes (with or without load screen transition)
public void LoadScene(); // and it's overrides
public void AdditiveScenesChange(); // and it's overrides

/// Iterates through scenes in hierarchy and sets as active if found
public void SetActiveScene(string withName);
public void ReloadActiveScene(bool async = true);

How to switch scene

Use SceneSystem.cs API. Scene system is MonoSingleton.

Simply call LoadScene(..) that has overrides (immediate, with loadScreen):

// immediate load
SceneSystem.Instance.LoadSceneSwitch("MainMenu");

// load with loadScreen
SceneSystem.Instance.LoadSceneSwitch("MainMenu", LoadScreens.FadeInOut);

If you want to load scenes additively -> call AdditiveScenesChange(..):

// immediate load
SceneSystem.Instance.AdditiveScenesChange(unloadScenes: null, 
            new string[] { "scene_1", "scene_2" });

// load with loadScreen
SceneSystem.Instance.AdditiveScenesChange(unloadScenes: null, 
            new string[] { "scene_1", "scene_2" }, 
            onLoadScreenShown: () => Debug.Log("+"), 
            LoadScreens.FadeInOut);

// unload scenes only
SceneSystem.Instance.AdditiveScenesChange(
            unloadScenes: new string[] { "scene_1", "scene_2" }, 
            loadScenes: null);

Learn more information how to implement custom load screens here.

You can find more examples in Assets\_Examples\Scene System\

Last updated