2023-08-22 15:41:12 +03:00
using QFSW.QC ;
using System.Collections ;
2023-07-24 16:38:13 +03:00
using System.Collections.Generic ;
using UnityEngine ;
using UnityEngine.SceneManagement ;
namespace BNG {
public class SceneLoader : MonoBehaviour {
[Tooltip("The Unity 'LoadSceneMode' method of loading the scene (In most cases should be 'Single'). ")]
public LoadSceneMode loadSceneMode = LoadSceneMode . Single ;
[Tooltip("If true, the ScreenFader component will fade the screen to black before loading a level.")]
public bool UseSceenFader = true ;
[Tooltip("Wait this long in seconds before attempting to load the scene. Useful if you need to fade the screen out before attempting to load the level.")]
public float ScreenFadeTime = 0.5f ;
ScreenFader sf ;
private string _loadSceneName = string . Empty ;
public void LoadScene ( string SceneName ) {
_loadSceneName = SceneName ;
if ( UseSceenFader ) {
StartCoroutine ( "FadeThenLoadScene" ) ;
}
else {
SceneManager . LoadScene ( _loadSceneName , loadSceneMode ) ;
}
}
public IEnumerator FadeThenLoadScene ( ) {
if ( UseSceenFader ) {
if ( sf = = null ) {
sf = FindObjectOfType < ScreenFader > ( ) ;
// May not have found anything
if ( sf ! = null ) {
sf . DoFadeIn ( ) ;
}
}
}
if ( ScreenFadeTime > 0 ) {
yield return new WaitForSeconds ( ScreenFadeTime ) ;
}
SceneManager . LoadScene ( _loadSceneName , loadSceneMode ) ;
}
}
}