using UnityEngine;
using UnityEngine.SceneManagement;

public class SceneLoader : MonoBehaviour
{
    public static SceneLoader Instance { get; private set; }

    private AsyncOperation loadingOperation;

    private void Awake()
    {
        if (Instance && Instance != this)
        {
            Destroy(gameObject);
            return;
        }

        Instance = this;
    }

    public void LoadScene(string sceneName)
    {
        Debug.Log($"SceneLoader.LoadScene('{sceneName}') called!\n{System.Environment.StackTrace}");
        loadingOperation = SceneManager.LoadSceneAsync(sceneName);
        loadingOperation.allowSceneActivation = false;
    }

    public void OpenLoadedScene()
    {
        Debug.Log($"SceneLoader.OpenLoadedScene() called!\n{System.Environment.StackTrace}");
        if (loadingOperation != null)
        {
            loadingOperation.allowSceneActivation = true;
        }
    }
}