using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ScreenWipe : MonoBehaviour
{
    public static ScreenWipe Instance = null;
    Animator m_Animator;
    bool fwd = true;

    System.Action ScreenWiped;
    System.Action ScreenCleared;
    System.Action callback;
    // Start is called before the first frame update
    void Awake()
    {
        m_Animator = GetComponent<Animator>();
        Instance = this;
        gameObject.SetActive(false);
    }

    public void BeginWipe(bool fwd, System.Action _callback )
    {
        callback = _callback;
        if (fwd)
        {
            gameObject.SetActive(true);
            m_Animator.Play("ScreenWipe", -1, 0.0f);
            fwd = true;
        }
        else
        {
            fwd = false;
            m_Animator.Play("ReverseWipe", -1, 0.0f);

        }
    }

    public void FinishWipe()
    {
        if (fwd)
        {
            if (ScreenWiped != null)
                ScreenWiped();
        }
        else
        {
            if (ScreenCleared != null)
                ScreenCleared();
            gameObject.SetActive(false);
            m_Animator.playbackTime = 0.0f;
        }
        if (callback != null)
            callback();
        callback = null;
    }
}
