using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using UnityEngine;

[ExecuteInEditMode]
[AddComponentMenu("NGUI/UI/NGUI Event System (UICamera)")]
[RequireComponent(typeof(Camera))]
public class UICamera : MonoBehaviour
{
	[Obsolete("Use new OnDragStart / OnDragOver / OnDragOut / OnDragEnd events instead")]
	public bool stickyPress
	{
		get
		{
			return true;
		}
	}

	public static Ray currentRay
	{
		get
		{
			return (!(UICamera.currentCamera != null) || UICamera.currentTouch == null) ? default(Ray) : UICamera.currentCamera.ScreenPointToRay(UICamera.currentTouch.pos);
		}
	}

	[Obsolete("Use delegates instead such as UICamera.onClick, UICamera.onHover, etc.")]
	public static GameObject genericEventHandler
	{
		get
		{
			return UICamera.mGenericHandler;
		}
		set
		{
			UICamera.mGenericHandler = value;
		}
	}

	private bool handlesEvents
	{
		get
		{
			return UICamera.eventHandler == this;
		}
	}

	public Camera cachedCamera
	{
		get
		{
			if (this.mCam == null)
			{
				this.mCam = base.GetComponent<Camera>();
			}
			return this.mCam;
		}
	}

	public bool Hover
	{
		get
		{
			return this.m_bHover;
		}
		private set
		{
			this.m_bHover = value;
		}
	}

	public bool EnableProcess
	{
		get
		{
			return this.m_bProcessEnable;
		}
		set
		{
			this.m_bProcessEnable = value;
		}
	}

	public void SetOvrVirtualMousePos(bool f_bHandL, Vector3 v)
	{
		v.x = Mathf.Min(Mathf.Max(v.x, 3f), 1277f);
		v.y = Mathf.Min(Mathf.Max(v.y, 3f), 717f);
		v.z = 0f;
		this.m_vVirtualMousePos[(!f_bHandL) ? 1 : 0] = v;
	}

	public Vector3 GetOvrVirtualMousePos(bool f_bHandL)
	{
		return this.m_vVirtualMousePos[(!f_bHandL) ? 1 : 0];
	}

	public Vector3 GetOvrVirtualMouseCurrentSidePos()
	{
		return this.m_vVirtualMousePos[(int)this.m_eCurrentCursorSide];
	}

	public void CreateVirtualCursorObj()
	{
		if (this.m_goVirtualCursor != null)
		{
			this.m_goVirtualCursor = new GameObject[2];
		}
		if (this.m_spriteVirtualCursor != null)
		{
			this.m_spriteVirtualCursor = new UI2DSprite[2];
		}
		GameObject gameObject = UnityEngine.Object.Instantiate(Resources.Load("OVR/PanelVCursor")) as GameObject;
		gameObject.transform.parent = base.transform.parent;
		gameObject.transform.localScale = new Vector3(1f, 1f, 1f);
		gameObject.SetActive(true);
		this.m_goVirtualCursor[0] = gameObject;
		this.m_spriteVirtualCursor[0] = gameObject.GetComponentInChildren<UI2DSprite>();
		gameObject = UnityEngine.Object.Instantiate<GameObject>(gameObject);
		gameObject.transform.parent = base.transform.parent;
		gameObject.transform.localScale = new Vector3(1f, 1f, 1f);
		gameObject.SetActive(true);
		this.m_goVirtualCursor[1] = gameObject;
		this.m_spriteVirtualCursor[1] = gameObject.GetComponentInChildren<UI2DSprite>();
	}

	public void HideVirtualCursorObj()
	{
		for (int i = 0; i < 2; i++)
		{
			this.SetActiveVirtualCursorObj((UICamera.VCURSOR)i, false);
		}
	}

	public void SetActiveVirtualCursorObjByNocurrent(UICamera.VCURSOR f_eCursor, bool f_bActive)
	{
		if (this.m_goVirtualCursor[(int)f_eCursor] != null)
		{
			UICamera.VCURSOR vcursor = (f_eCursor != UICamera.VCURSOR.LEFT) ? UICamera.VCURSOR.LEFT : UICamera.VCURSOR.RIGHT;
			if (!f_bActive)
			{
				if (f_eCursor == this.m_eCurrentCursorSide)
				{
					if (this.m_goVirtualCursor[(int)vcursor].activeInHierarchy)
					{
						this.SetCurrentCursorSide(vcursor);
						this.m_goVirtualCursor[(int)f_eCursor].SetActive(false);
						this.m_bVirtualDummyActive[(int)f_eCursor] = false;
					}
					else
					{
						this.m_bVirtualDummyActive[(int)f_eCursor] = true;
					}
				}
				else
				{
					this.m_goVirtualCursor[(int)f_eCursor].SetActive(false);
					this.m_bVirtualDummyActive[(int)f_eCursor] = false;
				}
			}
			else
			{
				this.m_goVirtualCursor[(int)f_eCursor].SetActive(true);
				this.m_bVirtualDummyActive[(int)f_eCursor] = false;
				if (this.m_bVirtualDummyActive[(int)vcursor])
				{
					this.m_goVirtualCursor[(int)vcursor].SetActive(false);
					this.m_bVirtualDummyActive[(int)vcursor] = false;
					this.SetCurrentCursorSide(f_eCursor);
				}
			}
		}
	}

	public void SetActiveVirtualCursorObj(UICamera.VCURSOR f_eCursor, bool f_bActive)
	{
		if (this.m_goVirtualCursor[(int)f_eCursor] != null)
		{
			this.m_goVirtualCursor[(int)f_eCursor].SetActive(f_bActive);
		}
	}

	public void DeleteVirtualCursorObj()
	{
		for (int i = 0; i < 2; i++)
		{
			if (this.m_goVirtualCursor[i] != null)
			{
				UnityEngine.Object.DestroyImmediate(this.m_goVirtualCursor[i]);
				this.m_goVirtualCursor[i] = null;
			}
		}
	}

	public void SetCurrentCursorSide(UICamera.VCURSOR f_eCursor)
	{
		this.m_eCurrentCursorSide = f_eCursor;
	}

	public static bool isOverUI
	{
		get
		{
			if (UICamera.currentTouch != null)
			{
				return UICamera.currentTouch.isOverUI;
			}
			return !(UICamera.hoveredObject == null) && !(UICamera.hoveredObject == UICamera.fallThrough) && NGUITools.FindInParents<UIRoot>(UICamera.hoveredObject) != null;
		}
	}

	public static GameObject selectedObject
	{
		get
		{
			return UICamera.mCurrentSelection;
		}
		set
		{
			UICamera.SetSelection(value, UICamera.currentScheme);
		}
	}

	public static bool IsPressed(GameObject go)
	{
		for (int i = 0; i < 3; i++)
		{
			if (UICamera.mMouse[i].pressed == go)
			{
				return true;
			}
		}
		foreach (KeyValuePair<int, UICamera.MouseOrTouch> keyValuePair in UICamera.mTouches)
		{
			if (keyValuePair.Value.pressed == go)
			{
				return true;
			}
		}
		return UICamera.controller.pressed == go;
	}

	protected static void SetSelection(GameObject go, UICamera.ControlScheme scheme)
	{
		if (UICamera.mNextSelection != null)
		{
			UICamera.mNextSelection = go;
		}
		else if (UICamera.mCurrentSelection != go)
		{
			UICamera.mNextSelection = go;
			UICamera.mNextScheme = scheme;
			if (UICamera.list.size > 0)
			{
				UICamera uicamera = (!(UICamera.mNextSelection != null)) ? UICamera.list[0] : UICamera.FindCameraForLayer(UICamera.mNextSelection.layer);
				if (uicamera != null)
				{
					uicamera.StartCoroutine(uicamera.ChangeSelection());
				}
			}
		}
	}

	private IEnumerator ChangeSelection()
	{
		yield return new WaitForEndOfFrame();
		if (UICamera.onSelect != null)
		{
			UICamera.onSelect(UICamera.mCurrentSelection, false);
		}
		UICamera.Notify(UICamera.mCurrentSelection, "OnSelect", false);
		UICamera.mCurrentSelection = UICamera.mNextSelection;
		UICamera.mNextSelection = null;
		if (UICamera.mCurrentSelection != null)
		{
			UICamera.current = this;
			UICamera.currentCamera = this.mCam;
			UICamera.currentScheme = UICamera.mNextScheme;
			UICamera.inputHasFocus = (UICamera.mCurrentSelection.GetComponent<UIInput>() != null);
			if (UICamera.onSelect != null)
			{
				UICamera.onSelect(UICamera.mCurrentSelection, true);
			}
			UICamera.Notify(UICamera.mCurrentSelection, "OnSelect", true);
			UICamera.current = null;
		}
		else
		{
			UICamera.inputHasFocus = false;
		}
		yield break;
	}

	public static int touchCount
	{
		get
		{
			int num = 0;
			foreach (KeyValuePair<int, UICamera.MouseOrTouch> keyValuePair in UICamera.mTouches)
			{
				if (keyValuePair.Value.pressed != null)
				{
					num++;
				}
			}
			for (int i = 0; i < UICamera.mMouse.Length; i++)
			{
				if (UICamera.mMouse[i].pressed != null)
				{
					num++;
				}
			}
			if (UICamera.controller.pressed != null)
			{
				num++;
			}
			return num;
		}
	}

	public static int dragCount
	{
		get
		{
			int num = 0;
			foreach (KeyValuePair<int, UICamera.MouseOrTouch> keyValuePair in UICamera.mTouches)
			{
				if (keyValuePair.Value.dragged != null)
				{
					num++;
				}
			}
			for (int i = 0; i < UICamera.mMouse.Length; i++)
			{
				if (UICamera.mMouse[i].dragged != null)
				{
					num++;
				}
			}
			if (UICamera.controller.dragged != null)
			{
				num++;
			}
			return num;
		}
	}

	public static Camera mainCamera
	{
		get
		{
			UICamera eventHandler = UICamera.eventHandler;
			return (!(eventHandler != null)) ? null : eventHandler.cachedCamera;
		}
	}

	public static UICamera eventHandler
	{
		get
		{
			for (int i = 0; i < UICamera.list.size; i++)
			{
				UICamera uicamera = UICamera.list.buffer[i];
				if (!(uicamera == null) && uicamera.enabled && NGUITools.GetActive(uicamera.gameObject))
				{
					return uicamera;
				}
			}
			return null;
		}
	}

	private static int CompareFunc(UICamera a, UICamera b)
	{
		if (a.cachedCamera.depth < b.cachedCamera.depth)
		{
			return 1;
		}
		if (a.cachedCamera.depth > b.cachedCamera.depth)
		{
			return -1;
		}
		return 0;
	}

	private static Rigidbody FindRootRigidbody(Transform trans)
	{
		while (trans != null)
		{
			if (trans.GetComponent<UIPanel>() != null)
			{
				return null;
			}
			Rigidbody component = trans.GetComponent<Rigidbody>();
			if (component != null)
			{
				return component;
			}
			trans = trans.parent;
		}
		return null;
	}

	private static Rigidbody2D FindRootRigidbody2D(Transform trans)
	{
		while (trans != null)
		{
			if (trans.GetComponent<UIPanel>() != null)
			{
				return null;
			}
			Rigidbody2D component = trans.GetComponent<Rigidbody2D>();
			if (component != null)
			{
				return component;
			}
			trans = trans.parent;
		}
		return null;
	}

	public static bool Raycast(Vector3 inPos)
	{
		for (int i = 0; i < UICamera.list.size; i++)
		{
			UICamera.list.buffer[i].Hover = false;
		}
		for (int j = 0; j < UICamera.list.size; j++)
		{
			UICamera uicamera = UICamera.list.buffer[j];
			if (uicamera.enabled && NGUITools.GetActive(uicamera.gameObject) && uicamera.EnableProcess)
			{
				UICamera.currentCamera = uicamera.cachedCamera;
				Vector3 vector = UICamera.currentCamera.ScreenToViewportPoint(inPos);
				if (!float.IsNaN(vector.x) && !float.IsNaN(vector.y))
				{
					if (vector.x >= 0f && vector.x <= 1f && vector.y >= 0f && vector.y <= 1f)
					{
						Ray ray = UICamera.currentCamera.ScreenPointToRay(inPos);
						int layerMask = UICamera.currentCamera.cullingMask & uicamera.eventReceiverMask;
						float num = (uicamera.rangeDistance <= 0f) ? (UICamera.currentCamera.farClipPlane - UICamera.currentCamera.nearClipPlane) : uicamera.rangeDistance;
						if (uicamera.eventType == UICamera.EventType.World_3D)
						{
							if (Physics.Raycast(ray, out UICamera.lastHit, num, layerMask))
							{
								UICamera.lastWorldPosition = UICamera.lastHit.point;
								UICamera.hoveredObject = UICamera.lastHit.collider.gameObject;
								if (!UICamera.list[0].eventsGoToColliders)
								{
									Rigidbody rigidbody = UICamera.FindRootRigidbody(UICamera.hoveredObject.transform);
									if (rigidbody != null)
									{
										UICamera.hoveredObject = rigidbody.gameObject;
									}
								}
								uicamera.Hover = true;
								return true;
							}
						}
						else if (uicamera.eventType == UICamera.EventType.UI_3D)
						{
							RaycastHit[] array = Physics.RaycastAll(ray, num, layerMask);
							if (array.Length > 1)
							{
								int k = 0;
								while (k < array.Length)
								{
									GameObject gameObject = array[k].collider.gameObject;
									UIWidget component = gameObject.GetComponent<UIWidget>();
									if (component != null)
									{
										if (component.isVisible)
										{
											if (component.hitCheck == null || component.hitCheck(array[k].point))
											{
												goto IL_2A2;
											}
										}
									}
									else
									{
										UIRect uirect = NGUITools.FindInParents<UIRect>(gameObject);
										if (!(uirect != null) || uirect.finalAlpha >= 0.001f)
										{
											goto IL_2A2;
										}
									}
									IL_323:
									k++;
									continue;
									IL_2A2:
									UICamera.mHit.depth = NGUITools.CalculateRaycastDepth(gameObject);
									if (UICamera.mHit.depth != 2147483647)
									{
										UICamera.mHit.hit = array[k];
										UICamera.mHit.point = array[k].point;
										UICamera.mHit.go = array[k].collider.gameObject;
										UICamera.mHits.Add(UICamera.mHit);
										goto IL_323;
									}
									goto IL_323;
								}
								UICamera.mHits.Sort((UICamera.DepthEntry r1, UICamera.DepthEntry r2) => r2.depth.CompareTo(r1.depth));
								for (int l = 0; l < UICamera.mHits.size; l++)
								{
									if (UICamera.IsVisible(ref UICamera.mHits.buffer[l]))
									{
										UICamera.lastHit = UICamera.mHits[l].hit;
										UICamera.hoveredObject = UICamera.mHits[l].go;
										UICamera.lastWorldPosition = UICamera.mHits[l].point;
										UICamera.mHits.Clear();
										uicamera.Hover = true;
										return true;
									}
								}
								UICamera.mHits.Clear();
							}
							else if (array.Length == 1)
							{
								GameObject gameObject2 = array[0].collider.gameObject;
								UIWidget component2 = gameObject2.GetComponent<UIWidget>();
								if (component2 != null)
								{
									if (!component2.isVisible)
									{
										goto IL_849;
									}
									if (component2.hitCheck != null && !component2.hitCheck(array[0].point))
									{
										goto IL_849;
									}
								}
								else
								{
									UIRect uirect2 = NGUITools.FindInParents<UIRect>(gameObject2);
									if (uirect2 != null && uirect2.finalAlpha < 0.001f)
									{
										goto IL_849;
									}
								}
								if (UICamera.IsVisible(array[0].point, array[0].collider.gameObject))
								{
									UICamera.lastHit = array[0];
									UICamera.lastWorldPosition = array[0].point;
									UICamera.hoveredObject = UICamera.lastHit.collider.gameObject;
									uicamera.Hover = true;
									return true;
								}
							}
						}
						else if (uicamera.eventType == UICamera.EventType.World_2D)
						{
							if (UICamera.m2DPlane.Raycast(ray, out num))
							{
								Vector3 point = ray.GetPoint(num);
								Collider2D collider2D = Physics2D.OverlapPoint(point, layerMask);
								if (collider2D)
								{
									UICamera.lastWorldPosition = point;
									UICamera.hoveredObject = collider2D.gameObject;
									if (!uicamera.eventsGoToColliders)
									{
										Rigidbody2D rigidbody2D = UICamera.FindRootRigidbody2D(UICamera.hoveredObject.transform);
										if (rigidbody2D != null)
										{
											UICamera.hoveredObject = rigidbody2D.gameObject;
										}
									}
									uicamera.Hover = true;
									return true;
								}
							}
						}
						else if (uicamera.eventType == UICamera.EventType.UI_2D)
						{
							if (UICamera.m2DPlane.Raycast(ray, out num))
							{
								UICamera.lastWorldPosition = ray.GetPoint(num);
								Collider2D[] array2 = Physics2D.OverlapPointAll(UICamera.lastWorldPosition, layerMask);
								if (array2.Length > 1)
								{
									int m = 0;
									while (m < array2.Length)
									{
										GameObject gameObject3 = array2[m].gameObject;
										UIWidget component3 = gameObject3.GetComponent<UIWidget>();
										if (component3 != null)
										{
											if (component3.isVisible)
											{
												if (component3.hitCheck == null || component3.hitCheck(UICamera.lastWorldPosition))
												{
													goto IL_692;
												}
											}
										}
										else
										{
											UIRect uirect3 = NGUITools.FindInParents<UIRect>(gameObject3);
											if (!(uirect3 != null) || uirect3.finalAlpha >= 0.001f)
											{
												goto IL_692;
											}
										}
										IL_6E1:
										m++;
										continue;
										IL_692:
										UICamera.mHit.depth = NGUITools.CalculateRaycastDepth(gameObject3);
										if (UICamera.mHit.depth != 2147483647)
										{
											UICamera.mHit.go = gameObject3;
											UICamera.mHit.point = UICamera.lastWorldPosition;
											UICamera.mHits.Add(UICamera.mHit);
											goto IL_6E1;
										}
										goto IL_6E1;
									}
									UICamera.mHits.Sort((UICamera.DepthEntry r1, UICamera.DepthEntry r2) => r2.depth.CompareTo(r1.depth));
									for (int n = 0; n < UICamera.mHits.size; n++)
									{
										if (UICamera.IsVisible(ref UICamera.mHits.buffer[n]))
										{
											UICamera.hoveredObject = UICamera.mHits[n].go;
											UICamera.mHits.Clear();
											uicamera.Hover = true;
											return true;
										}
									}
									UICamera.mHits.Clear();
								}
								else if (array2.Length == 1)
								{
									GameObject gameObject4 = array2[0].gameObject;
									UIWidget component4 = gameObject4.GetComponent<UIWidget>();
									if (component4 != null)
									{
										if (!component4.isVisible)
										{
											goto IL_849;
										}
										if (component4.hitCheck != null && !component4.hitCheck(UICamera.lastWorldPosition))
										{
											goto IL_849;
										}
									}
									else
									{
										UIRect uirect4 = NGUITools.FindInParents<UIRect>(gameObject4);
										if (uirect4 != null && uirect4.finalAlpha < 0.001f)
										{
											goto IL_849;
										}
									}
									if (UICamera.IsVisible(UICamera.lastWorldPosition, gameObject4))
									{
										UICamera.hoveredObject = gameObject4;
										uicamera.Hover = true;
										return true;
									}
								}
							}
						}
					}
				}
			}
			IL_849:;
		}
		return false;
	}

	private static bool IsVisible(Vector3 worldPoint, GameObject go)
	{
		UIPanel uipanel = NGUITools.FindInParents<UIPanel>(go);
		while (uipanel != null)
		{
			if (!uipanel.IsVisible(worldPoint))
			{
				return false;
			}
			uipanel = uipanel.parentPanel;
		}
		return true;
	}

	private static bool IsVisible(ref UICamera.DepthEntry de)
	{
		UIPanel uipanel = NGUITools.FindInParents<UIPanel>(de.go);
		while (uipanel != null)
		{
			if (!uipanel.IsVisible(de.point))
			{
				return false;
			}
			uipanel = uipanel.parentPanel;
		}
		return true;
	}

	public static bool IsHighlighted(GameObject go)
	{
		if (UICamera.currentScheme == UICamera.ControlScheme.Mouse)
		{
			return UICamera.hoveredObject == go;
		}
		return UICamera.currentScheme == UICamera.ControlScheme.Controller && UICamera.selectedObject == go;
	}

	public static UICamera FindCameraForLayer(int layer)
	{
		int num = 1 << layer;
		for (int i = 0; i < UICamera.list.size; i++)
		{
			UICamera uicamera = UICamera.list.buffer[i];
			Camera cachedCamera = uicamera.cachedCamera;
			if (cachedCamera != null && (cachedCamera.cullingMask & num) != 0)
			{
				return uicamera;
			}
		}
		return null;
	}

	private static int GetDirection(KeyCode up, KeyCode down)
	{
		if (UICamera.GetKeyDown(up))
		{
			return 1;
		}
		if (UICamera.GetKeyDown(down))
		{
			return -1;
		}
		return 0;
	}

	private static int GetDirection(KeyCode up0, KeyCode up1, KeyCode down0, KeyCode down1)
	{
		if (UICamera.GetKeyDown(up0) || UICamera.GetKeyDown(up1))
		{
			return 1;
		}
		if (UICamera.GetKeyDown(down0) || UICamera.GetKeyDown(down1))
		{
			return -1;
		}
		return 0;
	}

	private static int GetDirection(string axis)
	{
		float time = RealTime.time;
		if (UICamera.mNextEvent < time && !string.IsNullOrEmpty(axis))
		{
			float num = UICamera.GetAxis(axis);
			if (num > 0.75f)
			{
				UICamera.mNextEvent = time + 0.25f;
				return 1;
			}
			if (num < -0.75f)
			{
				UICamera.mNextEvent = time + 0.25f;
				return -1;
			}
		}
		return 0;
	}

	public static void Notify(GameObject go, string funcName, object obj)
	{
		if (UICamera.mNotifying)
		{
			return;
		}
		UICamera.mNotifying = true;
		if (NGUITools.GetActive(go))
		{
			go.SendMessage(funcName, obj, SendMessageOptions.DontRequireReceiver);
			if (UICamera.mGenericHandler != null && UICamera.mGenericHandler != go)
			{
				UICamera.mGenericHandler.SendMessage(funcName, obj, SendMessageOptions.DontRequireReceiver);
			}
		}
		UICamera.mNotifying = false;
	}

	public static UICamera.MouseOrTouch GetMouse(int button)
	{
		return UICamera.mMouse[button];
	}

	public static UICamera.MouseOrTouch GetTouch(int id)
	{
		UICamera.MouseOrTouch mouseOrTouch = null;
		if (id < 0)
		{
			return UICamera.GetMouse(-id - 1);
		}
		if (!UICamera.mTouches.TryGetValue(id, out mouseOrTouch))
		{
			mouseOrTouch = new UICamera.MouseOrTouch();
			mouseOrTouch.pressTime = RealTime.time;
			mouseOrTouch.touchBegan = true;
			UICamera.mTouches.Add(id, mouseOrTouch);
		}
		return mouseOrTouch;
	}

	public static void RemoveTouch(int id)
	{
		UICamera.mTouches.Remove(id);
	}

	public static int ScreenWidth
	{
		get
		{
			if (Application.isPlaying && (GameMain.Instance != null && GameMain.Instance.VRMode))
			{
				return 1280;
			}
			return Screen.width;
		}
	}

	public static int ScreenHeight
	{
		get
		{
			if (Application.isPlaying && (GameMain.Instance != null && GameMain.Instance.VRMode))
			{
				return 720;
			}
			return Screen.height;
		}
	}

	private void Awake()
	{
		if (GameMain.Instance != null && GameMain.Instance.VRMode)
		{
			this.VRUpdateCamDepth();
		}
		UICamera.mWidth = UICamera.ScreenWidth;
		UICamera.mHeight = UICamera.ScreenHeight;
		if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.WP8Player || Application.platform == RuntimePlatform.BlackBerryPlayer)
		{
			this.useTouch = true;
			if (Application.platform == RuntimePlatform.IPhonePlayer)
			{
				this.useMouse = false;
				this.useKeyboard = false;
				this.useController = false;
			}
		}
		else if (Application.platform == RuntimePlatform.PS3 || Application.platform == RuntimePlatform.XBOX360)
		{
			this.useMouse = false;
			this.useTouch = false;
			this.useKeyboard = false;
			this.useController = true;
		}
		UICamera.mMouse[0].pos = Input.mousePosition;
		for (int i = 1; i < 3; i++)
		{
			UICamera.mMouse[i].pos = UICamera.mMouse[0].pos;
			UICamera.mMouse[i].lastPos = UICamera.mMouse[0].pos;
		}
		UICamera.lastTouchPosition = UICamera.mMouse[0].pos;
	}

	private void OnEnable()
	{
		UICamera.list.Add(this);
		BetterList<UICamera> betterList = UICamera.list;
		if (UICamera.<>f__mg$cache0 == null)
		{
			UICamera.<>f__mg$cache0 = new BetterList<UICamera>.CompareFunc(UICamera.CompareFunc);
		}
		betterList.Sort(UICamera.<>f__mg$cache0);
		if (GameMain.Instance != null && GameMain.Instance.VRMode)
		{
			this.VRUpdateCamDepth();
		}
	}

	private void OnDisable()
	{
		UICamera.list.Remove(this);
		if (GameMain.Instance != null && GameMain.Instance.VRMode)
		{
			this.VRUpdateCamDepth();
		}
	}

	private void Start()
	{
		if (this.eventType != UICamera.EventType.World_3D && this.cachedCamera.transparencySortMode != TransparencySortMode.Orthographic)
		{
			this.cachedCamera.transparencySortMode = TransparencySortMode.Orthographic;
		}
		if (Application.isPlaying)
		{
			if (UICamera.fallThrough == null)
			{
				UIRoot uiroot = NGUITools.FindInParents<UIRoot>(base.gameObject);
				if (uiroot != null)
				{
					UICamera.fallThrough = uiroot.gameObject;
				}
				else
				{
					Transform transform = base.transform;
					UICamera.fallThrough = ((!(transform.parent != null)) ? base.gameObject : transform.parent.gameObject);
				}
			}
			this.cachedCamera.eventMask = 0;
		}
		if (this.handlesEvents)
		{
			NGUIDebug.debugRaycast = this.debug;
		}
	}

	private void VRUpdateCamDepth()
	{
		if (this.VRExclusionUI)
		{
			return;
		}
		UICamera[] array = (from a in UnityEngine.Object.FindObjectsOfType<UICamera>()
		where !a.VRExclusionUI
		select a).ToArray<UICamera>();
		if (array.Length == 0)
		{
			return;
		}
		Camera camera = array[0].cachedCamera;
		for (int i = 0; i < array.Length; i++)
		{
			Camera cachedCamera = array[i].cachedCamera;
			cachedCamera.clearFlags = CameraClearFlags.Depth;
			if (cachedCamera.depth < camera.depth)
			{
				camera = cachedCamera;
			}
		}
		camera.clearFlags = CameraClearFlags.Color;
		this.cachedCamera.targetTexture = GameMain.Instance.OvrMgr.UIRTarget;
		if (base.transform.parent.name == "SystemUI Root")
		{
			this.cachedCamera.clearFlags = CameraClearFlags.Depth;
		}
	}

	public static void InputEnableFlag(UICamera.INPUT_CTRL_TYPE flag, bool bEnable)
	{
		if (bEnable)
		{
			UICamera.m_unInputEnableFlag |= (uint)flag;
		}
		else
		{
			UICamera.m_unInputEnableFlag &= (uint)(~(uint)flag);
		}
	}

	private void Update()
	{
		if (!this.handlesEvents)
		{
			return;
		}
		if (!UICamera.InputEnable)
		{
			return;
		}
		UICamera.current = this;
		if (GameMain.Instance.VRMode && Application.isPlaying)
		{
			for (int i = 0; i < 2; i++)
			{
				if (!GameMain.Instance.VRDummyMode)
				{
					Vector3[] vVirtualMousePos = this.m_vVirtualMousePos;
					int num = i;
					vVirtualMousePos[num].x = vVirtualMousePos[num].x + NInput.GetAxis("Mouse X") * Time.deltaTime * 100f * 10f;
					Vector3[] vVirtualMousePos2 = this.m_vVirtualMousePos;
					int num2 = i;
					vVirtualMousePos2[num2].y = vVirtualMousePos2[num2].y + NInput.GetAxis("Mouse Y") * Time.deltaTime * 100f * 10f;
				}
				this.m_vVirtualMousePos[i].x = Mathf.Min(Mathf.Max(this.m_vVirtualMousePos[i].x, 3f), 1277f);
				this.m_vVirtualMousePos[i].y = Mathf.Min(Mathf.Max(this.m_vVirtualMousePos[i].y, 3f), 717f);
				this.m_vVirtualMousePos[i].z = 0f;
				if (this.m_goVirtualCursor[i] != null)
				{
					this.m_goVirtualCursor[i].transform.position = base.GetComponent<Camera>().ScreenToWorldPoint(this.m_vVirtualMousePos[i]);
				}
				if (this.m_spriteVirtualCursor[i] != null)
				{
					this.m_spriteVirtualCursor[i].color = ((i != (int)this.m_eCurrentCursorSide) ? new Color(1f, 1f, 1f, 0.5f) : new Color(1f, 1f, 1f, 1f));
				}
			}
		}
		if (this.useTouch)
		{
			this.ProcessTouches();
		}
		else if (this.useMouse)
		{
			this.ProcessMouse();
		}
		if (UICamera.onCustomInput != null)
		{
			UICamera.onCustomInput();
		}
		if (this.useMouse && UICamera.mCurrentSelection != null)
		{
			if (this.cancelKey0 != KeyCode.None && UICamera.GetKeyDown(this.cancelKey0))
			{
				UICamera.currentScheme = UICamera.ControlScheme.Controller;
				UICamera.currentKey = this.cancelKey0;
				UICamera.selectedObject = null;
			}
			else if (this.cancelKey1 != KeyCode.None && UICamera.GetKeyDown(this.cancelKey1))
			{
				UICamera.currentScheme = UICamera.ControlScheme.Controller;
				UICamera.currentKey = this.cancelKey1;
				UICamera.selectedObject = null;
			}
		}
		if (UICamera.mCurrentSelection == null)
		{
			UICamera.inputHasFocus = false;
		}
		if (UICamera.mCurrentSelection != null)
		{
			this.ProcessOthers();
		}
		if (this.useMouse && UICamera.mHover != null)
		{
			float num3 = string.IsNullOrEmpty(this.scrollAxisName) ? 0f : UICamera.GetAxis(this.scrollAxisName);
			if (num3 != 0f)
			{
				if (UICamera.onScroll != null)
				{
					UICamera.onScroll(UICamera.mHover, num3);
				}
				UICamera.Notify(UICamera.mHover, "OnScroll", num3);
			}
			if (UICamera.showTooltips && this.mTooltipTime != 0f && (this.mTooltipTime < RealTime.time || UICamera.GetKey(KeyCode.LeftShift) || UICamera.GetKey(KeyCode.RightShift)))
			{
				this.mTooltip = UICamera.mHover;
				this.ShowTooltip(true);
			}
		}
		UICamera.current = null;
		UICamera.currentTouchID = -100;
	}

	private void LateUpdate()
	{
		if (!this.handlesEvents)
		{
			return;
		}
		int screenWidth = UICamera.ScreenWidth;
		int screenHeight = UICamera.ScreenHeight;
		if (screenWidth != UICamera.mWidth || screenHeight != UICamera.mHeight)
		{
			UICamera.mWidth = screenWidth;
			UICamera.mHeight = screenHeight;
			UIRoot.Broadcast("UpdateAnchors");
			if (UICamera.onScreenResize != null)
			{
				UICamera.onScreenResize();
			}
		}
	}

	public void ProcessMouse()
	{
		if (GameMain.Instance.VRMode && Application.isPlaying)
		{
			if (GameMain.Instance.MainCamera.IsFadeOut())
			{
				return;
			}
			UICamera.lastTouchPosition = new Vector2(this.m_vVirtualMousePos[(int)this.m_eCurrentCursorSide].x, this.m_vVirtualMousePos[(int)this.m_eCurrentCursorSide].y);
		}
		else
		{
			UICamera.lastTouchPosition = Input.mousePosition;
		}
		UICamera.mMouse[0].delta = UICamera.lastTouchPosition - UICamera.mMouse[0].pos;
		UICamera.mMouse[0].pos = UICamera.lastTouchPosition;
		bool flag = UICamera.mMouse[0].delta.sqrMagnitude > 0.001f;
		for (int i = 1; i < 3; i++)
		{
			UICamera.mMouse[i].pos = UICamera.mMouse[0].pos;
			UICamera.mMouse[i].delta = UICamera.mMouse[0].delta;
		}
		bool flag2 = false;
		bool flag3 = false;
		if (UICamera.isDisableRightClick && (NInput.GetMouseButtonDown(1) || NInput.GetMouseButton(1) || NInput.GetMouseButtonUp(1)))
		{
			return;
		}
		for (int j = 0; j < 3; j++)
		{
			if (NInput.GetMouseButtonDown(j))
			{
				UICamera.currentScheme = UICamera.ControlScheme.Mouse;
				flag3 = true;
				flag2 = true;
			}
			else if (NInput.GetMouseButton(j))
			{
				UICamera.currentScheme = UICamera.ControlScheme.Mouse;
				flag2 = true;
			}
		}
		if (flag2 || flag || this.mNextRaycast < RealTime.time)
		{
			this.mNextRaycast = RealTime.time + 0.02f;
			Vector3 inPos;
			if (GameMain.Instance.VRMode && Application.isPlaying)
			{
				inPos = this.m_vVirtualMousePos[(int)this.m_eCurrentCursorSide];
			}
			else
			{
				inPos = Input.mousePosition;
			}
			if (!UICamera.Raycast(inPos))
			{
				UICamera.hoveredObject = UICamera.fallThrough;
				UICamera.isFallThrough = true;
			}
			else
			{
				UICamera.isFallThrough = false;
			}
			if (UICamera.hoveredObject == null)
			{
				UICamera.hoveredObject = UICamera.mGenericHandler;
			}
			for (int k = 0; k < 3; k++)
			{
				UICamera.mMouse[k].current = UICamera.hoveredObject;
			}
		}
		bool flag4 = UICamera.mMouse[0].last != UICamera.mMouse[0].current;
		if (flag4)
		{
			UICamera.currentScheme = UICamera.ControlScheme.Mouse;
		}
		if (flag2)
		{
			this.mTooltipTime = 0f;
		}
		else if (flag && (!this.stickyTooltip || flag4))
		{
			if (this.mTooltipTime != 0f)
			{
				this.mTooltipTime = RealTime.time + this.tooltipDelay;
			}
			else if (this.mTooltip != null)
			{
				this.ShowTooltip(false);
			}
		}
		if (flag && UICamera.onMouseMove != null)
		{
			UICamera.currentTouch = UICamera.mMouse[0];
			UICamera.onMouseMove(UICamera.currentTouch.delta);
			UICamera.currentTouch = null;
		}
		if ((flag3 || !flag2) && UICamera.mHover != null && flag4)
		{
			UICamera.currentScheme = UICamera.ControlScheme.Mouse;
			UICamera.currentTouch = UICamera.mMouse[0];
			if (this.mTooltip != null)
			{
				this.ShowTooltip(false);
			}
			if (UICamera.onHover != null)
			{
				UICamera.onHover(UICamera.mHover, false);
			}
			UICamera.Notify(UICamera.mHover, "OnHover", false);
			UICamera.mHover = null;
		}
		for (int l = 0; l < 3; l++)
		{
			bool mouseButtonDown = NInput.GetMouseButtonDown(l);
			bool mouseButtonUp = NInput.GetMouseButtonUp(l);
			if (mouseButtonDown || mouseButtonUp)
			{
				UICamera.currentScheme = UICamera.ControlScheme.Mouse;
			}
			UICamera.currentTouch = UICamera.mMouse[l];
			UICamera.currentTouchID = -1 - l;
			UICamera.currentKey = KeyCode.Mouse0 + l;
			if (mouseButtonDown)
			{
				UICamera.currentTouch.pressedCam = UICamera.currentCamera;
			}
			else if (UICamera.currentTouch.pressed != null)
			{
				UICamera.currentCamera = UICamera.currentTouch.pressedCam;
			}
			this.ProcessTouch(mouseButtonDown, mouseButtonUp);
			UICamera.currentKey = KeyCode.None;
		}
		if (!flag2 && flag4)
		{
			UICamera.currentScheme = UICamera.ControlScheme.Mouse;
			this.mTooltipTime = RealTime.time + this.tooltipDelay;
			UICamera.mHover = UICamera.mMouse[0].current;
			UICamera.currentTouch = UICamera.mMouse[0];
			if (UICamera.onHover != null)
			{
				UICamera.onHover(UICamera.mHover, true);
			}
			UICamera.Notify(UICamera.mHover, "OnHover", true);
		}
		UICamera.currentTouch = null;
		UICamera.mMouse[0].last = UICamera.mMouse[0].current;
		for (int m = 1; m < 3; m++)
		{
			UICamera.mMouse[m].last = UICamera.mMouse[0].last;
		}
	}

	public void ProcessTouches()
	{
		UICamera.currentScheme = UICamera.ControlScheme.Touch;
		for (int i = 0; i < Input.touchCount; i++)
		{
			Touch touch = Input.GetTouch(i);
			UICamera.currentTouchID = ((!this.allowMultiTouch) ? 1 : touch.fingerId);
			UICamera.currentTouch = UICamera.GetTouch(UICamera.currentTouchID);
			bool flag = touch.phase == TouchPhase.Began || UICamera.currentTouch.touchBegan;
			bool flag2 = touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended;
			UICamera.currentTouch.touchBegan = false;
			UICamera.currentTouch.delta = ((!flag) ? (touch.position - UICamera.currentTouch.pos) : Vector2.zero);
			UICamera.currentTouch.pos = touch.position;
			if (!UICamera.Raycast(UICamera.currentTouch.pos))
			{
				UICamera.hoveredObject = UICamera.fallThrough;
			}
			if (UICamera.hoveredObject == null)
			{
				UICamera.hoveredObject = UICamera.mGenericHandler;
			}
			UICamera.currentTouch.last = UICamera.currentTouch.current;
			UICamera.currentTouch.current = UICamera.hoveredObject;
			UICamera.lastTouchPosition = UICamera.currentTouch.pos;
			if (flag)
			{
				UICamera.currentTouch.pressedCam = UICamera.currentCamera;
			}
			else if (UICamera.currentTouch.pressed != null)
			{
				UICamera.currentCamera = UICamera.currentTouch.pressedCam;
			}
			if (touch.tapCount > 1)
			{
				UICamera.currentTouch.clickTime = RealTime.time;
			}
			this.ProcessTouch(flag, flag2);
			if (flag2)
			{
				UICamera.RemoveTouch(UICamera.currentTouchID);
			}
			UICamera.currentTouch.last = null;
			UICamera.currentTouch = null;
			if (!this.allowMultiTouch)
			{
				break;
			}
		}
		if (Input.touchCount == 0)
		{
			if (UICamera.mUsingTouchEvents)
			{
				UICamera.mUsingTouchEvents = false;
				return;
			}
			if (this.useMouse)
			{
				this.ProcessMouse();
			}
		}
		else
		{
			UICamera.mUsingTouchEvents = true;
		}
	}

	private void ProcessFakeTouches()
	{
		bool mouseButtonDown = NInput.GetMouseButtonDown(0);
		bool mouseButtonUp = NInput.GetMouseButtonUp(0);
		bool mouseButton = NInput.GetMouseButton(0);
		if (mouseButtonDown || mouseButtonUp || mouseButton)
		{
			UICamera.currentTouchID = 1;
			UICamera.currentTouch = UICamera.mMouse[0];
			UICamera.currentTouch.touchBegan = mouseButtonDown;
			if (mouseButtonDown)
			{
				UICamera.currentTouch.pressTime = RealTime.time;
			}
			Vector2 vector;
			if (GameMain.Instance.VRMode && Application.isPlaying)
			{
				vector = new Vector2(this.m_vVirtualMousePos[(int)this.m_eCurrentCursorSide].x, this.m_vVirtualMousePos[(int)this.m_eCurrentCursorSide].y);
			}
			else
			{
				vector = Input.mousePosition;
			}
			UICamera.currentTouch.delta = ((!mouseButtonDown) ? (vector - UICamera.currentTouch.pos) : Vector2.zero);
			UICamera.currentTouch.pos = vector;
			if (!UICamera.Raycast(UICamera.currentTouch.pos))
			{
				UICamera.hoveredObject = UICamera.fallThrough;
			}
			if (UICamera.hoveredObject == null)
			{
				UICamera.hoveredObject = UICamera.mGenericHandler;
			}
			UICamera.currentTouch.last = UICamera.currentTouch.current;
			UICamera.currentTouch.current = UICamera.hoveredObject;
			UICamera.lastTouchPosition = UICamera.currentTouch.pos;
			if (mouseButtonDown)
			{
				UICamera.currentTouch.pressedCam = UICamera.currentCamera;
			}
			else if (UICamera.currentTouch.pressed != null)
			{
				UICamera.currentCamera = UICamera.currentTouch.pressedCam;
			}
			this.ProcessTouch(mouseButtonDown, mouseButtonUp);
			if (mouseButtonUp)
			{
				UICamera.RemoveTouch(UICamera.currentTouchID);
			}
			UICamera.currentTouch.last = null;
			UICamera.currentTouch = null;
		}
	}

	public void ProcessOthers()
	{
		UICamera.currentTouchID = -100;
		UICamera.currentTouch = UICamera.controller;
		bool flag = false;
		bool flag2 = false;
		if (this.submitKey0 != KeyCode.None && UICamera.GetKeyDown(this.submitKey0))
		{
			UICamera.currentKey = this.submitKey0;
			flag = true;
		}
		if (this.submitKey1 != KeyCode.None && UICamera.GetKeyDown(this.submitKey1))
		{
			UICamera.currentKey = this.submitKey1;
			flag = true;
		}
		if (this.submitKey0 != KeyCode.None && UICamera.GetKeyUp(this.submitKey0))
		{
			UICamera.currentKey = this.submitKey0;
			flag2 = true;
		}
		if (this.submitKey1 != KeyCode.None && UICamera.GetKeyUp(this.submitKey1))
		{
			UICamera.currentKey = this.submitKey1;
			flag2 = true;
		}
		if (flag || flag2)
		{
			UICamera.currentScheme = UICamera.ControlScheme.Controller;
			UICamera.currentTouch.last = UICamera.currentTouch.current;
			UICamera.currentTouch.current = UICamera.mCurrentSelection;
			UICamera.currentTouch.last = null;
		}
		int num = 0;
		int num2 = 0;
		if (this.useKeyboard)
		{
			if (UICamera.inputHasFocus)
			{
				num += UICamera.GetDirection(KeyCode.UpArrow, KeyCode.DownArrow);
				num2 += UICamera.GetDirection(KeyCode.RightArrow, KeyCode.LeftArrow);
			}
			else
			{
				num += UICamera.GetDirection(KeyCode.W, KeyCode.UpArrow, KeyCode.S, KeyCode.DownArrow);
				num2 += UICamera.GetDirection(KeyCode.D, KeyCode.RightArrow, KeyCode.A, KeyCode.LeftArrow);
			}
		}
		if (this.useController)
		{
			if (!string.IsNullOrEmpty(this.verticalAxisName))
			{
				num += UICamera.GetDirection(this.verticalAxisName);
			}
			if (!string.IsNullOrEmpty(this.horizontalAxisName))
			{
				num2 += UICamera.GetDirection(this.horizontalAxisName);
			}
		}
		if (num != 0)
		{
			UICamera.currentScheme = UICamera.ControlScheme.Controller;
			KeyCode keyCode = (num <= 0) ? KeyCode.DownArrow : KeyCode.UpArrow;
			if (UICamera.onKey != null)
			{
				UICamera.onKey(UICamera.mCurrentSelection, keyCode);
			}
			UICamera.Notify(UICamera.mCurrentSelection, "OnKey", keyCode);
		}
		if (num2 != 0)
		{
			UICamera.currentScheme = UICamera.ControlScheme.Controller;
			KeyCode keyCode2 = (num2 <= 0) ? KeyCode.LeftArrow : KeyCode.RightArrow;
			if (UICamera.onKey != null)
			{
				UICamera.onKey(UICamera.mCurrentSelection, keyCode2);
			}
			UICamera.Notify(UICamera.mCurrentSelection, "OnKey", keyCode2);
		}
		if (this.useKeyboard && UICamera.GetKeyDown(KeyCode.Tab))
		{
			UICamera.currentKey = KeyCode.Tab;
			UICamera.currentScheme = UICamera.ControlScheme.Controller;
			if (UICamera.onKey != null)
			{
				UICamera.onKey(UICamera.mCurrentSelection, KeyCode.Tab);
			}
			UICamera.Notify(UICamera.mCurrentSelection, "OnKey", KeyCode.Tab);
		}
		if (this.cancelKey0 != KeyCode.None && UICamera.GetKeyDown(this.cancelKey0))
		{
			UICamera.currentKey = this.cancelKey0;
			UICamera.currentScheme = UICamera.ControlScheme.Controller;
			if (UICamera.onKey != null)
			{
				UICamera.onKey(UICamera.mCurrentSelection, KeyCode.Escape);
			}
			UICamera.Notify(UICamera.mCurrentSelection, "OnKey", KeyCode.Escape);
		}
		if (this.cancelKey1 != KeyCode.None && UICamera.GetKeyDown(this.cancelKey1))
		{
			UICamera.currentKey = this.cancelKey1;
			UICamera.currentScheme = UICamera.ControlScheme.Controller;
			if (UICamera.onKey != null)
			{
				UICamera.onKey(UICamera.mCurrentSelection, KeyCode.Escape);
			}
			UICamera.Notify(UICamera.mCurrentSelection, "OnKey", KeyCode.Escape);
		}
		UICamera.currentTouch = null;
		UICamera.currentKey = KeyCode.None;
	}

	public void ProcessTouch(bool pressed, bool unpressed)
	{
		bool flag = UICamera.currentScheme == UICamera.ControlScheme.Mouse;
		float num = (!flag) ? this.touchDragThreshold : this.mouseDragThreshold;
		float num2 = (!flag) ? this.touchClickThreshold : this.mouseClickThreshold;
		num *= num;
		num2 *= num2;
		if (pressed)
		{
			if (this.mTooltip != null)
			{
				this.ShowTooltip(false);
			}
			UICamera.currentTouch.pressStarted = true;
			if (UICamera.onPress != null && UICamera.currentTouch.pressed)
			{
				UICamera.onPress(UICamera.currentTouch.pressed, false);
			}
			UICamera.Notify(UICamera.currentTouch.pressed, "OnPress", false);
			UICamera.currentTouch.pressed = UICamera.currentTouch.current;
			UICamera.currentTouch.dragged = UICamera.currentTouch.current;
			UICamera.currentTouch.clickNotification = UICamera.ClickNotification.BasedOnDelta;
			UICamera.currentTouch.totalDelta = Vector2.zero;
			UICamera.currentTouch.dragStarted = false;
			if (UICamera.onPress != null && UICamera.currentTouch.pressed)
			{
				UICamera.onPress(UICamera.currentTouch.pressed, true);
			}
			UICamera.Notify(UICamera.currentTouch.pressed, "OnPress", true);
			if (UICamera.currentTouch.pressed != UICamera.mCurrentSelection)
			{
				if (this.mTooltip != null)
				{
					this.ShowTooltip(false);
				}
				UICamera.currentScheme = UICamera.ControlScheme.Touch;
				UICamera.selectedObject = UICamera.currentTouch.pressed;
			}
		}
		else if (UICamera.currentTouch.pressed != null && (UICamera.currentTouch.delta.sqrMagnitude != 0f || UICamera.currentTouch.current != UICamera.currentTouch.last))
		{
			UICamera.currentTouch.totalDelta += UICamera.currentTouch.delta;
			float sqrMagnitude = UICamera.currentTouch.totalDelta.sqrMagnitude;
			bool flag2 = false;
			if (!UICamera.currentTouch.dragStarted && UICamera.currentTouch.last != UICamera.currentTouch.current)
			{
				UICamera.currentTouch.dragStarted = true;
				UICamera.currentTouch.delta = UICamera.currentTouch.totalDelta;
				UICamera.isDragging = true;
				if (UICamera.onDragStart != null)
				{
					UICamera.onDragStart(UICamera.currentTouch.dragged);
				}
				UICamera.Notify(UICamera.currentTouch.dragged, "OnDragStart", null);
				if (UICamera.onDragOver != null)
				{
					UICamera.onDragOver(UICamera.currentTouch.last, UICamera.currentTouch.dragged);
				}
				UICamera.Notify(UICamera.currentTouch.last, "OnDragOver", UICamera.currentTouch.dragged);
				UICamera.isDragging = false;
			}
			else if (!UICamera.currentTouch.dragStarted && num < sqrMagnitude)
			{
				flag2 = true;
				UICamera.currentTouch.dragStarted = true;
				UICamera.currentTouch.delta = UICamera.currentTouch.totalDelta;
			}
			if (UICamera.currentTouch.dragStarted)
			{
				if (this.mTooltip != null)
				{
					this.ShowTooltip(false);
				}
				UICamera.isDragging = true;
				bool flag3 = UICamera.currentTouch.clickNotification == UICamera.ClickNotification.None;
				if (flag2)
				{
					if (UICamera.onDragStart != null)
					{
						UICamera.onDragStart(UICamera.currentTouch.dragged);
					}
					UICamera.Notify(UICamera.currentTouch.dragged, "OnDragStart", null);
					if (UICamera.onDragOver != null)
					{
						UICamera.onDragOver(UICamera.currentTouch.last, UICamera.currentTouch.dragged);
					}
					UICamera.Notify(UICamera.currentTouch.current, "OnDragOver", UICamera.currentTouch.dragged);
				}
				else if (UICamera.currentTouch.last != UICamera.currentTouch.current)
				{
					if (UICamera.onDragStart != null)
					{
						UICamera.onDragStart(UICamera.currentTouch.dragged);
					}
					UICamera.Notify(UICamera.currentTouch.last, "OnDragOut", UICamera.currentTouch.dragged);
					if (UICamera.onDragOver != null)
					{
						UICamera.onDragOver(UICamera.currentTouch.last, UICamera.currentTouch.dragged);
					}
					UICamera.Notify(UICamera.currentTouch.current, "OnDragOver", UICamera.currentTouch.dragged);
				}
				if (UICamera.onDrag != null)
				{
					UICamera.onDrag(UICamera.currentTouch.dragged, UICamera.currentTouch.delta);
				}
				UICamera.Notify(UICamera.currentTouch.dragged, "OnDrag", UICamera.currentTouch.delta);
				UICamera.currentTouch.last = UICamera.currentTouch.current;
				UICamera.isDragging = false;
				if (flag3)
				{
					UICamera.currentTouch.clickNotification = UICamera.ClickNotification.None;
				}
				else if (UICamera.currentTouch.clickNotification == UICamera.ClickNotification.BasedOnDelta && num2 < sqrMagnitude)
				{
					UICamera.currentTouch.clickNotification = UICamera.ClickNotification.None;
				}
			}
		}
		if (unpressed)
		{
			UICamera.currentTouch.pressStarted = false;
			if (this.mTooltip != null)
			{
				this.ShowTooltip(false);
			}
			if (UICamera.currentTouch.pressed != null)
			{
				if (UICamera.currentTouch.dragStarted)
				{
					if (UICamera.onDragOut != null)
					{
						UICamera.onDragOut(UICamera.currentTouch.last, UICamera.currentTouch.dragged);
					}
					UICamera.Notify(UICamera.currentTouch.last, "OnDragOut", UICamera.currentTouch.dragged);
					if (UICamera.onDragEnd != null)
					{
						UICamera.onDragEnd(UICamera.currentTouch.dragged);
					}
					UICamera.Notify(UICamera.currentTouch.dragged, "OnDragEnd", null);
				}
				if (UICamera.onPress != null)
				{
					UICamera.onPress(UICamera.currentTouch.pressed, false);
				}
				UICamera.Notify(UICamera.currentTouch.pressed, "OnPress", false);
				if (flag)
				{
					if (UICamera.onHover != null)
					{
						UICamera.onHover(UICamera.currentTouch.current, true);
					}
					UICamera.Notify(UICamera.currentTouch.current, "OnHover", true);
				}
				UICamera.mHover = UICamera.currentTouch.current;
				if (UICamera.currentTouch.dragged == UICamera.currentTouch.current || (UICamera.currentScheme != UICamera.ControlScheme.Controller && UICamera.currentTouch.clickNotification != UICamera.ClickNotification.None && UICamera.currentTouch.totalDelta.sqrMagnitude < num))
				{
					if (UICamera.currentTouch.pressed != UICamera.mCurrentSelection)
					{
						UICamera.mNextSelection = null;
						UICamera.mCurrentSelection = UICamera.currentTouch.pressed;
						if (UICamera.onSelect != null)
						{
							UICamera.onSelect(UICamera.currentTouch.pressed, true);
						}
						UICamera.Notify(UICamera.currentTouch.pressed, "OnSelect", true);
					}
					else
					{
						UICamera.mNextSelection = null;
						UICamera.mCurrentSelection = UICamera.currentTouch.pressed;
					}
					if (UICamera.currentTouch.clickNotification != UICamera.ClickNotification.None && UICamera.currentTouch.pressed == UICamera.currentTouch.current)
					{
						float time = RealTime.time;
						if (UICamera.onClick != null)
						{
							UICamera.onClick(UICamera.currentTouch.pressed);
						}
						UICamera.Notify(UICamera.currentTouch.pressed, "OnClick", null);
						if (UICamera.currentTouch.clickTime + 0.35f > time)
						{
							if (UICamera.onDoubleClick != null)
							{
								UICamera.onDoubleClick(UICamera.currentTouch.pressed);
							}
							UICamera.Notify(UICamera.currentTouch.pressed, "OnDoubleClick", null);
						}
						UICamera.currentTouch.clickTime = time;
					}
				}
				else if (UICamera.currentTouch.dragStarted)
				{
					if (UICamera.onDrop != null)
					{
						UICamera.onDrop(UICamera.currentTouch.current, UICamera.currentTouch.dragged);
					}
					UICamera.Notify(UICamera.currentTouch.current, "OnDrop", UICamera.currentTouch.dragged);
				}
			}
			UICamera.currentTouch.dragStarted = false;
			UICamera.currentTouch.pressed = null;
			UICamera.currentTouch.dragged = null;
		}
	}

	public void ShowTooltip(bool val)
	{
		this.mTooltipTime = 0f;
		if (UICamera.onTooltip != null)
		{
			UICamera.onTooltip(this.mTooltip, val);
		}
		UICamera.Notify(this.mTooltip, "OnTooltip", val);
		if (!val)
		{
			this.mTooltip = null;
		}
	}

	private void OnApplicationPause()
	{
		UICamera.MouseOrTouch mouseOrTouch = UICamera.currentTouch;
		if (this.useTouch)
		{
			BetterList<int> betterList = new BetterList<int>();
			foreach (KeyValuePair<int, UICamera.MouseOrTouch> keyValuePair in UICamera.mTouches)
			{
				if (keyValuePair.Value != null && keyValuePair.Value.pressed)
				{
					UICamera.currentTouch = keyValuePair.Value;
					UICamera.currentTouchID = keyValuePair.Key;
					UICamera.currentScheme = UICamera.ControlScheme.Touch;
					UICamera.currentTouch.clickNotification = UICamera.ClickNotification.None;
					this.ProcessTouch(false, true);
					betterList.Add(UICamera.currentTouchID);
				}
			}
			for (int i = 0; i < betterList.size; i++)
			{
				UICamera.RemoveTouch(betterList[i]);
			}
		}
		if (this.useMouse)
		{
			for (int j = 0; j < 3; j++)
			{
				if (UICamera.mMouse[j].pressed)
				{
					UICamera.currentTouch = UICamera.mMouse[j];
					UICamera.currentTouchID = -1 - j;
					UICamera.currentKey = KeyCode.Mouse0 + j;
					UICamera.currentScheme = UICamera.ControlScheme.Mouse;
					UICamera.currentTouch.clickNotification = UICamera.ClickNotification.None;
					this.ProcessTouch(false, true);
				}
			}
		}
		if (this.useController && UICamera.controller.pressed)
		{
			UICamera.currentTouch = UICamera.controller;
			UICamera.currentTouchID = -100;
			UICamera.currentScheme = UICamera.ControlScheme.Controller;
			UICamera.currentTouch.last = UICamera.currentTouch.current;
			UICamera.currentTouch.current = UICamera.mCurrentSelection;
			UICamera.currentTouch.clickNotification = UICamera.ClickNotification.None;
			this.ProcessTouch(false, true);
			UICamera.currentTouch.last = null;
		}
		UICamera.currentTouch = mouseOrTouch;
	}

	// Note: this type is marked as 'beforefieldinit'.
	static UICamera()
	{
		if (UICamera.<>f__mg$cache1 == null)
		{
			UICamera.<>f__mg$cache1 = new UICamera.GetKeyStateFunc(Input.GetKeyDown);
		}
		UICamera.GetKeyDown = UICamera.<>f__mg$cache1;
		if (UICamera.<>f__mg$cache2 == null)
		{
			UICamera.<>f__mg$cache2 = new UICamera.GetKeyStateFunc(Input.GetKeyUp);
		}
		UICamera.GetKeyUp = UICamera.<>f__mg$cache2;
		if (UICamera.<>f__mg$cache3 == null)
		{
			UICamera.<>f__mg$cache3 = new UICamera.GetKeyStateFunc(Input.GetKey);
		}
		UICamera.GetKey = UICamera.<>f__mg$cache3;
		if (UICamera.<>f__mg$cache4 == null)
		{
			UICamera.<>f__mg$cache4 = new UICamera.GetAxisFunc(NInput.GetAxis);
		}
		UICamera.GetAxis = UICamera.<>f__mg$cache4;
		UICamera.showTooltips = true;
		UICamera.lastTouchPosition = Vector2.zero;
		UICamera.lastWorldPosition = Vector3.zero;
		UICamera.current = null;
		UICamera.currentCamera = null;
		UICamera.currentScheme = UICamera.ControlScheme.Mouse;
		UICamera.currentTouchID = -100;
		UICamera.currentKey = KeyCode.None;
		UICamera.currentTouch = null;
		UICamera.inputHasFocus = false;
		UICamera.mCurrentSelection = null;
		UICamera.mNextSelection = null;
		UICamera.mNextScheme = UICamera.ControlScheme.Controller;
		UICamera.mMouse = new UICamera.MouseOrTouch[]
		{
			new UICamera.MouseOrTouch(),
			new UICamera.MouseOrTouch(),
			new UICamera.MouseOrTouch()
		};
		UICamera.controller = new UICamera.MouseOrTouch();
		UICamera.mNextEvent = 0f;
		UICamera.mTouches = new Dictionary<int, UICamera.MouseOrTouch>();
		UICamera.mWidth = 0;
		UICamera.mHeight = 0;
		UICamera.isDragging = false;
		UICamera.isFallThrough = false;
		UICamera.isDisableRightClick = false;
		UICamera.mHit = default(UICamera.DepthEntry);
		UICamera.mHits = new BetterList<UICamera.DepthEntry>();
		UICamera.m2DPlane = new Plane(Vector3.back, 0f);
		UICamera.mNotifying = false;
		UICamera.m_unInputEnableFlag = 0u;
		UICamera.InputEnable = true;
		UICamera.mUsingTouchEvents = true;
	}

	public static BetterList<UICamera> list = new BetterList<UICamera>();

	public static UICamera.GetKeyStateFunc GetKeyDown;

	public static UICamera.GetKeyStateFunc GetKeyUp;

	public static UICamera.GetKeyStateFunc GetKey;

	public static UICamera.GetAxisFunc GetAxis;

	public static UICamera.OnScreenResize onScreenResize;

	public UICamera.EventType eventType = UICamera.EventType.UI_3D;

	public bool eventsGoToColliders;

	public LayerMask eventReceiverMask = -1;

	public bool debug;

	public bool useMouse = true;

	public bool useTouch = true;

	public bool allowMultiTouch = true;

	public bool useKeyboard = true;

	public bool useController = true;

	public bool stickyTooltip = true;

	public float tooltipDelay = 1f;

	public float mouseDragThreshold = 4f;

	public float mouseClickThreshold = 10f;

	public float touchDragThreshold = 40f;

	public float touchClickThreshold = 40f;

	public float rangeDistance = -1f;

	public string scrollAxisName = "Mouse ScrollWheel";

	public string verticalAxisName = "Vertical";

	public string horizontalAxisName = "Horizontal";

	public KeyCode submitKey0 = KeyCode.Return;

	public KeyCode submitKey1 = KeyCode.JoystickButton0;

	public KeyCode cancelKey0 = KeyCode.Escape;

	public KeyCode cancelKey1 = KeyCode.JoystickButton1;

	public static UICamera.OnCustomInput onCustomInput;

	public static bool showTooltips;

	public static Vector2 lastTouchPosition;

	public static Vector3 lastWorldPosition;

	public static RaycastHit lastHit;

	public static UICamera current;

	public static Camera currentCamera;

	public static UICamera.ControlScheme currentScheme;

	public static int currentTouchID;

	public static KeyCode currentKey;

	public static UICamera.MouseOrTouch currentTouch;

	public static bool inputHasFocus;

	private static GameObject mGenericHandler;

	public static GameObject fallThrough;

	public static UICamera.VoidDelegate onClick;

	public static UICamera.VoidDelegate onDoubleClick;

	public static UICamera.BoolDelegate onHover;

	public static UICamera.BoolDelegate onPress;

	public static UICamera.BoolDelegate onSelect;

	public static UICamera.FloatDelegate onScroll;

	public static UICamera.VectorDelegate onDrag;

	public static UICamera.VoidDelegate onDragStart;

	public static UICamera.ObjectDelegate onDragOver;

	public static UICamera.ObjectDelegate onDragOut;

	public static UICamera.VoidDelegate onDragEnd;

	public static UICamera.ObjectDelegate onDrop;

	public static UICamera.KeyCodeDelegate onKey;

	public static UICamera.BoolDelegate onTooltip;

	public static UICamera.MoveDelegate onMouseMove;

	private static GameObject mCurrentSelection;

	private static GameObject mNextSelection;

	private static UICamera.ControlScheme mNextScheme;

	private static UICamera.MouseOrTouch[] mMouse;

	private static GameObject mHover;

	public static UICamera.MouseOrTouch controller;

	private static float mNextEvent;

	private static Dictionary<int, UICamera.MouseOrTouch> mTouches;

	private static int mWidth;

	private static int mHeight;

	private GameObject mTooltip;

	private Camera mCam;

	private float mTooltipTime;

	private float mNextRaycast;

	public static bool isDragging;

	public static GameObject hoveredObject;

	public static bool isFallThrough;

	public static bool isDisableRightClick;

	private bool m_bHover;

	private bool m_bProcessEnable = true;

	public bool VRExclusionUI;

	private Vector3[] m_vVirtualMousePos = new Vector3[2];

	private GameObject[] m_goVirtualCursor = new GameObject[2];

	private UI2DSprite[] m_spriteVirtualCursor = new UI2DSprite[2];

	private bool[] m_bVirtualDummyActive = new bool[2];

	private UICamera.VCURSOR m_eCurrentCursorSide = UICamera.VCURSOR.RIGHT;

	private static UICamera.DepthEntry mHit;

	private static BetterList<UICamera.DepthEntry> mHits;

	private static Plane m2DPlane;

	private static bool mNotifying;

	private static uint m_unInputEnableFlag;

	public static bool InputEnable;

	private const float VIRTUAL_SCREEN_SIZE_W = 1920f;

	private const float VIRTUAL_SCREEN_SIZE_H = 1080f;

	private static bool mUsingTouchEvents;

	[CompilerGenerated]
	private static BetterList<UICamera>.CompareFunc <>f__mg$cache0;

	[CompilerGenerated]
	private static UICamera.GetKeyStateFunc <>f__mg$cache1;

	[CompilerGenerated]
	private static UICamera.GetKeyStateFunc <>f__mg$cache2;

	[CompilerGenerated]
	private static UICamera.GetKeyStateFunc <>f__mg$cache3;

	[CompilerGenerated]
	private static UICamera.GetAxisFunc <>f__mg$cache4;

	public enum ControlScheme
	{
		Mouse,
		Touch,
		Controller
	}

	public enum ClickNotification
	{
		None,
		Always,
		BasedOnDelta
	}

	public class MouseOrTouch
	{
		public float deltaTime
		{
			get
			{
				return (!this.touchBegan) ? 0f : (RealTime.time - this.pressTime);
			}
		}

		public bool isOverUI
		{
			get
			{
				return this.current != null && this.current != UICamera.fallThrough && NGUITools.FindInParents<UIRoot>(this.current) != null;
			}
		}

		public Vector2 pos;

		public Vector2 lastPos;

		public Vector2 delta;

		public Vector2 totalDelta;

		public Camera pressedCam;

		public GameObject last;

		public GameObject current;

		public GameObject pressed;

		public GameObject dragged;

		public float pressTime;

		public float clickTime;

		public UICamera.ClickNotification clickNotification = UICamera.ClickNotification.Always;

		public bool touchBegan = true;

		public bool pressStarted;

		public bool dragStarted;
	}

	public enum EventType
	{
		World_3D,
		UI_3D,
		World_2D,
		UI_2D
	}

	public delegate bool GetKeyStateFunc(KeyCode key);

	public delegate float GetAxisFunc(string name);

	public delegate void OnScreenResize();

	public delegate void OnCustomInput();

	public delegate void MoveDelegate(Vector2 delta);

	public delegate void VoidDelegate(GameObject go);

	public delegate void BoolDelegate(GameObject go, bool state);

	public delegate void FloatDelegate(GameObject go, float delta);

	public delegate void VectorDelegate(GameObject go, Vector2 delta);

	public delegate void ObjectDelegate(GameObject go, GameObject obj);

	public delegate void KeyCodeDelegate(GameObject go, KeyCode key);

	public enum VCURSOR
	{
		LEFT,
		RIGHT,
		MAX
	}

	private struct DepthEntry
	{
		public int depth;

		public RaycastHit hit;

		public Vector3 point;

		public GameObject go;
	}

	public enum INPUT_CTRL_TYPE
	{
		FADE = 1,
		EDIT,
		SAVE_LOAD = 4,
		SCHEDULE = 8
	}
}
