-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathUICamera.cs
1650 lines (1495 loc) · 37.5 KB
/
UICamera.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[AddComponentMenu("NGUI/UI/NGUI Event System (UICamera)")]
[ExecuteInEditMode]
[RequireComponent(typeof(Camera))]
public class UICamera : MonoBehaviour
{
public enum ControlScheme
{
Mouse,
Touch,
Controller
}
public enum ClickNotification
{
None,
Always,
BasedOnDelta
}
public class MouseOrTouch
{
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 ClickNotification clickNotification = ClickNotification.Always;
public bool touchBegan = true;
public bool pressStarted;
public bool dragStarted;
public float deltaTime => (!touchBegan) ? 0f : (RealTime.time - pressTime);
public bool isOverUI => current != null && current != fallThrough && NGUITools.FindInParents<UIRoot>(current) != null;
}
public enum EventType
{
World_3D,
UI_3D,
World_2D,
UI_2D
}
private struct DepthEntry
{
public int depth;
public RaycastHit hit;
public Vector3 point;
public GameObject go;
}
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 static BetterList<UICamera> list = new BetterList<UICamera>();
public static GetKeyStateFunc GetKeyDown = Input.GetKeyDown;
public static GetKeyStateFunc GetKeyUp = Input.GetKeyUp;
public static GetKeyStateFunc GetKey = Input.GetKey;
public static GetAxisFunc GetAxis = Input.GetAxis;
public static OnScreenResize onScreenResize;
public EventType eventType = 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 OnCustomInput onCustomInput;
public static bool showTooltips = true;
public static Vector2 lastTouchPosition = Vector2.zero;
public static Vector3 lastWorldPosition = Vector3.zero;
public static RaycastHit lastHit;
public static UICamera current = null;
public static Camera currentCamera = null;
public static ControlScheme currentScheme = ControlScheme.Mouse;
public static int currentTouchID = -1;
public static KeyCode currentKey = KeyCode.None;
public static MouseOrTouch currentTouch = null;
public static bool inputHasFocus = false;
private static GameObject mGenericHandler;
public static GameObject fallThrough;
public static VoidDelegate onClick;
public static VoidDelegate onDoubleClick;
public static BoolDelegate onHover;
public static BoolDelegate onPress;
public static BoolDelegate onSelect;
public static FloatDelegate onScroll;
public static VectorDelegate onDrag;
public static VoidDelegate onDragStart;
public static ObjectDelegate onDragOver;
public static ObjectDelegate onDragOut;
public static VoidDelegate onDragEnd;
public static ObjectDelegate onDrop;
public static KeyCodeDelegate onKey;
public static BoolDelegate onTooltip;
public static MoveDelegate onMouseMove;
private static GameObject mCurrentSelection = null;
private static GameObject mNextSelection = null;
private static ControlScheme mNextScheme = ControlScheme.Controller;
private static MouseOrTouch[] mMouse = new MouseOrTouch[3]
{
new MouseOrTouch(),
new MouseOrTouch(),
new MouseOrTouch()
};
private static GameObject mHover;
public static MouseOrTouch controller = new MouseOrTouch();
private static float mNextEvent = 0f;
private static Dictionary<int, MouseOrTouch> mTouches = new Dictionary<int, MouseOrTouch>();
private static int mWidth = 0;
private static int mHeight = 0;
private GameObject mTooltip;
private Camera mCam;
private float mTooltipTime;
private float mNextRaycast;
public static bool isDragging = false;
public static GameObject hoveredObject;
private static DepthEntry mHit = default(DepthEntry);
private static BetterList<DepthEntry> mHits = new BetterList<DepthEntry>();
private static Plane m2DPlane = new Plane(Vector3.back, 0f);
private static bool mNotifying = false;
[Obsolete("Use new OnDragStart / OnDragOver / OnDragOut / OnDragEnd events instead")]
public bool stickyPress
{
get
{
return true;
}
}
public static Ray currentRay => (!(currentCamera != null) || currentTouch == null) ? default(Ray) : currentCamera.ScreenPointToRay(currentTouch.pos);
[Obsolete("Use delegates instead such as UICamera.onClick, UICamera.onHover, etc.")]
public static GameObject genericEventHandler
{
get
{
return mGenericHandler;
}
set
{
mGenericHandler = value;
}
}
private bool handlesEvents => eventHandler == this;
public Camera cachedCamera
{
get
{
if (mCam == null)
{
mCam = GetComponent<Camera>();
}
return mCam;
}
}
public static bool isOverUI
{
get
{
if (currentTouch != null)
{
return currentTouch.isOverUI;
}
if (hoveredObject == null)
{
return false;
}
if (hoveredObject == fallThrough)
{
return false;
}
return NGUITools.FindInParents<UIRoot>(hoveredObject) != null;
}
}
public static GameObject selectedObject
{
get
{
return mCurrentSelection;
}
set
{
SetSelection(value, currentScheme);
}
}
public static int touchCount
{
get
{
int num = 0;
foreach (KeyValuePair<int, MouseOrTouch> mTouch in mTouches)
{
if (mTouch.Value.pressed != null)
{
num++;
}
}
for (int i = 0; i < mMouse.Length; i++)
{
if (mMouse[i].pressed != null)
{
num++;
}
}
if (controller.pressed != null)
{
num++;
}
return num;
}
}
public static int dragCount
{
get
{
int num = 0;
foreach (KeyValuePair<int, MouseOrTouch> mTouch in mTouches)
{
if (mTouch.Value.dragged != null)
{
num++;
}
}
for (int i = 0; i < mMouse.Length; i++)
{
if (mMouse[i].dragged != null)
{
num++;
}
}
if (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 < list.size; i++)
{
UICamera uICamera = list.buffer[i];
if (!(uICamera == null) && uICamera.enabled && NGUITools.GetActive(uICamera.gameObject))
{
return uICamera;
}
}
return null;
}
}
public static bool IsPressed(GameObject go)
{
for (int i = 0; i < 3; i++)
{
if (mMouse[i].pressed == go)
{
return true;
}
}
foreach (KeyValuePair<int, MouseOrTouch> mTouch in mTouches)
{
if (mTouch.Value.pressed == go)
{
return true;
}
}
if (controller.pressed == go)
{
return true;
}
return false;
}
protected static void SetSelection(GameObject go, ControlScheme scheme)
{
if (mNextSelection != null)
{
mNextSelection = go;
}
else if (mCurrentSelection != go)
{
mNextSelection = go;
mNextScheme = scheme;
if (list.size > 0)
{
UICamera uICamera = (!(mNextSelection != null)) ? list[0] : FindCameraForLayer(mNextSelection.layer);
if (uICamera != null)
{
uICamera.StartCoroutine(uICamera.ChangeSelection());
}
}
}
}
private IEnumerator ChangeSelection()
{
yield return (object)new WaitForEndOfFrame();
if (onSelect != null)
{
onSelect(mCurrentSelection, state: false);
}
Notify(mCurrentSelection, "OnSelect", false);
mCurrentSelection = mNextSelection;
mNextSelection = null;
if (mCurrentSelection != null)
{
current = this;
currentCamera = mCam;
currentScheme = mNextScheme;
inputHasFocus = (mCurrentSelection.GetComponent<UIInput>() != null);
if (onSelect != null)
{
onSelect(mCurrentSelection, state: true);
}
Notify(mCurrentSelection, "OnSelect", true);
current = null;
}
else
{
inputHasFocus = false;
}
}
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 < list.size; i++)
{
UICamera uICamera = list.buffer[i];
if (uICamera.enabled && NGUITools.GetActive(uICamera.gameObject))
{
currentCamera = uICamera.cachedCamera;
Vector3 vector = currentCamera.ScreenToViewportPoint(inPos);
if (!float.IsNaN(vector.x) && !float.IsNaN(vector.y) && !(vector.x < 0f) && !(vector.x > 1f) && !(vector.y < 0f) && !(vector.y > 1f))
{
Ray ray = currentCamera.ScreenPointToRay(inPos);
int layerMask = currentCamera.cullingMask & (int)uICamera.eventReceiverMask;
float enter = (!(uICamera.rangeDistance > 0f)) ? (currentCamera.farClipPlane - currentCamera.nearClipPlane) : uICamera.rangeDistance;
if (uICamera.eventType == EventType.World_3D)
{
if (Physics.Raycast(ray, out lastHit, enter, layerMask))
{
lastWorldPosition = lastHit.point;
hoveredObject = lastHit.collider.gameObject;
if (!uICamera.eventsGoToColliders)
{
Rigidbody rigidbody = FindRootRigidbody(hoveredObject.transform);
if (rigidbody != null)
{
hoveredObject = rigidbody.gameObject;
}
}
return true;
}
}
else if (uICamera.eventType == EventType.UI_3D)
{
RaycastHit[] array = Physics.RaycastAll(ray, enter, layerMask);
if (array.Length > 1)
{
for (int j = 0; j < array.Length; j++)
{
GameObject gameObject = array[j].collider.gameObject;
UIWidget component = gameObject.GetComponent<UIWidget>();
if (component != null)
{
if (!component.isVisible || (component.hitCheck != null && !component.hitCheck(array[j].point)))
{
continue;
}
}
else
{
UIRect uIRect = NGUITools.FindInParents<UIRect>(gameObject);
if (uIRect != null && uIRect.finalAlpha < 0.001f)
{
continue;
}
}
mHit.depth = NGUITools.CalculateRaycastDepth(gameObject);
if (mHit.depth != 2147483647)
{
mHit.hit = array[j];
mHit.point = array[j].point;
mHit.go = array[j].collider.gameObject;
mHits.Add(mHit);
}
}
mHits.Sort((DepthEntry r1, DepthEntry r2) => r2.depth.CompareTo(r1.depth));
for (int k = 0; k < mHits.size; k++)
{
if (IsVisible(ref mHits.buffer[k]))
{
DepthEntry depthEntry = mHits[k];
lastHit = depthEntry.hit;
DepthEntry depthEntry2 = mHits[k];
hoveredObject = depthEntry2.go;
DepthEntry depthEntry3 = mHits[k];
lastWorldPosition = depthEntry3.point;
mHits.Clear();
return true;
}
}
mHits.Clear();
}
else if (array.Length == 1)
{
GameObject gameObject2 = array[0].collider.gameObject;
UIWidget component2 = gameObject2.GetComponent<UIWidget>();
if (component2 != null)
{
if (!component2.isVisible || (component2.hitCheck != null && !component2.hitCheck(array[0].point)))
{
continue;
}
}
else
{
UIRect uIRect2 = NGUITools.FindInParents<UIRect>(gameObject2);
if (uIRect2 != null && uIRect2.finalAlpha < 0.001f)
{
continue;
}
}
if (IsVisible(array[0].point, array[0].collider.gameObject))
{
lastHit = array[0];
lastWorldPosition = array[0].point;
hoveredObject = lastHit.collider.gameObject;
return true;
}
}
}
else if (uICamera.eventType == EventType.World_2D)
{
if (m2DPlane.Raycast(ray, out enter))
{
Vector3 point = ray.GetPoint(enter);
Collider2D collider2D = Physics2D.OverlapPoint(point, layerMask);
if ((bool)collider2D)
{
lastWorldPosition = point;
hoveredObject = collider2D.gameObject;
if (!uICamera.eventsGoToColliders)
{
Rigidbody2D rigidbody2D = FindRootRigidbody2D(hoveredObject.transform);
if (rigidbody2D != null)
{
hoveredObject = rigidbody2D.gameObject;
}
}
return true;
}
}
}
else if (uICamera.eventType == EventType.UI_2D && m2DPlane.Raycast(ray, out enter))
{
lastWorldPosition = ray.GetPoint(enter);
Collider2D[] array2 = Physics2D.OverlapPointAll(lastWorldPosition, layerMask);
if (array2.Length > 1)
{
for (int l = 0; l < array2.Length; l++)
{
GameObject gameObject3 = array2[l].gameObject;
UIWidget component3 = gameObject3.GetComponent<UIWidget>();
if (component3 != null)
{
if (!component3.isVisible || (component3.hitCheck != null && !component3.hitCheck(lastWorldPosition)))
{
continue;
}
}
else
{
UIRect uIRect3 = NGUITools.FindInParents<UIRect>(gameObject3);
if (uIRect3 != null && uIRect3.finalAlpha < 0.001f)
{
continue;
}
}
mHit.depth = NGUITools.CalculateRaycastDepth(gameObject3);
if (mHit.depth != 2147483647)
{
mHit.go = gameObject3;
mHit.point = lastWorldPosition;
mHits.Add(mHit);
}
}
mHits.Sort((DepthEntry r1, DepthEntry r2) => r2.depth.CompareTo(r1.depth));
for (int m = 0; m < mHits.size; m++)
{
if (IsVisible(ref mHits.buffer[m]))
{
DepthEntry depthEntry4 = mHits[m];
hoveredObject = depthEntry4.go;
mHits.Clear();
return true;
}
}
mHits.Clear();
}
else if (array2.Length == 1)
{
GameObject gameObject4 = array2[0].gameObject;
UIWidget component4 = gameObject4.GetComponent<UIWidget>();
if (component4 != null)
{
if (!component4.isVisible || (component4.hitCheck != null && !component4.hitCheck(lastWorldPosition)))
{
continue;
}
}
else
{
UIRect uIRect4 = NGUITools.FindInParents<UIRect>(gameObject4);
if (uIRect4 != null && uIRect4.finalAlpha < 0.001f)
{
continue;
}
}
if (IsVisible(lastWorldPosition, gameObject4))
{
hoveredObject = gameObject4;
return true;
}
}
}
}
}
}
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 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 (currentScheme == ControlScheme.Mouse)
{
return hoveredObject == go;
}
if (currentScheme == ControlScheme.Controller)
{
return selectedObject == go;
}
return false;
}
public static UICamera FindCameraForLayer(int layer)
{
int num = 1 << layer;
for (int i = 0; i < list.size; i++)
{
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 (GetKeyDown(up))
{
return 1;
}
if (GetKeyDown(down))
{
return -1;
}
return 0;
}
private static int GetDirection(KeyCode up0, KeyCode up1, KeyCode down0, KeyCode down1)
{
if (GetKeyDown(up0) || GetKeyDown(up1))
{
return 1;
}
if (GetKeyDown(down0) || GetKeyDown(down1))
{
return -1;
}
return 0;
}
private static int GetDirection(string axis)
{
float time = RealTime.time;
if (mNextEvent < time && !string.IsNullOrEmpty(axis))
{
float num = GetAxis(axis);
if (num > 0.75f)
{
mNextEvent = time + 0.25f;
return 1;
}
if (num < -0.75f)
{
mNextEvent = time + 0.25f;
return -1;
}
}
return 0;
}
public static void Notify(GameObject go, string funcName, object obj)
{
if (!mNotifying)
{
mNotifying = true;
if (NGUITools.GetActive(go))
{
go.SendMessage(funcName, obj, SendMessageOptions.DontRequireReceiver);
if (mGenericHandler != null && mGenericHandler != go)
{
mGenericHandler.SendMessage(funcName, obj, SendMessageOptions.DontRequireReceiver);
}
}
mNotifying = false;
}
}
public static MouseOrTouch GetMouse(int button)
{
return mMouse[button];
}
public static MouseOrTouch GetTouch(int id)
{
MouseOrTouch value = null;
if (id < 0)
{
return GetMouse(-id - 1);
}
if (!mTouches.TryGetValue(id, out value))
{
value = new MouseOrTouch();
value.pressTime = RealTime.time;
value.touchBegan = true;
mTouches.Add(id, value);
}
return value;
}
public static void RemoveTouch(int id)
{
mTouches.Remove(id);
}
private void Awake()
{
mWidth = Screen.width;
mHeight = Screen.height;
if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.WP8Player || Application.platform == RuntimePlatform.BlackBerryPlayer)
{
useTouch = true;
if (Application.platform == RuntimePlatform.IPhonePlayer)
{
useMouse = false;
useKeyboard = false;
useController = false;
}
}
else if (Application.platform == RuntimePlatform.PS3 || Application.platform == RuntimePlatform.XBOX360)
{
useMouse = false;
useTouch = false;
useKeyboard = false;
useController = true;
}
mMouse[0].pos = Input.mousePosition;
for (int i = 1; i < 3; i++)
{
mMouse[i].pos = mMouse[0].pos;
mMouse[i].lastPos = mMouse[0].pos;
}
lastTouchPosition = mMouse[0].pos;
}
private void OnEnable()
{
list.Add(this);
list.Sort(CompareFunc);
}
private void OnDisable()
{
list.Remove(this);
}
private void Start()
{
if (eventType != 0 && cachedCamera.transparencySortMode != TransparencySortMode.Orthographic)
{
cachedCamera.transparencySortMode = TransparencySortMode.Orthographic;
}
if (Application.isPlaying)
{
if (fallThrough == null)
{
UIRoot uIRoot = NGUITools.FindInParents<UIRoot>(base.gameObject);
if (uIRoot != null)
{
fallThrough = uIRoot.gameObject;
}
else
{
Transform transform = base.transform;
fallThrough = ((!(transform.parent != null)) ? base.gameObject : transform.parent.gameObject);
}
}
cachedCamera.eventMask = 0;
}
if (handlesEvents)
{
NGUIDebug.debugRaycast = debug;
}
}
private void Update()
{
if (handlesEvents)
{
current = this;
if (useTouch)
{
ProcessTouches();
}
else if (useMouse)
{
ProcessMouse();
}
if (onCustomInput != null)
{
onCustomInput();
}
if (useMouse && mCurrentSelection != null)
{
if (cancelKey0 != 0 && GetKeyDown(cancelKey0))
{
currentScheme = ControlScheme.Controller;
currentKey = cancelKey0;
selectedObject = null;
}
else if (cancelKey1 != 0 && GetKeyDown(cancelKey1))
{
currentScheme = ControlScheme.Controller;
currentKey = cancelKey1;
selectedObject = null;
}
}
if (mCurrentSelection == null)
{
inputHasFocus = false;
}
if (mCurrentSelection != null)
{
ProcessOthers();
}
if (useMouse && mHover != null)