using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using MEC;
using UnityEngine.UI;

public class LookPhase : AbstractPhase
{
    private static LookPhase _instance;
    public static LookPhase Instance
    {
        get
        {
            return _instance;
        }
    }

    public GameObject Tutorial1;
    public PlayableDirector mPlayableDirector;
    public Animator mAnimator, mAnimatorFade;

    public string[] mAnimationHead;

    private void Awake()
    {
        _instance = this;
    }

    public override void BeginPhase()
    {

        Timing.RunCoroutine(BeginGame());


        MusicPlayer.Instance.PlayMusic("ggj18-talvez-final-1"); //musica timer
    }

    public override void EndPhase()
    {
        TimerGame.Instance.TimeClosedEvent -= EndPhase;
        ControlProgressManager.Instance.mCurrentPhase++;
        ControlProgressManager.Instance.RunningProgress();
    }

    IEnumerator<float> BeginGame()
    {
        yield return Timing.WaitForSeconds(5f);

        Tutorial1.SetActive(false);
        mAnimatorFade.Play("FadeOut");

        yield return Timing.WaitForSeconds(2f);

        TimerGame.Instance.TimeClosedEvent += EndPhase;
        TimerGame.Instance.StartTime(3); //voltar para 5
        mPlayableDirector.Play();
        mAnimator.gameObject.SetActive(true);
        mAnimator.Play(mAnimationHead[Random.Range(0, 6)]);
    }
}
