using FMODUnity;
using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;

public class MainMenu : MonoBehaviour
{
    public Animator cameraAnimator;

    public string firstLevelName = "Lvl2 1";

    private FMOD.Studio.EventInstance mainMenuMusic_fmodinstance;

    public FMODUnity.EventReference mainMenuMusic_unityRef;

    void Start()
    {
        cameraAnimator.Play("MainMenuCam");

        mainMenuMusic_fmodinstance = FMODUnity.RuntimeManager.CreateInstance(mainMenuMusic_unityRef);
        mainMenuMusic_fmodinstance.start();
    }

    public void p_MainMenu()
    {
        cameraAnimator.Play("MainMenuCam");
    }

    public void p_SettingsMenu()
    {
        cameraAnimator.Play("SettingsCam");
    }

    public void p_CreditsMenu()
    {
        cameraAnimator.Play("CreditsCam");
    }

    public void p_ControlsMenu()
    {
        cameraAnimator.Play("ControlsCam");
    }
    
    public void p_LevelsMenu()
    {
        cameraAnimator.Play("LevelsCam");
    }

    public void p_Quit()
    {
        Application.Quit();
    }

    public void p_PlayGame()
    {
        Time.timeScale = 1;

        StartMainMenuMusicTransition();
        StartCoroutine(MusicEnd(2.5f));
        StartCoroutine(StartTransition(1.75f));
    }

    public void ButtonSelectSound()
    {
        FMODUnity.RuntimeManager.PlayOneShot("event:/UI/Button_select");
    }
    public void ButtonPressSound()
    {
        FMODUnity.RuntimeManager.PlayOneShot("event:/UI/Button_press");
    }

    public IEnumerator MusicEnd(float time)
    {
        yield return new WaitForSeconds(time);
        StopMainMenuMusic();
    }
    public IEnumerator StartTransition(float time)
    {
        yield return new WaitForSeconds(time);
        cameraAnimator.Play("GameCam");
        //TransitionManager.instance.ChangeScene("Game");
        //TransitionManager.instance.ChangeScene("Lvl2");
        TransitionManager.instance.ChangeScene(firstLevelName);

    }
    public void StartMainMenuMusicTransition()
    {
        mainMenuMusic_fmodinstance.setParameterByName("MenuMusicEnding", 1);
    }
    public void StopMainMenuMusic()
    {
        mainMenuMusic_fmodinstance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
    }
}
