using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class ButtonTools : MonoBehaviour {
    AsyncOperation async;
    bool _isNewLevelReady = false;
    private void Start()
    {
    }
    public void LoadScene(string _sceneToLoad)
    {
        SceneManager.LoadSceneAsync(_sceneToLoad);
    }
    public IEnumerator LoadSceneByTime(string _sceneToLoad, float _waitTime)
    {
        yield return new WaitForSeconds(_waitTime);
        SceneManager.LoadSceneAsync(_sceneToLoad);
    }
    public void OpenUrl(string url)
    {
        Application.OpenURL(url);
    }
    IEnumerator LoadBackgroundLevel(string _levelToLoad)
    {
        _isNewLevelReady = false;
        async =SceneManager.LoadSceneAsync(_levelToLoad);
        async.allowSceneActivation = false;
        yield return async;

    }
    public void StartLoadingBGLevel(string _sceneToLoad)
    {
       StartCoroutine( LoadBackgroundLevel(_sceneToLoad));
        //StartCoroutine(LoadBackgroundLevel(_sceneToLoad));
    }
    public void ActivateBGScene()
    {
        StartCoroutine(AllowAsyncActivation());
    }
    public void ExitApplication()
    {
        Application.Quit();
    }
    IEnumerator AllowAsyncActivation()
    {
        while (async.progress < 0.9f)
        {
            yield return new WaitForSeconds(0.1f);
        }
        async.allowSceneActivation = true;
        _isNewLevelReady = true;
      //  Debug.Log("LEVEL READY");
    }
    public AsyncOperation GetLevelAsync()
    {
        return this.async;
    }
    public void DesactivateObj()
    {

    }
}
