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

public class VRConfigMenu : MonoBehaviour
{
	private void Refresh()
	{
		if (GameMain.Instance == null)
		{
			return;
		}
		this.m_2DMouseRotSpeed.SetActive(false);
		this.m_2DMouseRotInverse.SetActive(false);
		this.m_2DPlaneMovement.SetActive(false);
		this.m_2DShowMan.SetActive(false);
		this.m_2DFieldOfView.SetActive(false);
		this.m_NonTouchPlaneMovement.SetActive(false);
		this.m_NonTouchMouseRotEnable.SetActive(false);
		this.m_NonTouchMouseRotSpeed.SetActive(false);
		this.m_ViveFloorHeight.SetActive(false);
		this.m_ViveUseSnapRotate.SetActive(false);
		this.m_ViveUseSnapRotateRate.SetActive(false);
		this.m_TouchUseSnapRotate.SetActive(false);
		this.m_TouchUseSnapRotateRate.SetActive(false);
		this.m_CommonEyeHeight.SetActive(true);
		this.m_CommonSittingHeight.SetActive(true);
		this.m_CommonCameraRotSpeed.SetActive(true);
		this.m_CommonCameraMoveSpeed.SetActive(true);
		GameMain.VRDeviceType vrdeviceTypeID = GameMain.Instance.VRDeviceTypeID;
		if (vrdeviceTypeID == GameMain.VRDeviceType.NON)
		{
			this.m_2DMouseRotSpeed.SetActive(true);
			this.m_2DMouseRotInverse.SetActive(true);
			this.m_2DPlaneMovement.SetActive(true);
			this.m_2DShowMan.SetActive(true);
			this.m_2DFieldOfView.SetActive(true);
		}
		else if (vrdeviceTypeID == GameMain.VRDeviceType.RIFT)
		{
			this.m_NonTouchPlaneMovement.SetActive(true);
			this.m_NonTouchMouseRotEnable.SetActive(true);
			this.m_NonTouchMouseRotSpeed.SetActive(true);
		}
		else if (vrdeviceTypeID == GameMain.VRDeviceType.FOVE)
		{
			this.m_NonTouchPlaneMovement.SetActive(true);
			this.m_NonTouchMouseRotEnable.SetActive(true);
			this.m_NonTouchMouseRotSpeed.SetActive(true);
		}
		else if (vrdeviceTypeID == GameMain.VRDeviceType.VIVE)
		{
			this.m_ViveFloorHeight.SetActive(true);
			this.m_ViveUseSnapRotate.SetActive(true);
			this.m_ViveUseSnapRotateRate.SetActive(true);
		}
		else
		{
			this.m_TouchUseSnapRotate.SetActive(true);
			this.m_TouchUseSnapRotateRate.SetActive(true);
		}
		this.SetValue_Slider(this.m_CommonEyeHeight, 1.5f, 1.8f, GameMain.Instance.CMSystem.VRCameraHeightStand);
		this.SetValue_Slider(this.m_CommonSittingHeight, 0.7f, 1f, GameMain.Instance.CMSystem.VRCameraHeightSit);
		this.SetValue_Slider(this.m_CommonCameraRotSpeed, 0f, 1f, GameMain.Instance.CMSystem.VRCameraRotSpeedKey);
		this.SetValue_Slider(this.m_CommonCameraMoveSpeed, 0f, 1f, GameMain.Instance.CMSystem.VRCameraMoveSpeedKey);
		this.SetValue_Slider(this.m_NonTouchMouseRotSpeed, 0f, 1f, GameMain.Instance.CMSystem.VRCameraRotSpeedMouse);
		this.SetValue_Slider(this.m_2DMouseRotSpeed, 0f, 1f, GameMain.Instance.CMSystem.VRCameraRotSpeedMouse);
		this.SetValue_Slider(this.m_2DFieldOfView, 30f, 60f, GameMain.Instance.CMSystem.VRCameraFov);
		this.SetValue_Slider(this.m_ViveUseSnapRotateRate, 10f, 80f, (float)GameMain.Instance.CMSystem.OvrUseSnapRotateRate);
		this.SetValue_Slider(this.m_TouchUseSnapRotateRate, 10f, 80f, (float)GameMain.Instance.CMSystem.OvrUseSnapRotateRate);
		bool flag = GameMain.Instance.CMSystem.VRCameraPlaneMove;
		this.SetValue_ToggleButton(this.m_2DPlaneMovement, new bool[]
		{
			flag,
			!flag
		});
		flag = GameMain.Instance.CMSystem.VRCamRotDownUp;
		this.SetValue_ToggleButton(this.m_2DMouseRotInverse, new bool[]
		{
			flag,
			!flag
		});
		flag = GameMain.Instance.CMSystem.VRManShow;
		this.SetValue_ToggleButton(this.m_2DShowMan, new bool[]
		{
			flag,
			!flag
		});
		flag = GameMain.Instance.CMSystem.VRCameraPlaneMove;
		this.SetValue_ToggleButton(this.m_NonTouchPlaneMovement, new bool[]
		{
			flag,
			!flag
		});
		flag = GameMain.Instance.CMSystem.OvrMouseRot;
		this.SetValue_ToggleButton(this.m_NonTouchMouseRotEnable, new bool[]
		{
			flag,
			!flag
		});
		flag = (GameMain.Instance.CMSystem.OvrCameraHeightType == CMSystem.OVR_CAM_HEIGHT_TYPE.REAL);
		this.SetValue_ToggleButton(this.m_ViveFloorHeight, new bool[]
		{
			flag,
			!flag
		});
		flag = GameMain.Instance.CMSystem.OvrUseSnapRotate;
		this.SetValue_ToggleButton(this.m_ViveUseSnapRotate, new bool[]
		{
			flag,
			!flag
		});
		this.SetValue_ToggleButton(this.m_TouchUseSnapRotate, new bool[]
		{
			flag,
			!flag
		});
		VRConfigMenu.SetEvent_Slider(this.m_CommonEyeHeight, delegate(float value)
		{
			GameMain.Instance.CMSystem.VRCameraHeightStand = value;
		});
		VRConfigMenu.SetEvent_Slider(this.m_CommonSittingHeight, delegate(float value)
		{
			GameMain.Instance.CMSystem.VRCameraHeightSit = value;
		});
		VRConfigMenu.SetEvent_Slider(this.m_CommonCameraRotSpeed, delegate(float value)
		{
			GameMain.Instance.CMSystem.VRCameraRotSpeedKey = value;
		});
		VRConfigMenu.SetEvent_Slider(this.m_CommonCameraMoveSpeed, delegate(float value)
		{
			GameMain.Instance.CMSystem.VRCameraMoveSpeedKey = value;
		});
		VRConfigMenu.SetEvent_Slider(this.m_ViveUseSnapRotateRate, delegate(float value)
		{
			GameMain.Instance.CMSystem.OvrUseSnapRotateRate = (int)value;
		});
		VRConfigMenu.SetEvent_Slider(this.m_TouchUseSnapRotateRate, delegate(float value)
		{
			GameMain.Instance.CMSystem.OvrUseSnapRotateRate = (int)value;
		});
		VRConfigMenu.SetEvent_Slider(this.m_NonTouchMouseRotSpeed, delegate(float value)
		{
			GameMain.Instance.CMSystem.VRCameraRotSpeedMouse = value;
		});
		VRConfigMenu.SetEvent_Slider(this.m_2DMouseRotSpeed, delegate(float value)
		{
			GameMain.Instance.CMSystem.VRCameraRotSpeedMouse = value;
		});
		VRConfigMenu.SetEvent_Slider(this.m_2DFieldOfView, delegate(float value)
		{
			GameMain.Instance.CMSystem.VRCameraFov = value;
		});
		GameObject 2DMouseRotInverse = this.m_2DMouseRotInverse;
		UnityAction[] array = new UnityAction[2];
		array[0] = delegate()
		{
			GameMain.Instance.CMSystem.VRCamRotDownUp = true;
		};
		array[1] = delegate()
		{
			GameMain.Instance.CMSystem.VRCamRotDownUp = false;
		};
		VRConfigMenu.SetEvent_ToggleButton(2DMouseRotInverse, array);
		GameObject 2DPlaneMovement = this.m_2DPlaneMovement;
		UnityAction[] array2 = new UnityAction[2];
		array2[0] = delegate()
		{
			GameMain.Instance.CMSystem.VRCameraPlaneMove = true;
		};
		array2[1] = delegate()
		{
			GameMain.Instance.CMSystem.VRCameraPlaneMove = false;
		};
		VRConfigMenu.SetEvent_ToggleButton(2DPlaneMovement, array2);
		GameObject 2DShowMan = this.m_2DShowMan;
		UnityAction[] array3 = new UnityAction[2];
		array3[0] = delegate()
		{
			GameMain.Instance.CMSystem.VRManShow = true;
		};
		array3[1] = delegate()
		{
			GameMain.Instance.CMSystem.VRManShow = false;
		};
		VRConfigMenu.SetEvent_ToggleButton(2DShowMan, array3);
		GameObject viveUseSnapRotate = this.m_ViveUseSnapRotate;
		UnityAction[] array4 = new UnityAction[2];
		array4[0] = delegate()
		{
			GameMain.Instance.CMSystem.OvrUseSnapRotate = true;
		};
		array4[1] = delegate()
		{
			GameMain.Instance.CMSystem.OvrUseSnapRotate = false;
		};
		VRConfigMenu.SetEvent_ToggleButton(viveUseSnapRotate, array4);
		GameObject touchUseSnapRotate = this.m_TouchUseSnapRotate;
		UnityAction[] array5 = new UnityAction[2];
		array5[0] = delegate()
		{
			GameMain.Instance.CMSystem.OvrUseSnapRotate = true;
		};
		array5[1] = delegate()
		{
			GameMain.Instance.CMSystem.OvrUseSnapRotate = false;
		};
		VRConfigMenu.SetEvent_ToggleButton(touchUseSnapRotate, array5);
		GameObject nonTouchPlaneMovement = this.m_NonTouchPlaneMovement;
		UnityAction[] array6 = new UnityAction[2];
		array6[0] = delegate()
		{
			GameMain.Instance.CMSystem.VRCameraPlaneMove = true;
		};
		array6[1] = delegate()
		{
			GameMain.Instance.CMSystem.VRCameraPlaneMove = false;
		};
		VRConfigMenu.SetEvent_ToggleButton(nonTouchPlaneMovement, array6);
		GameObject nonTouchMouseRotEnable = this.m_NonTouchMouseRotEnable;
		UnityAction[] array7 = new UnityAction[2];
		array7[0] = delegate()
		{
			GameMain.Instance.CMSystem.OvrMouseRot = true;
		};
		array7[1] = delegate()
		{
			GameMain.Instance.CMSystem.OvrMouseRot = false;
		};
		VRConfigMenu.SetEvent_ToggleButton(nonTouchMouseRotEnable, array7);
		GameObject viveFloorHeight = this.m_ViveFloorHeight;
		UnityAction[] array8 = new UnityAction[2];
		array8[0] = delegate()
		{
			GameMain.Instance.CMSystem.OvrCameraHeightType = CMSystem.OVR_CAM_HEIGHT_TYPE.REAL;
		};
		array8[1] = delegate()
		{
			GameMain.Instance.CMSystem.OvrCameraHeightType = CMSystem.OVR_CAM_HEIGHT_TYPE.VR;
		};
		VRConfigMenu.SetEvent_ToggleButton(viveFloorHeight, array8);
	}

	private static void SetEvent_Slider(GameObject SliderObject, UnityAction<float> callback)
	{
		Slider componentInChildren = SliderObject.GetComponentInChildren<Slider>();
		componentInChildren.onValueChanged.RemoveAllListeners();
		componentInChildren.onValueChanged.AddListener(callback);
	}

	private static void SetEvent_ToggleButton(GameObject ButtonParentObject, params UnityAction[] callbacks)
	{
		Button[] buttons = ButtonParentObject.GetComponentsInChildren<Button>();
		for (int i = 0; i < buttons.Length; i++)
		{
			Button button = buttons[i];
			UnityAction callback = null;
			if (callbacks.Length > i)
			{
				callback = callbacks[i];
			}
			else
			{
				Debug.LogWarning("[VRConfig]フラグの数がイベントの数より少ない");
			}
			button.onClick.RemoveAllListeners();
			button.onClick.AddListener(delegate()
			{
				ColorBlock colors;
				for (int j = 0; j < buttons.Length; j++)
				{
					colors = buttons[j].colors;
					colors.normalColor = Color.white * 0.66f;
					buttons[j].colors = colors;
				}
				colors = button.colors;
				colors.normalColor = Color.white;
				button.colors = colors;
				callback();
			});
		}
	}

	private void SetValue_Slider(GameObject SliderObject, float min, float max, float value)
	{
		Slider componentInChildren = SliderObject.GetComponentInChildren<Slider>();
		componentInChildren.minValue = min;
		componentInChildren.maxValue = max;
		componentInChildren.value = value;
	}

	private void SetValue_ToggleButton(GameObject ButtonParentObject, params bool[] selecteds)
	{
		Button[] componentsInChildren = ButtonParentObject.GetComponentsInChildren<Button>();
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			Button button = componentsInChildren[i];
			bool flag = false;
			if (selecteds.Length > i)
			{
				flag = selecteds[i];
			}
			else
			{
				Debug.LogWarning("[VRConfig]フラグの数がボタンの数より少ない");
			}
			ColorBlock colors = componentsInChildren[i].colors;
			colors.normalColor = ((!flag) ? (Color.white * 0.66f) : Color.white);
			componentsInChildren[i].colors = colors;
		}
	}

	private void OnEnable()
	{
		this.Refresh();
	}

	[SerializeField]
	private GameObject m_CommonEyeHeight;

	[SerializeField]
	private GameObject m_CommonSittingHeight;

	[SerializeField]
	private GameObject m_CommonCameraRotSpeed;

	[SerializeField]
	private GameObject m_CommonCameraMoveSpeed;

	[SerializeField]
	private GameObject m_ViveFloorHeight;

	[SerializeField]
	private GameObject m_ViveUseSnapRotate;

	[SerializeField]
	private GameObject m_ViveUseSnapRotateRate;

	[SerializeField]
	private GameObject m_TouchUseSnapRotate;

	[SerializeField]
	private GameObject m_TouchUseSnapRotateRate;

	[SerializeField]
	private GameObject m_NonTouchPlaneMovement;

	[SerializeField]
	private GameObject m_NonTouchMouseRotEnable;

	[SerializeField]
	private GameObject m_NonTouchMouseRotSpeed;

	[SerializeField]
	private GameObject m_2DMouseRotSpeed;

	[SerializeField]
	private GameObject m_2DMouseRotInverse;

	[SerializeField]
	private GameObject m_2DPlaneMovement;

	[SerializeField]
	private GameObject m_2DShowMan;

	[SerializeField]
	private GameObject m_2DFieldOfView;
}
