9 namespace HKI.Core.Scenes
20 [SerializeField] GameObject FaderGO = null;
25 [SerializeField] CanvasGroup FaderCanvasGroup = null;
30 [SerializeField] GameObject VisualsGO = null;
35 [SerializeField] GameObject InfoTextGO = null;
40 [SerializeField]
GameEvent LoadingSceneUnloadedEvent = null;
52 FaderCanvasGroup.alpha = 0.0f;
60 if (VisualsGO != null)
61 VisualsGO.SetActive(
true);
66 if (VisualsGO != null)
67 VisualsGO.SetActive(
false);
72 if(textLocalization == null)
74 Debug.LogError(
"(SceneLoaderController) you are trying to change the info text but the given textLocalization is null!)");
90 public void LoadScene(
string loadingScene,
string scene,
bool directLoad =
true,
float fadeInTime = 1.0f,
float fadeOutTime = 1.0f,
bool doFading =
true)
92 if(!DoesSceneExist(scene))
94 Debug.LogError(
"(SceneLoaderController) you are trying to load a scene that doesn't exist! (Maybe you need to add the scene to the build settings scenes!)");
99 StartCoroutine(SceneLoadingDirectly(scene, fadeInTime, fadeOutTime, doFading));
101 StartCoroutine(SceneLoadingWithLoadingScene(loadingScene, scene, fadeInTime, fadeOutTime, doFading));
110 if (!DoesSceneExist(scene))
112 Debug.LogError(
"(SceneLoader) you are trying to load a scene that doesn't exist! (Maybe you need to add the scene to the build settings scenes!)");
116 StartCoroutine(SceneLoadingAdditively(scene));
131 yield
return StartCoroutine(Fade(fadeInTime,
true));
133 yield
return SceneManager.LoadSceneAsync(scene, LoadSceneMode.Single);
136 yield
return StartCoroutine(Fade(fadeOutTime,
false));
151 yield
return StartCoroutine(Fade(fadeInTime,
true));
153 yield
return SceneManager.LoadSceneAsync(loadingScene, LoadSceneMode.Single);
161 yield
return StartCoroutine(Fade(fadeOutTime,
false));
164 yield
return SceneLoadingAdditively(scene);
166 yield
return new WaitForSecondsRealtime(1.0f);
169 yield
return StartCoroutine(Fade(fadeInTime,
true));
171 if (LoadingSceneUnloadedEvent != null)
172 LoadingSceneUnloadedEvent.
Raise();
176 yield
return SceneManager.UnloadSceneAsync(loadingScene);
179 yield
return StartCoroutine(Fade(fadeOutTime,
false));
189 yield
return SceneManager.LoadSceneAsync(scene, LoadSceneMode.Additive);
195 return !
string.IsNullOrEmpty(scene);
204 IEnumerator
Fade(
float fadingTime,
bool fadeIn)
206 float timeSinceFadingStart = 0.0f;
208 FaderCanvasGroup.alpha = fadeIn ? 0.0f : 1.0f;
210 while (timeSinceFadingStart < fadingTime)
212 timeSinceFadingStart += Time.unscaledDeltaTime;
215 FaderCanvasGroup.alpha = Mathf.Lerp(0.0f, 1.0f, timeSinceFadingStart / fadingTime);
217 FaderCanvasGroup.alpha = Mathf.Lerp(1.0f, 0.0f, timeSinceFadingStart / fadingTime);
222 FaderCanvasGroup.alpha = fadeIn ? 1.0f : 0.0f;
IEnumerator Fade(float fadingTime, bool fadeIn)
Coroutine implementation of fading.
void LoadSceneAdditively(string scene)
This function will load a scene to the existing scene additively.
bool DoesSceneExist(string scene)
This ScriptableObject contains as a container for all text localization information.
void Raise()
Calling this function will inform all registered listener that this event is raised.
string GetText(Language language)
This function returns the string in a specific language. If there is no localization element in the r...
void ChangeText(string text)
This class allows the use of the standard Unity UI Text component and the TextMeshPro component witho...
IEnumerator SceneLoadingWithLoadingScene(string loadingScene, string scene, float fadeInTime, float fadeOutTime, bool doFading)
Coroutine implementation of loading a new scene via a loading scene.
Special Variable enables the use of the SystemLanguage data type as a variable of the settings system...
IEnumerator SceneLoadingAdditively(string scene)
Coroutine implementation of loading a scene additively to another.
This is a ScriptableObject game event. It can be listen too and raised via code or within Unity Edito...
This MonoBehaviour controls scene changing and the blending of the fading overlay for scene transitio...
void LoadScene(string loadingScene, string scene, bool directLoad=true, float fadeInTime=1.0f, float fadeOutTime=1.0f, bool doFading=true)
This function is for switching from one scene to another.
void ChangInfoText(TextLocalization textLocalization, Language textLanguage)
IEnumerator SceneLoadingDirectly(string scene, float fadeInTime, float fadeOutTime, bool doFading)
Coroutine implementation of direct loading a new scene.