using System;
using UnityEngine;

public class VREventNotifierLook : VREventNotifier
{
	protected override void Start()
	{
		this.m_EyeRay = GameMain.Instance.OvrMgr.OvrCamera.EyeRay;
		this.LookTimeCountDownStop();
	}

	private void LookTimeCountDownStart()
	{
		this.m_fMaxTime = this.m_HitLookTarget.GetTimeOutTime();
		this.m_fNowTime = this.m_fMaxTime;
		this.m_EventText.SetGaugeRate(0f);
		this.m_EventText.Show(VREventText.TYPE.LOOK, this.m_HitLookTarget.GetEventName(), 0f);
	}

	private void LookTimeCountDownStop()
	{
		if (this.m_EventText != null)
		{
			this.m_EventText.Hide(VREventText.TYPE.LOOK);
		}
	}

	private void LookTimeOut()
	{
		Debug.Log("Look:StartScript");
		this.LookTimeCountDownStop();
		if (this.m_HitLookTarget != null)
		{
			this.m_HitLookTarget.StartScript();
			this.m_HitLookTarget = null;
		}
	}

	private void Update()
	{
		GameMain.Instance.OvrMgr.OvrCamera.HideDummyHand(OvrCamera.DUMMY_HAND.EVENT_GRAB);
		if (SceneVRCommunication.Instance == null || !SceneVRCommunication.Instance.IsFreeMode)
		{
			this.LookTimeCountDownStop();
			return;
		}
		this.m_HitLookTarget = null;
		if (GameMain.Instance.MainCamera.IsFadeOut())
		{
			this.m_HitBackLookTarget = null;
			if (object.ReferenceEquals(VREventNotifier.m_clSingle, this))
			{
				VREventNotifier.m_clSingle = null;
			}
			this.LookTimeCountDownStop();
			return;
		}
		if (this.m_EyeRay.RayCast(out this.m_hit, VREventNotifierLook.m_fMaxDistance, 2097152))
		{
			this.m_HitLookTarget = this.m_hit.transform.GetComponentInChildren<VREventTriggerLook>();
			if (this.m_HitLookTarget != null && !this.m_HitLookTarget.IsEnableEvent())
			{
				this.m_HitLookTarget = null;
			}
		}
		bool flag = false;
		if (GameMain.Instance.OvrMgr.OvrCamera.IsNoHandController && this.m_EyeRay.RayCast(out this.m_hit, VREventNotifierLook.m_fMaxDistance, 131072))
		{
			this.m_HitLookTarget = this.m_hit.transform.GetComponentInChildren<VREventTriggerGrab>();
			if (this.m_HitLookTarget != null && !this.m_HitLookTarget.IsEnableEvent())
			{
				this.m_HitLookTarget = null;
			}
			else
			{
				flag = true;
				this.m_vDummyGrabPos = this.m_hit.point;
			}
		}
		if (VREventNotifier.m_clSingle == null || object.ReferenceEquals(VREventNotifier.m_clSingle, this))
		{
			if (this.m_HitLookTarget != null && this.m_HitBackLookTarget == null)
			{
				this.m_HitLookTarget.OnEvnetCountDownEnter(base.gameObject);
				this.LookTimeCountDownStart();
				VREventNotifier.m_clSingle = this;
			}
			else if (this.m_HitLookTarget != null && this.m_HitBackLookTarget != null)
			{
				if (!object.ReferenceEquals(this.m_HitLookTarget, this.m_HitBackLookTarget))
				{
					this.m_HitBackLookTarget.OnEventCountDownExit(base.gameObject);
					this.LookTimeCountDownStop();
					this.m_HitLookTarget.OnEvnetCountDownEnter(base.gameObject);
					this.LookTimeCountDownStart();
				}
				VREventNotifier.m_clSingle = this;
				this.m_fNowTime -= Time.deltaTime;
				if (this.m_fNowTime <= 0f)
				{
					this.LookTimeOut();
					this.m_EventText.SetGaugeRate(1f);
				}
				else
				{
					this.m_EventText.SetGaugeRate(1f - this.m_fNowTime / this.m_fMaxTime);
				}
				if (flag)
				{
					GameMain.Instance.OvrMgr.OvrCamera.ShowDummyHand(OvrCamera.DUMMY_HAND.EVENT_GRAB, this.m_vDummyGrabPos, true);
				}
			}
			else if (this.m_HitLookTarget == null && this.m_HitBackLookTarget != null)
			{
				this.m_HitBackLookTarget.OnEventCountDownExit(base.gameObject);
				this.LookTimeCountDownStop();
				this.m_HitLookTarget = null;
				GameMain.Instance.OvrMgr.OvrCamera.HideDummyHand(OvrCamera.DUMMY_HAND.EVENT_GRAB);
				VREventNotifier.m_clSingle = null;
			}
		}
		this.m_HitBackLookTarget = this.m_HitLookTarget;
	}

	public static float m_fMaxDistance = 10f;

	public VREventText m_EventText;

	private RaycastHit m_hit;

	private VREventTrigger m_HitLookTarget;

	private VREventTrigger m_HitBackLookTarget;

	private float m_fMaxTime = 5f;

	private float m_fNowTime;

	private OvrEyeRay m_EyeRay;

	private Vector3 m_vDummyGrabPos;
}
