# Load Screen Manager

Can be used with [**Initialization**](https://reddycat.gitbook.io/base-project-cube-doc/fundamentals/singletons/scene-system/initialization), used in [**SceneSystem**](https://reddycat.gitbook.io/base-project-cube-doc/fundamentals/singletons/scene-system).

## How it works

LoadScreenManager is singleton and it will exist between scenes. SceneSettuper will create it only in editor if it doesn't exist in scene after \_Loader.

LoadScreenManager creates instance of LoadScreen.cs object and destroys it on hide finished.\
You can combine different LoadScreen transitions (in and out).\
\
You need to use LoadScreenManager.ShowLoadScreen(type) \
and hide it when you don't need by LoadScreenManager.HideLoadScreen()\
\
Also you can create instance of load screen by LoadScreenManager.CreateLoadScreen(type),\
then setup it's fields and pass to LoadScreenManager.ShowLoadScreen(screen instance).\
\ <mark style="color:red;">**Note that if you created instance of load screen and didn't used it, you need manualy destroy it so avoid unused objects in memory.**</mark>

In [How To Use ](#how-to-use)will be examples how to work with SceneSystem transitions.

## How to use

add **`using Game.Core;`**

[**SceneSystem** ](https://reddycat.gitbook.io/base-project-cube-doc/fundamentals/singletons/scene-system)already uses it when you switch scene. You can load new scene with load screen manager like this:

```csharp
// last two arguments are in and out transitions
SceneSystem.Instance.LoadSceneSwitch(SceneSystem.GAME_SCENE, 
                                     SceneTypes.LevelScene, 
                                     LoadScreens.CutoutCube, 
                                     LoadScreens.FadeInOut);

// in this example cutout cube transition will be as in and out transitions
SceneSystem.Instance.LoadSceneSwitch(SceneSystem.GAME_SCENE, 
                                     SceneTypes.LevelScene, 
                                     LoadScreens.CutoutCube);



// if you want to override prefab settings on scene switch 
// (make it faster or change color):
// 1. create load screen instance by LoadScreenManager
var loadScreenOut = LoadScreenManager.CreateLoadScreen(LoadScreens.FadeInOut);
// 2. override some properties
loadScreenOut.TransitionOutTime = 3f;
// here I knwo that this is FadeInOut screen and I can change it's specific fields
loadScreenOut.CastTo<FadeInOutLoadScreen>().SetTransitionColor(Color.green);
// 3. call load scene switch and pass load screen instance,
// here I use transition out with custom parameters, but transition in will be with
// prefab default parameters and it's cutout cube transition
SceneSystem.Instance.LoadSceneSwitch(SceneSystem.GAME_SCENE, 
                                     SceneTypes.LevelScene, 
                                     LoadScreens.CutoutCube, 
                                     loadScreenOut);
// you can make the same as above with in and out transitions, so you need to create
// two instances and pass them to load scene switch method
```

{% hint style="info" %}
[**See** ](https://reddycat.gitbook.io/base-project-cube-doc/fundamentals/singletons/load-screen-manager/implementing-custom-load-screens)how to implement your custom load screens
{% endhint %}

## API

```csharp
/// Returns current instance if there is already or in scene
/// Doesn't create singleton object if there isn't
public static LoadScreenManager instance;

/// Is load screen manager active
public static bool IsActive;

/// Use this function to setup LoadScreen object before it will show/hide
/// Don't use LoadScreen.Show/Hide methods, you should call only LoadScreenManager for this!
public static LoadScreen GetActiveScreen();

/// returns Undefined state if no screen shown
public static LoadScreenState GetActiveScreenState();

/// Shows load screen
/// <param name="type">Type of load screen</param>
/// <param name="callback">callback on shown</param>
public static void ShowLoadScreen(LoadScreens type, UnityAction callback = null);

/// Shows load screen by created instance
/// <param name="loadScreenInstance">load screen instance that you got by <see cref="CreateInstance(LoadScreen)"/></param>
/// <param name="callback">callback on shown</param>
public static void ShowLoadScreen(LoadScreen loadScreenInstance, UnityAction callback = null);

/// Hides active load screen, if there if no screens callback will be invoked immediately
/// <param name="targetHideScreenTransition">Leave None to keep active screen hide transition, or set another</param>
public static void HideLoadScreen(UnityAction callback = null, LoadScreens targetHideScreenTransition = LoadScreens.None);

/// Hides active load screen, if there if no screens callback will be invoked immediately
/// <param name="targetHideScreenTransitionInstance">Must be load screen that you got by <see cref="CreateLoadScreen(LoadScreens)"/> or <see cref="Show(LoadScreen, UnityAction)"/></param>
public static LoadScreen HideLoadScreen(LoadScreen targetHideScreenTransitionInstance, UnityAction callback = null);

/// Use this only to pass for Show(LoadScreen, UnityAction) or Hide(UnityAction, LoadScreen)
/// Don't use LoadScreen Show/Hide methods, it must control LoadScreenManager!
/// returns Instance of load screen, you can freely change it timing before passing to LoadScreenManager
public static LoadScreen CreateLoadScreen(LoadScreens type)
```

Example of Show/Hide load screen runtime **Assets\\\_Examples\Load Screen\Example.scene**
