123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- 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()
- {
- UICamera[] array = UnityEngine.Object.FindObjectsOfType<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;
- }
- static UICamera()
- {
- // Note: this type is marked as 'beforefieldinit'.
- 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;
- 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
- }
- }
|