using UnityEngine;

using System.Collections.Generic;
using UnityEngine.SceneManagement;
using System.Collections;
using System;
using VirtuoseReality.Extension.AudioManager;

public class Application : MonoBehaviour
{
#region Scene Management

    private const string NAME_GAME_SCENE = "Main";

    public void LoadGameScene(bool isActiveScene, Action onComplete = null)
    {
        StartCoroutine(LoadScene(NAME_GAME_SCENE, isActiveScene, onComplete));
    }

    public void UnloadGameScene(Action onComplete = null)
    {
        StartCoroutine(UnloadScene(NAME_GAME_SCENE, onComplete));
    }

    private IEnumerator LoadScene(string sceneName, bool isActiveScene, Action onComplete = null)
    {
        AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive);
        while (!operation.isDone)
            yield return null;

        onComplete.Invoke();

        if (isActiveScene)
        {
            Scene scene = SceneManager.GetSceneByName(sceneName);
            SceneManager.SetActiveScene(scene);
        }

        yield return null;
    }

    private IEnumerator UnloadScene(string sceneName, Action onComplete = null)
    {
        AsyncOperation operation = SceneManager.UnloadSceneAsync(sceneName);
        while (!operation.isDone)
            yield return null;

        onComplete.Invoke();

        yield return null;
    }

#endregion

#region SoundManager

    [SerializeField]
    private SoundManagerToolSettings _soundSettings = null;

    private void Start()
    {
        SoundManager.PlaySound(SoundDataIDStatic.AMBIENT_MUSIC);
    }

#endregion
}
