using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

public class VRDecideUseTouch : MonoBehaviour
{
	private void Update()
	{
		if (!this.m_IsUpdate)
		{
			return;
		}
		if (GameMain.Instance == null)
		{
			return;
		}
		if (this.m_ControllerR == null || this.m_ControllerL == null)
		{
			this.m_ControllerR = GameMain.Instance.OvrMgr.ovr_obj.right_controller.controller_buttons;
			this.m_ControllerL = GameMain.Instance.OvrMgr.ovr_obj.left_controller.controller_buttons;
		}
		if (this.m_ControllerR == null || this.m_ControllerL == null)
		{
			return;
		}
		bool isTouchControllerPress = false;
		isTouchControllerPress |= this.m_ControllerR.GetPress(AVRControllerButtons.BTN.VIRTUAL_L_CLICK);
		isTouchControllerPress |= this.m_ControllerL.GetPress(AVRControllerButtons.BTN.VIRTUAL_L_CLICK);
		bool flag = this.IsPressMouse() | Input.GetKey(KeyCode.Return);
		string text = string.Empty;
		if (isTouchControllerPress)
		{
			this.m_TotalGrabTime += Time.deltaTime;
			this.m_TextCountDown.gameObject.SetActive(true);
		}
		else if (flag && !isTouchControllerPress)
		{
			this.m_TotalGrabTime += Time.deltaTime;
			this.m_TextCountDown.gameObject.SetActive(true);
		}
		if (!isTouchControllerPress && !flag)
		{
			this.m_TotalGrabTime = 0f;
			this.m_TextCountDown.gameObject.SetActive(false);
		}
		if (flag != this.m_BeforeMousePress || isTouchControllerPress != this.m_BeforeTouchPress)
		{
			this.m_TotalGrabTime = 0f;
		}
		float num = this.m_MaxGrabTime - this.m_TotalGrabTime;
		num = ((num >= 0f) ? num : 0f);
		if (flag && !isTouchControllerPress)
		{
			text += "マウスとキーボードを使用します\n";
		}
		else if (isTouchControllerPress)
		{
			text += "Oculus Touch を使用します\n";
		}
		text += num.ToString("0.0");
		this.m_TextCountDown.text = text;
		if (this.m_MaxGrabTime < this.m_TotalGrabTime)
		{
			this.m_IsUpdate = false;
			string message = string.Empty;
			if (flag && !isTouchControllerPress)
			{
				message = "マウスとキーボードで移動や選択をします。";
			}
			else
			{
				message = "Oculus Touch を使用します。";
			}
			VRDialogMenu dialog = VRDialogMenu.CreateDialog();
			VRDialogMenu.TYPE_STYLE style = (VRDialogMenu.TYPE_STYLE)12;
			dialog.OpenDialog(message, style, delegate(VRDialogMenu.TYPE_STYLE type)
			{
				dialog.CloseDialog();
				if (type == VRDialogMenu.TYPE_STYLE.OK)
				{
					if (this.m_Callback != null)
					{
						this.m_Callback(isTouchControllerPress);
					}
					VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
				}
				else
				{
					VRCanvasManager.Instance.OpenVRDecideUseTouch(this.m_Callback);
				}
			});
		}
		this.m_BeforeMousePress = flag;
		this.m_BeforeTouchPress = isTouchControllerPress;
	}

	private bool IsPressMouse()
	{
		bool isHandPenMode = GameMain.Instance.OvrMgr.OvrCamera.IsHandPenMode;
		if (NInput.GetMouseButtonDown(0))
		{
			if (isHandPenMode)
			{
				this.m_IsClick = (this.m_BeforeHandModeClick = true);
			}
			else
			{
				this.m_IsClick = true;
			}
		}
		if (NInput.GetMouseButton(0) && this.m_BeforeHandModeClick && !isHandPenMode)
		{
			this.m_IsClick = false;
		}
		if (NInput.GetMouseButtonUp(0))
		{
			this.m_IsClick = false;
		}
		if (this.m_ControllerR.GetPressUp(AVRControllerButtons.BTN.VIRTUAL_L_CLICK) | this.m_ControllerL.GetPressUp(AVRControllerButtons.BTN.VIRTUAL_L_CLICK))
		{
			this.m_IsClick = false;
		}
		this.m_BeforeHandModeClick = isHandPenMode;
		return this.m_IsClick;
	}

	public void StartDecideController(UnityAction<bool> callback_is_oculus_touch)
	{
		this.m_Callback = callback_is_oculus_touch;
		this.m_IsUpdate = true;
		this.m_BeforeMousePress = false;
		this.m_BeforeTouchPress = false;
		this.m_BeforeHandModeClick = false;
		this.m_IsClick = false;
	}

	[SerializeField]
	[Tooltip("カウントダウン用テキストUI")]
	private Text m_TextCountDown;

	private AVRControllerButtons m_ControllerR;

	private AVRControllerButtons m_ControllerL;

	private float m_TotalGrabTime;

	private float m_MaxGrabTime = 3f;

	private UnityAction<bool> m_Callback;

	private bool m_IsUpdate;

	private bool m_BeforeMousePress;

	private bool m_BeforeTouchPress;

	private bool m_BeforePenMode;

	private bool m_IsMousePress;

	private bool m_BeforeHandModeClick;

	private bool m_IsClick;
}
