forked from hunterzonewu/unity-decompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputField.cs
More file actions
2236 lines (2113 loc) · 77.9 KB
/
InputField.cs
File metadata and controls
2236 lines (2113 loc) · 77.9 KB
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
// Decompiled with JetBrains decompiler
// Type: UnityEngine.UI.InputField
// Assembly: UnityEngine.UI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 2216A18B-AF52-44A5-85A0-A1CAA19C1090
// Assembly location: C:\Users\Blake\sandbox\unity\test-project\Library\UnityAssemblies\UnityEngine.UI.dll
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using UnityEditor;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
namespace UnityEngine.UI
{
/// <summary>
/// <para>Turn a simple label into a interactable input field.</para>
/// </summary>
[AddComponentMenu("UI/Input Field", 31)]
public class InputField : Selectable, IEventSystemHandler, IPointerClickHandler, IBeginDragHandler, IDragHandler, IEndDragHandler, IUpdateSelectedHandler, ISubmitHandler, ICanvasElement
{
private static readonly char[] kSeparators = new char[6]{ ' ', '.', ',', '\t', '\r', '\n' };
[FormerlySerializedAs("asteriskChar")]
[SerializeField]
private char m_AsteriskChar = '*';
[FormerlySerializedAs("m_EndEdit")]
[FormerlySerializedAs("onSubmit")]
[FormerlySerializedAs("m_OnSubmit")]
[SerializeField]
private InputField.SubmitEvent m_OnEndEdit = new InputField.SubmitEvent();
[FormerlySerializedAs("onValueChange")]
[FormerlySerializedAs("m_OnValueChange")]
[SerializeField]
private InputField.OnChangeEvent m_OnValueChanged = new InputField.OnChangeEvent();
[SerializeField]
private Color m_CaretColor = new Color(0.1960784f, 0.1960784f, 0.1960784f, 1f);
[FormerlySerializedAs("selectionColor")]
[SerializeField]
private Color m_SelectionColor = new Color(0.6588235f, 0.8078431f, 1f, 0.7529412f);
[SerializeField]
[FormerlySerializedAs("mValue")]
protected string m_Text = string.Empty;
[SerializeField]
[Range(0.0f, 4f)]
private float m_CaretBlinkRate = 0.85f;
[SerializeField]
[Range(1f, 5f)]
private int m_CaretWidth = 1;
private string m_OriginalText = string.Empty;
private Event m_ProcessingEvent = new Event();
private const float kHScrollSpeed = 0.05f;
private const float kVScrollSpeed = 0.1f;
private const string kEmailSpecialCharacters = "!#$%&'*+-/=?^_`{|}~";
protected TouchScreenKeyboard m_Keyboard;
[SerializeField]
[FormerlySerializedAs("text")]
protected Text m_TextComponent;
[SerializeField]
protected Graphic m_Placeholder;
[SerializeField]
private InputField.ContentType m_ContentType;
[SerializeField]
[FormerlySerializedAs("inputType")]
private InputField.InputType m_InputType;
[FormerlySerializedAs("keyboardType")]
[SerializeField]
private TouchScreenKeyboardType m_KeyboardType;
[SerializeField]
private InputField.LineType m_LineType;
[FormerlySerializedAs("hideMobileInput")]
[SerializeField]
private bool m_HideMobileInput;
[FormerlySerializedAs("validation")]
[SerializeField]
private InputField.CharacterValidation m_CharacterValidation;
[FormerlySerializedAs("characterLimit")]
[SerializeField]
private int m_CharacterLimit;
[FormerlySerializedAs("onValidateInput")]
[SerializeField]
private InputField.OnValidateInput m_OnValidateInput;
[SerializeField]
private bool m_CustomCaretColor;
[SerializeField]
private bool m_ReadOnly;
protected int m_CaretPosition;
protected int m_CaretSelectPosition;
private RectTransform caretRectTrans;
protected UIVertex[] m_CursorVerts;
private TextGenerator m_InputTextCache;
private CanvasRenderer m_CachedInputRenderer;
private bool m_PreventFontCallback;
[NonSerialized]
protected Mesh m_Mesh;
private bool m_AllowInput;
private bool m_ShouldActivateNextUpdate;
private bool m_UpdateDrag;
private bool m_DragPositionOutOfBounds;
protected bool m_CaretVisible;
private Coroutine m_BlinkCoroutine;
private float m_BlinkStartTime;
protected int m_DrawStart;
protected int m_DrawEnd;
private Coroutine m_DragCoroutine;
private bool m_WasCanceled;
private bool m_HasDoneFocusTransition;
protected Mesh mesh
{
get
{
if ((UnityEngine.Object) this.m_Mesh == (UnityEngine.Object) null)
this.m_Mesh = new Mesh();
return this.m_Mesh;
}
}
protected TextGenerator cachedInputTextGenerator
{
get
{
if (this.m_InputTextCache == null)
this.m_InputTextCache = new TextGenerator();
return this.m_InputTextCache;
}
}
/// <summary>
/// <para>Should the mobile keyboard input be hidden.</para>
/// </summary>
public bool shouldHideMobileInput
{
get
{
RuntimePlatform platform = Application.platform;
switch (platform)
{
case RuntimePlatform.IPhonePlayer:
case RuntimePlatform.Android:
return this.m_HideMobileInput;
default:
if (platform != RuntimePlatform.BB10Player && platform != RuntimePlatform.TizenPlayer && platform != RuntimePlatform.tvOS)
return true;
goto case RuntimePlatform.IPhonePlayer;
}
}
set
{
SetPropertyUtility.SetStruct<bool>(ref this.m_HideMobileInput, value);
}
}
private bool shouldActivateOnSelect
{
get
{
return Application.platform != RuntimePlatform.tvOS;
}
}
/// <summary>
/// <para>The current value of the input field.</para>
/// </summary>
public string text
{
get
{
return this.m_Text;
}
set
{
if (this.text == value)
return;
if (this.onValidateInput != null || this.characterValidation != InputField.CharacterValidation.None)
{
this.m_Text = string.Empty;
InputField.OnValidateInput onValidateInput = this.onValidateInput ?? new InputField.OnValidateInput(this.Validate);
this.m_CaretPosition = this.m_CaretSelectPosition = value.Length;
int num = this.characterLimit <= 0 ? value.Length : Math.Min(this.characterLimit - 1, value.Length);
for (int index = 0; index < num; ++index)
{
char ch = onValidateInput(this.m_Text, this.m_Text.Length, value[index]);
if ((int) ch != 0)
this.m_Text += (string) (object) ch;
}
}
else
this.m_Text = this.characterLimit <= 0 || value.Length <= this.characterLimit ? value : value.Substring(0, this.characterLimit);
if (!Application.isPlaying)
{
this.SendOnValueChangedAndUpdateLabel();
}
else
{
if (this.m_Keyboard != null)
this.m_Keyboard.text = this.m_Text;
if (this.m_CaretPosition > this.m_Text.Length)
this.m_CaretPosition = this.m_CaretSelectPosition = this.m_Text.Length;
this.SendOnValueChangedAndUpdateLabel();
}
}
}
/// <summary>
/// <para>Does the InputField currently have focus and is able to process events.</para>
/// </summary>
public bool isFocused
{
get
{
return this.m_AllowInput;
}
}
/// <summary>
/// <para>The blinking rate of the input caret, defined as the number of times the blink cycle occurs per second.</para>
/// </summary>
public float caretBlinkRate
{
get
{
return this.m_CaretBlinkRate;
}
set
{
if (!SetPropertyUtility.SetStruct<float>(ref this.m_CaretBlinkRate, value) || !this.m_AllowInput)
return;
this.SetCaretActive();
}
}
/// <summary>
/// <para>The width of the caret in pixels.</para>
/// </summary>
public int caretWidth
{
get
{
return this.m_CaretWidth;
}
set
{
if (!SetPropertyUtility.SetStruct<int>(ref this.m_CaretWidth, value))
return;
this.MarkGeometryAsDirty();
}
}
/// <summary>
/// <para>The Text component that is going to be used to render the text to screen.</para>
/// </summary>
public Text textComponent
{
get
{
return this.m_TextComponent;
}
set
{
SetPropertyUtility.SetClass<Text>(ref this.m_TextComponent, value);
}
}
/// <summary>
/// <para>This is an optional ‘empty’ graphic to show that InputField text field is empty. Note that this ‘empty' graphic still displays even when the InputField is selected (that is; when there is focus on it).
///
/// A placeholder graphic can be used to show subtle hints or make it more obvious that the control is an InputField.</para>
/// </summary>
public Graphic placeholder
{
get
{
return this.m_Placeholder;
}
set
{
SetPropertyUtility.SetClass<Graphic>(ref this.m_Placeholder, value);
}
}
/// <summary>
/// <para>The custom caret color used if customCaretColor is set.</para>
/// </summary>
public Color caretColor
{
get
{
if (this.customCaretColor)
return this.m_CaretColor;
return this.textComponent.color;
}
set
{
if (!SetPropertyUtility.SetColor(ref this.m_CaretColor, value))
return;
this.MarkGeometryAsDirty();
}
}
/// <summary>
/// <para>Should a custom caret color be used or should the textComponent.color be used.</para>
/// </summary>
public bool customCaretColor
{
get
{
return this.m_CustomCaretColor;
}
set
{
if (this.m_CustomCaretColor == value)
return;
this.m_CustomCaretColor = value;
this.MarkGeometryAsDirty();
}
}
/// <summary>
/// <para>The color of the highlight to show which characters are selected.</para>
/// </summary>
public Color selectionColor
{
get
{
return this.m_SelectionColor;
}
set
{
if (!SetPropertyUtility.SetColor(ref this.m_SelectionColor, value))
return;
this.MarkGeometryAsDirty();
}
}
/// <summary>
/// <para>The Unity Event to call when editing has ended.</para>
/// </summary>
public InputField.SubmitEvent onEndEdit
{
get
{
return this.m_OnEndEdit;
}
set
{
SetPropertyUtility.SetClass<InputField.SubmitEvent>(ref this.m_OnEndEdit, value);
}
}
/// <summary>
/// <para>Accessor to the OnChangeEvent.</para>
/// </summary>
[Obsolete("onValueChange has been renamed to onValueChanged")]
public InputField.OnChangeEvent onValueChange
{
get
{
return this.onValueChanged;
}
set
{
this.onValueChanged = value;
}
}
/// <summary>
/// <para>Accessor to the OnChangeEvent.</para>
/// </summary>
public InputField.OnChangeEvent onValueChanged
{
get
{
return this.m_OnValueChanged;
}
set
{
SetPropertyUtility.SetClass<InputField.OnChangeEvent>(ref this.m_OnValueChanged, value);
}
}
/// <summary>
/// <para>The function to call to validate the input characters.</para>
/// </summary>
public InputField.OnValidateInput onValidateInput
{
get
{
return this.m_OnValidateInput;
}
set
{
SetPropertyUtility.SetClass<InputField.OnValidateInput>(ref this.m_OnValidateInput, value);
}
}
/// <summary>
/// <para>How many characters the input field is limited to. 0 = infinite.</para>
/// </summary>
public int characterLimit
{
get
{
return this.m_CharacterLimit;
}
set
{
if (!SetPropertyUtility.SetStruct<int>(ref this.m_CharacterLimit, Math.Max(0, value)))
return;
this.UpdateLabel();
}
}
/// <summary>
/// <para>Specifies the type of the input text content.</para>
/// </summary>
public InputField.ContentType contentType
{
get
{
return this.m_ContentType;
}
set
{
if (!SetPropertyUtility.SetStruct<InputField.ContentType>(ref this.m_ContentType, value))
return;
this.EnforceContentType();
}
}
/// <summary>
/// <para>The LineType used by the InputField.</para>
/// </summary>
public InputField.LineType lineType
{
get
{
return this.m_LineType;
}
set
{
if (!SetPropertyUtility.SetStruct<InputField.LineType>(ref this.m_LineType, value))
return;
this.SetToCustomIfContentTypeIsNot(InputField.ContentType.Standard, InputField.ContentType.Autocorrected);
}
}
/// <summary>
/// <para>The type of input expected. See InputField.InputType.</para>
/// </summary>
public InputField.InputType inputType
{
get
{
return this.m_InputType;
}
set
{
if (!SetPropertyUtility.SetStruct<InputField.InputType>(ref this.m_InputType, value))
return;
this.SetToCustom();
}
}
/// <summary>
/// <para>They type of mobile keyboard that will be used.</para>
/// </summary>
public TouchScreenKeyboardType keyboardType
{
get
{
return this.m_KeyboardType;
}
set
{
if (!SetPropertyUtility.SetStruct<TouchScreenKeyboardType>(ref this.m_KeyboardType, value))
return;
this.SetToCustom();
}
}
/// <summary>
/// <para>The type of validation to perform on a character.</para>
/// </summary>
public InputField.CharacterValidation characterValidation
{
get
{
return this.m_CharacterValidation;
}
set
{
if (!SetPropertyUtility.SetStruct<InputField.CharacterValidation>(ref this.m_CharacterValidation, value))
return;
this.SetToCustom();
}
}
/// <summary>
/// <para>Set the InputField to be read only.</para>
/// </summary>
public bool readOnly
{
get
{
return this.m_ReadOnly;
}
set
{
this.m_ReadOnly = value;
}
}
/// <summary>
/// <para>If the input field supports multiple lines.</para>
/// </summary>
public bool multiLine
{
get
{
if (this.m_LineType != InputField.LineType.MultiLineNewline)
return this.lineType == InputField.LineType.MultiLineSubmit;
return true;
}
}
/// <summary>
/// <para>The character used for password fields.</para>
/// </summary>
public char asteriskChar
{
get
{
return this.m_AsteriskChar;
}
set
{
if (!SetPropertyUtility.SetStruct<char>(ref this.m_AsteriskChar, value))
return;
this.UpdateLabel();
}
}
/// <summary>
/// <para>If the UI.InputField was canceled and will revert back to the original text upon DeactivateInputField.</para>
/// </summary>
public bool wasCanceled
{
get
{
return this.m_WasCanceled;
}
}
protected int caretPositionInternal
{
get
{
return this.m_CaretPosition + Input.compositionString.Length;
}
set
{
this.m_CaretPosition = value;
this.ClampPos(ref this.m_CaretPosition);
}
}
protected int caretSelectPositionInternal
{
get
{
return this.m_CaretSelectPosition + Input.compositionString.Length;
}
set
{
this.m_CaretSelectPosition = value;
this.ClampPos(ref this.m_CaretSelectPosition);
}
}
private bool hasSelection
{
get
{
return this.caretPositionInternal != this.caretSelectPositionInternal;
}
}
/// <summary>
/// <para>Current InputField selection head.</para>
/// </summary>
[Obsolete("caretSelectPosition has been deprecated. Use selectionFocusPosition instead (UnityUpgradable) -> selectionFocusPosition", true)]
public int caretSelectPosition
{
get
{
return this.selectionFocusPosition;
}
protected set
{
this.selectionFocusPosition = value;
}
}
/// <summary>
/// <para>Current InputField caret position (also selection tail).</para>
/// </summary>
public int caretPosition
{
get
{
return this.m_CaretSelectPosition + Input.compositionString.Length;
}
set
{
this.selectionAnchorPosition = value;
this.selectionFocusPosition = value;
}
}
/// <summary>
/// <para>The beginning point of the selection.</para>
/// </summary>
public int selectionAnchorPosition
{
get
{
return this.m_CaretPosition + Input.compositionString.Length;
}
set
{
if (Input.compositionString.Length != 0)
return;
this.m_CaretPosition = value;
this.ClampPos(ref this.m_CaretPosition);
}
}
/// <summary>
/// <para>The the end point of the selection.</para>
/// </summary>
public int selectionFocusPosition
{
get
{
return this.m_CaretSelectPosition + Input.compositionString.Length;
}
set
{
if (Input.compositionString.Length != 0)
return;
this.m_CaretSelectPosition = value;
this.ClampPos(ref this.m_CaretSelectPosition);
}
}
private static string clipboard
{
get
{
return GUIUtility.systemCopyBuffer;
}
set
{
GUIUtility.systemCopyBuffer = value;
}
}
protected InputField()
{
}
protected void ClampPos(ref int pos)
{
if (pos < 0)
{
pos = 0;
}
else
{
if (pos <= this.text.Length)
return;
pos = this.text.Length;
}
}
protected override void OnValidate()
{
base.OnValidate();
this.EnforceContentType();
this.m_CharacterLimit = Math.Max(0, this.m_CharacterLimit);
if (!this.IsActive())
return;
this.UpdateLabel();
if (!this.m_AllowInput)
return;
this.SetCaretActive();
}
protected override void OnEnable()
{
base.OnEnable();
if (this.m_Text == null)
this.m_Text = string.Empty;
this.m_DrawStart = 0;
this.m_DrawEnd = this.m_Text.Length;
if ((UnityEngine.Object) this.m_CachedInputRenderer != (UnityEngine.Object) null)
this.m_CachedInputRenderer.SetMaterial(Graphic.defaultGraphicMaterial, (Texture) Texture2D.whiteTexture);
if (!((UnityEngine.Object) this.m_TextComponent != (UnityEngine.Object) null))
return;
this.m_TextComponent.RegisterDirtyVerticesCallback(new UnityAction(this.MarkGeometryAsDirty));
this.m_TextComponent.RegisterDirtyVerticesCallback(new UnityAction(this.UpdateLabel));
this.UpdateLabel();
}
/// <summary>
/// <para>See MonoBehaviour.OnDisable.</para>
/// </summary>
protected override void OnDisable()
{
this.m_BlinkCoroutine = (Coroutine) null;
this.DeactivateInputField();
if ((UnityEngine.Object) this.m_TextComponent != (UnityEngine.Object) null)
{
this.m_TextComponent.UnregisterDirtyVerticesCallback(new UnityAction(this.MarkGeometryAsDirty));
this.m_TextComponent.UnregisterDirtyVerticesCallback(new UnityAction(this.UpdateLabel));
}
CanvasUpdateRegistry.UnRegisterCanvasElementForRebuild((ICanvasElement) this);
if ((UnityEngine.Object) this.m_CachedInputRenderer != (UnityEngine.Object) null)
this.m_CachedInputRenderer.Clear();
if ((UnityEngine.Object) this.m_Mesh != (UnityEngine.Object) null)
UnityEngine.Object.DestroyImmediate((UnityEngine.Object) this.m_Mesh);
this.m_Mesh = (Mesh) null;
base.OnDisable();
}
[DebuggerHidden]
private IEnumerator CaretBlink()
{
// ISSUE: object of a compiler-generated type is created
return (IEnumerator) new InputField.\u003CCaretBlink\u003Ec__Iterator3() { \u003C\u003Ef__this = this };
}
private void SetCaretVisible()
{
if (!this.m_AllowInput)
return;
this.m_CaretVisible = true;
this.m_BlinkStartTime = Time.unscaledTime;
this.SetCaretActive();
}
private void SetCaretActive()
{
if (!this.m_AllowInput)
return;
if ((double) this.m_CaretBlinkRate > 0.0)
{
if (this.m_BlinkCoroutine != null)
return;
this.m_BlinkCoroutine = this.StartCoroutine(this.CaretBlink());
}
else
this.m_CaretVisible = true;
}
/// <summary>
/// <para>Focus the input field initializing properties.</para>
/// </summary>
protected void OnFocus()
{
this.SelectAll();
}
/// <summary>
/// <para>Highlight the whole InputField.</para>
/// </summary>
protected void SelectAll()
{
this.caretPositionInternal = this.text.Length;
this.caretSelectPositionInternal = 0;
}
/// <summary>
/// <para>Move the caret index to end of text.</para>
/// </summary>
/// <param name="shift">Only move the selectionPosition.</param>
public void MoveTextEnd(bool shift)
{
int length = this.text.Length;
if (shift)
{
this.caretSelectPositionInternal = length;
}
else
{
this.caretPositionInternal = length;
this.caretSelectPositionInternal = this.caretPositionInternal;
}
this.UpdateLabel();
}
/// <summary>
/// <para>Move the caret index to start of text.</para>
/// </summary>
/// <param name="shift">Only move the selectionPosition.</param>
public void MoveTextStart(bool shift)
{
int num = 0;
if (shift)
{
this.caretSelectPositionInternal = num;
}
else
{
this.caretPositionInternal = num;
this.caretSelectPositionInternal = this.caretPositionInternal;
}
this.UpdateLabel();
}
private bool InPlaceEditing()
{
return !TouchScreenKeyboard.isSupported;
}
protected virtual void LateUpdate()
{
if (this.m_ShouldActivateNextUpdate)
{
if (!this.isFocused)
{
this.ActivateInputFieldInternal();
this.m_ShouldActivateNextUpdate = false;
return;
}
this.m_ShouldActivateNextUpdate = false;
}
if (this.InPlaceEditing() || !this.isFocused)
return;
this.AssignPositioningIfNeeded();
if (this.m_Keyboard == null || !this.m_Keyboard.active)
{
if (this.m_Keyboard != null)
{
if (!this.m_ReadOnly)
this.text = this.m_Keyboard.text;
if (this.m_Keyboard.wasCanceled)
this.m_WasCanceled = true;
}
this.OnDeselect((BaseEventData) null);
}
else
{
string text = this.m_Keyboard.text;
if (this.m_Text != text)
{
if (this.m_ReadOnly)
{
this.m_Keyboard.text = this.m_Text;
}
else
{
this.m_Text = string.Empty;
for (int index = 0; index < text.Length; ++index)
{
char ch = text[index];
switch (ch)
{
case '\r':
case '\x0003':
ch = '\n';
break;
}
if (this.onValidateInput != null)
ch = this.onValidateInput(this.m_Text, this.m_Text.Length, ch);
else if (this.characterValidation != InputField.CharacterValidation.None)
ch = this.Validate(this.m_Text, this.m_Text.Length, ch);
if (this.lineType == InputField.LineType.MultiLineSubmit && (int) ch == 10)
{
this.m_Keyboard.text = this.m_Text;
this.OnDeselect((BaseEventData) null);
return;
}
if ((int) ch != 0)
this.m_Text += (string) (object) ch;
}
if (this.characterLimit > 0 && this.m_Text.Length > this.characterLimit)
this.m_Text = this.m_Text.Substring(0, this.characterLimit);
int length = this.m_Text.Length;
this.caretSelectPositionInternal = length;
this.caretPositionInternal = length;
if (this.m_Text != text)
this.m_Keyboard.text = this.m_Text;
this.SendOnValueChangedAndUpdateLabel();
}
}
if (!this.m_Keyboard.done)
return;
if (this.m_Keyboard.wasCanceled)
this.m_WasCanceled = true;
this.OnDeselect((BaseEventData) null);
}
}
/// <summary>
/// <para>Convert screen space into input field local space.</para>
/// </summary>
/// <param name="screen"></param>
[Obsolete("This function is no longer used. Please use RectTransformUtility.ScreenPointToLocalPointInRectangle() instead.")]
public Vector2 ScreenToLocal(Vector2 screen)
{
Canvas canvas = this.m_TextComponent.canvas;
if ((UnityEngine.Object) canvas == (UnityEngine.Object) null)
return screen;
Vector3 vector3 = Vector3.zero;
if (canvas.renderMode == UnityEngine.RenderMode.ScreenSpaceOverlay)
vector3 = this.m_TextComponent.transform.InverseTransformPoint((Vector3) screen);
else if ((UnityEngine.Object) canvas.worldCamera != (UnityEngine.Object) null)
{
Ray ray = canvas.worldCamera.ScreenPointToRay((Vector3) screen);
float enter;
new Plane(this.m_TextComponent.transform.forward, this.m_TextComponent.transform.position).Raycast(ray, out enter);
vector3 = this.m_TextComponent.transform.InverseTransformPoint(ray.GetPoint(enter));
}
return new Vector2(vector3.x, vector3.y);
}
private int GetUnclampedCharacterLineFromPosition(Vector2 pos, TextGenerator generator)
{
if (!this.multiLine)
return 0;
float num1 = pos.y * this.m_TextComponent.pixelsPerUnit;
float num2 = 0.0f;
for (int index = 0; index < generator.lineCount; ++index)
{
float topY = generator.lines[index].topY;
float num3 = topY - (float) generator.lines[index].height;
if ((double) num1 > (double) topY)
{
float num4 = topY - num2;
if ((double) num1 > (double) topY - 0.5 * (double) num4)
return index - 1;
return index;
}
if ((double) num1 > (double) num3)
return index;
num2 = num3;
}
return generator.lineCount;
}
/// <summary>
/// <para>The character that is under the mouse.</para>
/// </summary>
/// <param name="pos">Mouse position.</param>
/// <returns>
/// <para>Character index with in value.</para>
/// </returns>
protected int GetCharacterIndexFromPosition(Vector2 pos)
{
TextGenerator cachedTextGenerator = this.m_TextComponent.cachedTextGenerator;
if (cachedTextGenerator.lineCount == 0)
return 0;
int lineFromPosition = this.GetUnclampedCharacterLineFromPosition(pos, cachedTextGenerator);
if (lineFromPosition < 0)
return 0;
if (lineFromPosition >= cachedTextGenerator.lineCount)
return cachedTextGenerator.characterCountVisible;
int startCharIdx = cachedTextGenerator.lines[lineFromPosition].startCharIdx;
int lineEndPosition = InputField.GetLineEndPosition(cachedTextGenerator, lineFromPosition);
for (int index = startCharIdx; index < lineEndPosition && index < cachedTextGenerator.characterCountVisible; ++index)
{
UICharInfo character = cachedTextGenerator.characters[index];
Vector2 vector2 = character.cursorPos / this.m_TextComponent.pixelsPerUnit;
if ((double) (pos.x - vector2.x) < (double) (vector2.x + character.charWidth / this.m_TextComponent.pixelsPerUnit - pos.x))
return index;
}
return lineEndPosition;
}
private bool MayDrag(PointerEventData eventData)
{
if (this.IsActive() && this.IsInteractable() && (eventData.button == PointerEventData.InputButton.Left && (UnityEngine.Object) this.m_TextComponent != (UnityEngine.Object) null))
return this.m_Keyboard == null;
return false;
}
/// <summary>
/// <para>Capture the OnBeginDrag callback from the EventSystem and ensure we should listen to the drag events to follow.</para>
/// </summary>
/// <param name="eventData">The data passed by the EventSystem.</param>
public virtual void OnBeginDrag(PointerEventData eventData)
{
if (!this.MayDrag(eventData))
return;
this.m_UpdateDrag = true;
}