using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

public class VRSelectorMenu : MonoBehaviour
{
	public static VRSelectorMenu CreateSelector()
	{
		if (VRSelectorMenu.m_Instance == null)
		{
			VRSelectorMenu.m_Instance = UnityEngine.Object.FindObjectOfType<VRSelectorMenu>();
		}
		return VRSelectorMenu.m_Instance;
	}

	private void Start()
	{
		if (VRSelectorMenu.m_Instance != null)
		{
		}
		VRSelectorMenu.m_Instance = this;
		base.gameObject.SetActive(false);
	}

	public void Open()
	{
		for (int i = 0; i < this.m_ParentButtonArea.childCount; i++)
		{
			this.m_ParentButtonArea.GetChild(i).gameObject.SetActive(false);
		}
		VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.NONE);
		UICanvasFade component = base.GetComponent<UICanvasFade>();
		component.FadeIn();
	}

	public void Close(UnityAction callback = null)
	{
		UICanvasFade component = base.GetComponent<UICanvasFade>();
		component.FadeOut(component.fadeTime, component.isTimeScaling, callback);
		VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
	}

	public void SelectStart(List<VRChoices.SelectPair> choices, UnityAction<VRChoices.SelectPair> callback)
	{
		VRSelectorMenu.m_Instance.Open();
		for (int i = 0; i < choices.Count; i++)
		{
			VRChoices.SelectPair choice = choices[i];
			GameObject gameObject;
			if (this.m_ParentButtonArea.childCount > i)
			{
				gameObject = this.m_ParentButtonArea.GetChild(i).gameObject;
			}
			else
			{
				gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_PrefabSelectorButton);
				gameObject.transform.SetParent(this.m_ParentButtonArea, false);
			}
			gameObject.SetActive(true);
			Button component = gameObject.GetComponent<Button>();
			Text componentInChildren = gameObject.GetComponentInChildren<Text>();
			component.onClick.RemoveAllListeners();
			componentInChildren.text = choice.strText;
			if (callback != null)
			{
				component.onClick.AddListener(delegate()
				{
					callback(choice);
				});
			}
		}
	}

	public void SetSelectType(VRChoices.SelectPair.Type type)
	{
		if (type == VRChoices.SelectPair.Type.Look)
		{
			if (this.m_ImageSelectLook)
			{
				this.m_ImageSelectLook.SetActive(true);
			}
			if (this.m_ImageSelectTouch)
			{
				this.m_ImageSelectTouch.SetActive(false);
			}
			if (this.m_ParentButtonArea)
			{
				this.m_ParentButtonArea.gameObject.SetActive(false);
			}
		}
		else if (type == VRChoices.SelectPair.Type.Touch)
		{
			if (this.m_ImageSelectLook)
			{
				this.m_ImageSelectLook.SetActive(false);
			}
			if (this.m_ImageSelectTouch)
			{
				this.m_ImageSelectTouch.SetActive(true);
			}
			if (this.m_ParentButtonArea)
			{
				this.m_ParentButtonArea.gameObject.SetActive(false);
			}
		}
		else if (type == VRChoices.SelectPair.Type.Text)
		{
			if (this.m_ImageSelectLook)
			{
				this.m_ImageSelectLook.SetActive(false);
			}
			if (this.m_ImageSelectTouch)
			{
				this.m_ImageSelectTouch.SetActive(false);
			}
			if (this.m_ParentButtonArea)
			{
				this.m_ParentButtonArea.gameObject.SetActive(true);
			}
		}
	}

	public void SelectFinalize(UnityAction callback = null)
	{
		this.Close(callback);
	}

	private static VRSelectorMenu m_Instance;

	[SerializeField]
	private RectTransform m_ParentButtonArea;

	[SerializeField]
	private GameObject m_PrefabSelectorButton;

	[SerializeField]
	[Tooltip("見て決めるタイプの選択肢の説明イメージ")]
	private GameObject m_ImageSelectLook;

	[SerializeField]
	[Tooltip("触って決めるタイプの選択肢の説明イメージ")]
	private GameObject m_ImageSelectTouch;
}
