using UnityEngine;
using System.Collections;

public class MenuInitializer : MonoBehaviour
{
	public Canvas canvas;
	public MenuSection initialSection;
	public GameObject dialogPrefab;
	public AudioClip backButtonSound;

	public bool exitApp = false;

	void Awake ()
	{
		MenuHelper.Initialize (this.canvas, this.initialSection, this.dialogPrefab);
		MenuHelper.MenuClosed += MenuHelper_MenuClosed;
	}

	void MenuHelper_MenuClosed (object sender, System.EventArgs e)
	{
		if (this.exitApp == true) {
			Application.Quit ();
		}
	}

	void Update ()
	{
		if (Input.GetKeyDown (KeyCode.Escape)) {
			AudioManager2D.instance.PlaySound (this.backButtonSound);
			MenuHelper.OnBackPressed ();
		}
	}

	void OnDestroy ()
	{
		MenuHelper.MenuClosed -= MenuHelper_MenuClosed;
	}
}
