using System;
using System.Collections;
using System.IO;
using UnityEngine;

public class VRMiniGameSetup : MonoBehaviour
{
	public VRMiniGameGaugeeManager GaugeManager
	{
		get
		{
			return this.m_GaugeManager;
		}
	}

	public AVRControllerButtons VRController
	{
		get
		{
			return this.m_Controller;
		}
	}

	public bool Is2DMode
	{
		get
		{
			return this.m_Is2DMode;
		}
	}

	public OvrCamera UseCamera
	{
		get
		{
			return this.m_UseCamera;
		}
	}

	private IEnumerator Start()
	{
		while (SceneVRCommunication.Instance == null)
		{
			yield return null;
		}
		SceneVRCommunication.VR_TIME nowTime = SceneVRCommunication.Instance.GetNowTime();
		if (nowTime == SceneVRCommunication.VR_TIME.NIGHT)
		{
			if (this.m_MiniGameType == VRMiniGameManager.VRMiniGameType.Wanage)
			{
				GameMain.Instance.BgMgr.ChangeBg("Villa_Farm_Night");
			}
			else if (this.m_MiniGameType == VRMiniGameManager.VRMiniGameType.Darts)
			{
				GameMain.Instance.BgMgr.ChangeBg("Villa_BedRoom_Night");
			}
		}
		else if (this.m_MiniGameType == VRMiniGameManager.VRMiniGameType.Wanage)
		{
			GameMain.Instance.BgMgr.ChangeBg("Villa_Farm");
		}
		else if (this.m_MiniGameType == VRMiniGameManager.VRMiniGameType.Darts)
		{
			GameMain.Instance.BgMgr.ChangeBg("Villa_BedRoom");
		}
		while (GameMain.Instance.OvrMgr == null)
		{
			yield return null;
		}
		while (VRMiniGameManager.Instance == null)
		{
			yield return null;
		}
		GameMain.Instance.MainCamera.FadeIn(0.5f, false, null, true, true, default(Color));
		while (GameMain.Instance.MainCamera.IsFadeProc())
		{
			yield return null;
		}
		this.m_BGMName = Path.ChangeExtension(this.m_BGMName, "ogg");
		GameMain.Instance.SoundMgr.PlayBGM(this.m_BGMName, 0.5f, true);
		this.m_UseCamera = GameMain.Instance.OvrMgr.OvrCamera;
		yield return null;
		this.m_UseCamera.ForceHideUI(true);
		if (this.m_PlayerPosition)
		{
			Vector3 position = this.m_PlayerPosition.position;
			Quaternion rotation = this.m_PlayerPosition.rotation;
			position = new Vector3(position.x, this.m_UseCamera.GetHeightStandAndSit(CameraMain.STAND_SIT.STAND), position.z);
			this.m_UseCamera.SetPos(position);
			this.m_UseCamera.SetRotation(rotation.eulerAngles);
		}
		if (this.m_MaidPosition)
		{
			Vector3 position2 = this.m_MaidPosition.position;
			GameMain.Instance.CharacterMgr.SetCharaAllPos(position2);
			Vector3 charaAllRot = new Vector3(0f, Quaternion.LookRotation(this.m_PlayerPosition.position - position2).eulerAngles.y, 0f);
			GameMain.Instance.CharacterMgr.SetCharaAllRot(charaAllRot);
		}
		this.m_Is2DMode = false;
		GameMain.VRDeviceType device = GameMain.Instance.VRDeviceTypeID;
		if (device == GameMain.VRDeviceType.NON || device == GameMain.VRDeviceType.RIFT || device == GameMain.VRDeviceType.FOVE)
		{
			this.m_Is2DMode = true;
		}
		VRMiniGameManager.Instance.Init(this.m_MiniGameType);
		if (this.m_DecideHandUIPosition && this.m_ScoreBoardUIPosition)
		{
			VRMiniGameManager.Instance.StartRightLeftHand(this.m_DecideHandUIPosition.position, this.m_DecideHandUIPosition.rotation, delegate(AVRController hand)
			{
				if (hand != null)
				{
					this.m_Controller = hand.VRControllerButtons;
				}
				else
				{
					VRMiniGameManager.Instance.VRController = this.m_Controller;
				}
				VRMiniGameManager.Instance.CreateScoreBoard(this.m_ScoreBoardUIPosition.position, this.m_ScoreBoardUIPosition.rotation);
				for (int i = 0; i < this.m_GoEnableObjects.Length; i++)
				{
					if (this.m_GoEnableObjects[i] != null)
					{
						this.m_GoEnableObjects[i].SetActive(true);
					}
				}
			});
		}
		yield return null;
		this.m_GaugeManager.ChangeDeviceMode(device);
		this.m_GaugeManager.Stop();
		this.m_GaugeManager.enabledMouseClickEvent = true;
		yield break;
	}

	private void Update()
	{
		if (this.m_Is2DMode && this.m_Controller != null && this.m_UseCamera != null && this.m_UseCamera.m_goCenterEye != null)
		{
			this.m_Controller.transform.position = this.m_UseCamera.m_goCenterEye.transform.position + this.m_UseCamera.m_goCenterEye.transform.forward * 0.2f;
			this.m_Controller.transform.rotation = Quaternion.LookRotation(this.m_Controller.transform.position - this.m_UseCamera.m_goCenterEye.transform.position);
		}
	}

	[SerializeField]
	[Tooltip("主人公の位置")]
	private Transform m_PlayerPosition;

	[SerializeField]
	[Tooltip("メイドの位置")]
	private Transform m_MaidPosition;

	[SerializeField]
	[Tooltip("利き手を決めるUIの位置")]
	private Transform m_DecideHandUIPosition;

	[SerializeField]
	[Tooltip("スコアボードUIの位置")]
	private Transform m_ScoreBoardUIPosition;

	[SerializeField]
	[Tooltip("ミニゲーム種類")]
	private VRMiniGameManager.VRMiniGameType m_MiniGameType;

	[SerializeField]
	[Tooltip("2D用ゲージマネージャー")]
	private VRMiniGameGaugeeManager m_GaugeManager;

	[SerializeField]
	[Tooltip("利き手が決定した直後に有効化するゲームオブジェクト")]
	private GameObject[] m_GoEnableObjects;

	[SerializeField]
	[Tooltip("ミニゲームに使用するコントローラ")]
	private AVRControllerButtons m_Controller;

	private string m_BGMName = "BGM_vr0007";

	private bool m_Is2DMode;

	private OvrCamera m_UseCamera;
}
