using System; using System.Collections; using System.Collections.Generic; using UnityEngine.Events; using UnityEngine.EventSystems; using UnityEngine.Serialization; namespace UnityEngine.UI { public class uGUIInputField : Selectable, IUpdateSelectedHandler, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerClickHandler, ISubmitHandler, ICanvasElement, ILayoutElement, IEventSystemHandler { protected uGUIInputField() { this.EnforceTextHOverflow(); } private BaseInput input { get { if (EventSystem.current && EventSystem.current.currentInputModule) { return EventSystem.current.currentInputModule.input; } return null; } } private string compositionString { get { return (!(this.input != null)) ? Input.compositionString : this.input.compositionString; } } protected Mesh mesh { get { if (this.m_Mesh == 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; } } public bool shouldHideMobileInput { get { RuntimePlatform platform = Application.platform; switch (platform) { case RuntimePlatform.IPhonePlayer: case RuntimePlatform.Android: break; default: if (platform != RuntimePlatform.TizenPlayer && platform != RuntimePlatform.tvOS) { return true; } break; } return this.m_HideMobileInput; } set { SetPropertyUtility.SetStruct(ref this.m_HideMobileInput, value); } } private bool shouldActivateOnSelect { get { return Application.platform != RuntimePlatform.tvOS; } } public string text { get { return this.m_Text; } set { if (this.text == value) { return; } if (value == null) { value = string.Empty; } value = value.Replace("\0", string.Empty); if (this.m_LineType == uGUIInputField.LineType.SingleLine) { value = value.Replace("\n", string.Empty).Replace("\t", string.Empty); } if (this.onValidateInput != null || this.characterValidation != uGUIInputField.CharacterValidation.None) { this.m_Text = string.Empty; uGUIInputField.OnValidateInput onValidateInput = this.onValidateInput ?? new uGUIInputField.OnValidateInput(this.Validate); this.m_CaretPosition = (this.m_CaretSelectPosition = value.Length); int num = (this.characterLimit <= 0) ? value.Length : Math.Min(this.characterLimit, value.Length); for (int i = 0; i < num; i++) { char c = onValidateInput(this.m_Text, this.m_Text.Length, value[i]); if (c != '\0') { this.m_Text += c; } } } else { this.m_Text = ((this.characterLimit <= 0 || value.Length <= this.characterLimit) ? value : value.Substring(0, this.characterLimit)); } 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); } else if (this.m_CaretSelectPosition > this.m_Text.Length) { this.m_CaretSelectPosition = this.m_Text.Length; } this.SendOnValueChangedAndUpdateLabel(); } } public bool isFocused { get { return this.m_AllowInput; } } public float caretBlinkRate { get { return this.m_CaretBlinkRate; } set { if (SetPropertyUtility.SetStruct(ref this.m_CaretBlinkRate, value) && this.m_AllowInput) { this.SetCaretActive(); } } } public int caretWidth { get { return this.m_CaretWidth; } set { if (SetPropertyUtility.SetStruct(ref this.m_CaretWidth, value)) { this.MarkGeometryAsDirty(); } } } public Text textComponent { get { return this.m_TextComponent; } set { if (SetPropertyUtility.SetClass(ref this.m_TextComponent, value)) { this.EnforceTextHOverflow(); } } } public Graphic placeholder { get { return this.m_Placeholder; } set { SetPropertyUtility.SetClass(ref this.m_Placeholder, value); } } public Color caretColor { get { return (!this.customCaretColor) ? this.textComponent.color : this.m_CaretColor; } set { if (SetPropertyUtility.SetColor(ref this.m_CaretColor, value)) { this.MarkGeometryAsDirty(); } } } public bool customCaretColor { get { return this.m_CustomCaretColor; } set { if (this.m_CustomCaretColor != value) { this.m_CustomCaretColor = value; this.MarkGeometryAsDirty(); } } } public Color selectionColor { get { return this.m_SelectionColor; } set { if (SetPropertyUtility.SetColor(ref this.m_SelectionColor, value)) { this.MarkGeometryAsDirty(); } } } public uGUIInputField.SubmitEvent onEndEdit { get { return this.m_OnEndEdit; } set { SetPropertyUtility.SetClass(ref this.m_OnEndEdit, value); } } [Obsolete("onValueChange has been renamed to onValueChanged")] public uGUIInputField.OnChangeEvent onValueChange { get { return this.onValueChanged; } set { this.onValueChanged = value; } } public uGUIInputField.OnChangeEvent onValueChanged { get { return this.m_OnValueChanged; } set { SetPropertyUtility.SetClass(ref this.m_OnValueChanged, value); } } public uGUIInputField.OnValidateInput onValidateInput { get { return this.m_OnValidateInput; } set { SetPropertyUtility.SetClass(ref this.m_OnValidateInput, value); } } public int characterLimit { get { return this.m_CharacterLimit; } set { if (SetPropertyUtility.SetStruct(ref this.m_CharacterLimit, Math.Max(0, value))) { this.UpdateLabel(); } } } public uGUIInputField.ContentType contentType { get { return this.m_ContentType; } set { if (SetPropertyUtility.SetStruct(ref this.m_ContentType, value)) { this.EnforceContentType(); } } } public uGUIInputField.LineType lineType { get { return this.m_LineType; } set { if (SetPropertyUtility.SetStruct(ref this.m_LineType, value)) { this.SetToCustomIfContentTypeIsNot(new uGUIInputField.ContentType[] { uGUIInputField.ContentType.Standard, uGUIInputField.ContentType.Autocorrected }); this.EnforceTextHOverflow(); } } } public uGUIInputField.InputType inputType { get { return this.m_InputType; } set { if (SetPropertyUtility.SetStruct(ref this.m_InputType, value)) { this.SetToCustom(); } } } public TouchScreenKeyboardType keyboardType { get { return this.m_KeyboardType; } set { if (SetPropertyUtility.SetStruct(ref this.m_KeyboardType, value)) { this.SetToCustom(); } } } public uGUIInputField.CharacterValidation characterValidation { get { return this.m_CharacterValidation; } set { if (SetPropertyUtility.SetStruct(ref this.m_CharacterValidation, value)) { this.SetToCustom(); } } } public bool readOnly { get { return this.m_ReadOnly; } set { this.m_ReadOnly = value; } } public bool multiLine { get { return this.m_LineType == uGUIInputField.LineType.MultiLineNewline || this.lineType == uGUIInputField.LineType.MultiLineSubmit; } } public char asteriskChar { get { return this.m_AsteriskChar; } set { if (SetPropertyUtility.SetStruct(ref this.m_AsteriskChar, value)) { this.UpdateLabel(); } } } public bool wasCanceled { get { return this.m_WasCanceled; } } protected void ClampPos(ref int pos) { if (pos < 0) { pos = 0; } else if (pos > this.text.Length) { pos = this.text.Length; } } protected int caretPositionInternal { get { return this.m_CaretPosition + this.compositionString.Length; } set { this.m_CaretPosition = value; this.ClampPos(ref this.m_CaretPosition); } } protected int caretSelectPositionInternal { get { return this.m_CaretSelectPosition + this.compositionString.Length; } set { this.m_CaretSelectPosition = value; this.ClampPos(ref this.m_CaretSelectPosition); } } private bool hasSelection { get { return this.caretPositionInternal != this.caretSelectPositionInternal; } } public int caretPosition { get { return this.m_CaretSelectPosition + this.compositionString.Length; } set { this.selectionAnchorPosition = value; this.selectionFocusPosition = value; } } public int selectionAnchorPosition { get { return this.m_CaretPosition + this.compositionString.Length; } set { if (this.compositionString.Length != 0) { return; } this.m_CaretPosition = value; this.ClampPos(ref this.m_CaretPosition); } } public int selectionFocusPosition { get { return this.m_CaretSelectPosition + this.compositionString.Length; } set { if (this.compositionString.Length != 0) { return; } this.m_CaretSelectPosition = value; this.ClampPos(ref this.m_CaretSelectPosition); } } 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 (this.m_CachedInputRenderer != null) { this.m_CachedInputRenderer.SetMaterial(this.m_TextComponent.GetModifiedMaterial(Graphic.defaultGraphicMaterial), Texture2D.whiteTexture); } if (this.m_TextComponent != null) { this.m_TextComponent.RegisterDirtyVerticesCallback(new UnityAction(this.MarkGeometryAsDirty)); this.m_TextComponent.RegisterDirtyVerticesCallback(new UnityAction(this.UpdateLabel)); this.m_TextComponent.RegisterDirtyMaterialCallback(new UnityAction(this.UpdateCaretMaterial)); this.UpdateLabel(); } } protected override void OnDisable() { this.m_BlinkCoroutine = null; this.DeactivateuGUIInputField(); if (this.m_TextComponent != null) { this.m_TextComponent.UnregisterDirtyVerticesCallback(new UnityAction(this.MarkGeometryAsDirty)); this.m_TextComponent.UnregisterDirtyVerticesCallback(new UnityAction(this.UpdateLabel)); this.m_TextComponent.UnregisterDirtyMaterialCallback(new UnityAction(this.UpdateCaretMaterial)); } CanvasUpdateRegistry.UnRegisterCanvasElementForRebuild(this); if (this.m_CachedInputRenderer != null) { this.m_CachedInputRenderer.Clear(); } if (this.m_Mesh != null) { Object.DestroyImmediate(this.m_Mesh); } this.m_Mesh = null; base.OnDisable(); } private IEnumerator CaretBlink() { this.m_CaretVisible = true; yield return null; while (this.isFocused && this.m_CaretBlinkRate > 0f) { float blinkPeriod = 1f / this.m_CaretBlinkRate; bool blinkState = (Time.unscaledTime - this.m_BlinkStartTime) % blinkPeriod < blinkPeriod / 2f; if (this.m_CaretVisible != blinkState) { this.m_CaretVisible = blinkState; if (!this.hasSelection) { this.MarkGeometryAsDirty(); } } yield return null; } this.m_BlinkCoroutine = null; yield break; } 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 (this.m_CaretBlinkRate > 0f) { if (this.m_BlinkCoroutine == null) { this.m_BlinkCoroutine = base.StartCoroutine(this.CaretBlink()); } } else { this.m_CaretVisible = true; } } private void UpdateCaretMaterial() { if (this.m_TextComponent != null && this.m_CachedInputRenderer != null) { this.m_CachedInputRenderer.SetMaterial(this.m_TextComponent.GetModifiedMaterial(Graphic.defaultGraphicMaterial), Texture2D.whiteTexture); } } protected void OnFocus() { this.SelectAll(); } protected void SelectAll() { this.caretPositionInternal = this.text.Length; this.caretSelectPositionInternal = 0; } 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(); } public void MoveTextStart(bool shift) { int num = 0; if (shift) { this.caretSelectPositionInternal = num; } else { this.caretPositionInternal = num; this.caretSelectPositionInternal = this.caretPositionInternal; } this.UpdateLabel(); } private static string clipboard { get { return GUIUtility.systemCopyBuffer; } set { GUIUtility.systemCopyBuffer = value; } } private bool InPlaceEditing() { return !TouchScreenKeyboard.isSupported; } private void UpdateCaretFromKeyboard() { RangeInt selection = this.m_Keyboard.selection; int start = selection.start; int end = selection.end; bool flag = false; if (this.caretPositionInternal != start) { flag = true; this.caretPositionInternal = start; } if (this.caretSelectPositionInternal != end) { this.caretSelectPositionInternal = end; flag = true; } if (flag) { this.m_BlinkStartTime = Time.unscaledTime; this.UpdateLabel(); } } protected virtual void LateUpdate() { if (this.m_ShouldActivateNextUpdate) { if (!this.isFocused) { this.ActivateuGUIInputFieldInternal(); 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.done) { 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.m_Text = this.m_Keyboard.text; this.SendOnValueChangedAndUpdateLabel(); } this.OnDeselect(null); return; } 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; foreach (char c in text) { if (c == '\r' || c == '\u0003') { c = '\n'; } if (this.onValidateInput != null) { c = this.onValidateInput(this.m_Text, this.m_Text.Length, c); } else if (this.characterValidation != uGUIInputField.CharacterValidation.None) { c = this.Validate(this.m_Text, this.m_Text.Length, c); } if (this.lineType == uGUIInputField.LineType.MultiLineSubmit && c == '\n') { this.m_Keyboard.text = this.m_Text; this.OnDeselect(null); return; } if (c != '\0') { this.m_Text += c; } } if (this.characterLimit > 0 && this.m_Text.Length > this.characterLimit) { this.m_Text = this.m_Text.Substring(0, this.characterLimit); } if (this.m_Keyboard.canGetSelection) { this.UpdateCaretFromKeyboard(); } else { 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(); } } else if (this.m_Keyboard.canGetSelection) { this.UpdateCaretFromKeyboard(); } if (this.m_Keyboard.done) { if (this.m_Keyboard.wasCanceled) { this.m_WasCanceled = true; } this.OnDeselect(null); } } [Obsolete("This function is no longer used. Please use RectTransformUtility.ScreenPointToLocalPointInRectangle() instead.")] public Vector2 ScreenToLocal(Vector2 screen) { Canvas canvas = this.m_TextComponent.canvas; if (canvas == null) { return screen; } Vector3 vector = Vector3.zero; if (canvas.renderMode == RenderMode.ScreenSpaceOverlay) { vector = this.m_TextComponent.transform.InverseTransformPoint(screen); } else if (canvas.worldCamera != null) { Ray ray = canvas.worldCamera.ScreenPointToRay(screen); Plane plane = new Plane(this.m_TextComponent.transform.forward, this.m_TextComponent.transform.position); float distance; plane.Raycast(ray, out distance); vector = this.m_TextComponent.transform.InverseTransformPoint(ray.GetPoint(distance)); } return new Vector2(vector.x, vector.y); } private int GetUnclampedCharacterLineFromPosition(Vector2 pos, TextGenerator generator) { if (!this.multiLine) { return 0; } float num = pos.y * this.m_TextComponent.pixelsPerUnit; float num2 = 0f; int i = 0; while (i < generator.lineCount) { float topY = generator.lines[i].topY; float num3 = topY - (float)generator.lines[i].height; if (num > topY) { float num4 = topY - num2; if (num > topY - 0.5f * num4) { return i - 1; } return i; } else { if (num > num3) { return i; } num2 = num3; i++; } } return generator.lineCount; } protected int GetCharacterIndexFromPosition(Vector2 pos) { TextGenerator cachedTextGenerator = this.m_TextComponent.cachedTextGenerator; if (cachedTextGenerator.lineCount == 0) { return 0; } int unclampedCharacterLineFromPosition = this.GetUnclampedCharacterLineFromPosition(pos, cachedTextGenerator); if (unclampedCharacterLineFromPosition < 0) { return 0; } if (unclampedCharacterLineFromPosition >= cachedTextGenerator.lineCount) { return cachedTextGenerator.characterCountVisible; } int startCharIdx = cachedTextGenerator.lines[unclampedCharacterLineFromPosition].startCharIdx; int lineEndPosition = uGUIInputField.GetLineEndPosition(cachedTextGenerator, unclampedCharacterLineFromPosition); for (int i = startCharIdx; i < lineEndPosition; i++) { if (i >= cachedTextGenerator.characterCountVisible) { break; } UICharInfo uicharInfo = cachedTextGenerator.characters[i]; Vector2 vector = uicharInfo.cursorPos / this.m_TextComponent.pixelsPerUnit; float num = pos.x - vector.x; float num2 = vector.x + uicharInfo.charWidth / this.m_TextComponent.pixelsPerUnit - pos.x; if (num < num2) { return i; } } return lineEndPosition; } private bool MayDrag(PointerEventData eventData) { return this.IsActive() && this.IsInteractable() && eventData.button == PointerEventData.InputButton.Left && this.m_TextComponent != null && this.m_Keyboard == null; } public virtual void OnBeginDrag(PointerEventData eventData) { if (!this.MayDrag(eventData)) { return; } this.m_UpdateDrag = true; } public virtual void OnDrag(PointerEventData eventData) { if (!this.MayDrag(eventData)) { return; } Vector2 pos; RectTransformUtility.ScreenPointToLocalPointInRectangle(this.textComponent.rectTransform, eventData.position, eventData.pressEventCamera, out pos); this.caretSelectPositionInternal = this.GetCharacterIndexFromPosition(pos) + this.m_DrawStart; this.MarkGeometryAsDirty(); this.m_DragPositionOutOfBounds = !RectTransformUtility.RectangleContainsScreenPoint(this.textComponent.rectTransform, eventData.position, eventData.pressEventCamera); if (this.m_DragPositionOutOfBounds && this.m_DragCoroutine == null) { this.m_DragCoroutine = base.StartCoroutine(this.MouseDragOutsideRect(eventData)); } eventData.Use(); } private IEnumerator MouseDragOutsideRect(PointerEventData eventData) { while (this.m_UpdateDrag && this.m_DragPositionOutOfBounds) { Vector2 localMousePos; RectTransformUtility.ScreenPointToLocalPointInRectangle(this.textComponent.rectTransform, eventData.position, eventData.pressEventCamera, out localMousePos); Rect rect = this.textComponent.rectTransform.rect; if (this.multiLine) { if (localMousePos.y > rect.yMax) { this.MoveUp(true, true); } else if (localMousePos.y < rect.yMin) { this.MoveDown(true, true); } } else if (localMousePos.x < rect.xMin) { this.MoveLeft(true, false); } else if (localMousePos.x > rect.xMax) { this.MoveRight(true, false); } this.UpdateLabel(); float delay = (!this.multiLine) ? 0.05f : 0.1f; yield return new WaitForSecondsRealtime(delay); } this.m_DragCoroutine = null; yield break; } public virtual void OnEndDrag(PointerEventData eventData) { if (!this.MayDrag(eventData)) { return; } this.m_UpdateDrag = false; } public override void OnPointerDown(PointerEventData eventData) { if (!this.MayDrag(eventData)) { return; } EventSystem.current.SetSelectedGameObject(base.gameObject, eventData); bool allowInput = this.m_AllowInput; base.OnPointerDown(eventData); if (!this.InPlaceEditing() && (this.m_Keyboard == null || !this.m_Keyboard.active)) { this.OnSelect(eventData); return; } if (allowInput) { Vector2 pos; RectTransformUtility.ScreenPointToLocalPointInRectangle(this.textComponent.rectTransform, eventData.position, eventData.pressEventCamera, out pos); int num = this.GetCharacterIndexFromPosition(pos) + this.m_DrawStart; this.caretPositionInternal = num; this.caretSelectPositionInternal = num; } this.UpdateLabel(); eventData.Use(); } protected uGUIInputField.EditState KeyPressed(Event evt) { EventModifiers modifiers = evt.modifiers; bool flag = (SystemInfo.operatingSystemFamily != OperatingSystemFamily.MacOSX) ? ((modifiers & EventModifiers.Control) != EventModifiers.None) : ((modifiers & EventModifiers.Command) != EventModifiers.None); bool flag2 = (modifiers & EventModifiers.Shift) != EventModifiers.None; bool flag3 = (modifiers & EventModifiers.Alt) != EventModifiers.None; bool flag4 = flag && !flag3 && !flag2; KeyCode keyCode = evt.keyCode; switch (keyCode) { case KeyCode.KeypadEnter: break; default: switch (keyCode) { case KeyCode.A: if (flag4) { this.SelectAll(); return uGUIInputField.EditState.Continue; } goto IL_1E5; default: switch (keyCode) { case KeyCode.V: if (flag4) { this.Append(uGUIInputField.clipboard); return uGUIInputField.EditState.Continue; } goto IL_1E5; default: if (keyCode == KeyCode.Backspace) { this.Backspace(); return uGUIInputField.EditState.Continue; } if (keyCode != KeyCode.Return) { if (keyCode == KeyCode.Escape) { this.m_WasCanceled = true; return uGUIInputField.EditState.Finish; } if (keyCode != KeyCode.Delete) { goto IL_1E5; } this.ForwardSpace(); return uGUIInputField.EditState.Continue; } break; case KeyCode.X: if (flag4) { if (this.inputType != uGUIInputField.InputType.Password) { uGUIInputField.clipboard = this.GetSelectedString(); } else { uGUIInputField.clipboard = string.Empty; } this.Delete(); this.SendOnValueChangedAndUpdateLabel(); return uGUIInputField.EditState.Continue; } goto IL_1E5; } break; case KeyCode.C: if (flag4) { if (this.inputType != uGUIInputField.InputType.Password) { uGUIInputField.clipboard = this.GetSelectedString(); } else { uGUIInputField.clipboard = string.Empty; } return uGUIInputField.EditState.Continue; } goto IL_1E5; } break; case KeyCode.UpArrow: this.MoveUp(flag2); return uGUIInputField.EditState.Continue; case KeyCode.DownArrow: this.MoveDown(flag2); return uGUIInputField.EditState.Continue; case KeyCode.RightArrow: this.MoveRight(flag2, flag); return uGUIInputField.EditState.Continue; case KeyCode.LeftArrow: this.MoveLeft(flag2, flag); return uGUIInputField.EditState.Continue; case KeyCode.Home: this.MoveTextStart(flag2); return uGUIInputField.EditState.Continue; case KeyCode.End: this.MoveTextEnd(flag2); return uGUIInputField.EditState.Continue; } if (this.lineType != uGUIInputField.LineType.MultiLineNewline) { return uGUIInputField.EditState.Finish; } IL_1E5: char c = evt.character; if (!this.multiLine && (c == '\t' || c == '\r' || c == '\n')) { return uGUIInputField.EditState.Continue; } if (c == '\r' || c == '\u0003') { c = '\n'; } if (this.IsValidChar(c)) { this.Append(c); } if (c == '\0' && this.compositionString.Length > 0) { this.UpdateLabel(); } return uGUIInputField.EditState.Continue; } private bool IsValidChar(char c) { return c != '\u007f' && (c == '\t' || c == '\n' || this.m_TextComponent.font.HasCharacter(c)); } public void ProcessEvent(Event e) { this.KeyPressed(e); } public virtual void OnUpdateSelected(BaseEventData eventData) { if (!this.isFocused) { return; } bool flag = false; while (Event.PopEvent(this.m_ProcessingEvent)) { if (this.m_ProcessingEvent.rawType == EventType.KeyDown) { flag = true; uGUIInputField.EditState editState = this.KeyPressed(this.m_ProcessingEvent); if (editState == uGUIInputField.EditState.Finish) { this.DeactivateuGUIInputField(); break; } } EventType type = this.m_ProcessingEvent.type; if (type == EventType.ValidateCommand || type == EventType.ExecuteCommand) { string commandName = this.m_ProcessingEvent.commandName; if (commandName != null) { if (commandName == "SelectAll") { this.SelectAll(); flag = true; } } } } if (flag) { this.UpdateLabel(); } eventData.Use(); } private string GetSelectedString() { if (!this.hasSelection) { return string.Empty; } int num = this.caretPositionInternal; int num2 = this.caretSelectPositionInternal; if (num > num2) { int num3 = num; num = num2; num2 = num3; } return this.text.Substring(num, num2 - num); } private int FindtNextWordBegin() { if (this.caretSelectPositionInternal + 1 >= this.text.Length) { return this.text.Length; } int num = this.text.IndexOfAny(uGUIInputField.kSeparators, this.caretSelectPositionInternal + 1); if (num == -1) { num = this.text.Length; } else { num++; } return num; } private void MoveRight(bool shift, bool ctrl) { if (this.hasSelection && !shift) { int num = Mathf.Max(this.caretPositionInternal, this.caretSelectPositionInternal); this.caretSelectPositionInternal = num; this.caretPositionInternal = num; return; } int num2; if (ctrl) { num2 = this.FindtNextWordBegin(); } else { num2 = this.caretSelectPositionInternal + 1; } if (shift) { this.caretSelectPositionInternal = num2; } else { int num = num2; this.caretPositionInternal = num; this.caretSelectPositionInternal = num; } } private int FindtPrevWordBegin() { if (this.caretSelectPositionInternal - 2 < 0) { return 0; } int num = this.text.LastIndexOfAny(uGUIInputField.kSeparators, this.caretSelectPositionInternal - 2); if (num == -1) { num = 0; } else { num++; } return num; } private void MoveLeft(bool shift, bool ctrl) { if (this.hasSelection && !shift) { int num = Mathf.Min(this.caretPositionInternal, this.caretSelectPositionInternal); this.caretSelectPositionInternal = num; this.caretPositionInternal = num; return; } int num2; if (ctrl) { num2 = this.FindtPrevWordBegin(); } else { num2 = this.caretSelectPositionInternal - 1; } if (shift) { this.caretSelectPositionInternal = num2; } else { int num = num2; this.caretPositionInternal = num; this.caretSelectPositionInternal = num; } } private int DetermineCharacterLine(int charPos, TextGenerator generator) { for (int i = 0; i < generator.lineCount - 1; i++) { if (generator.lines[i + 1].startCharIdx > charPos) { return i; } } return generator.lineCount - 1; } private int LineUpCharacterPosition(int originalPos, bool goToFirstChar) { if (originalPos >= this.cachedInputTextGenerator.characters.Count) { return 0; } UICharInfo uicharInfo = this.cachedInputTextGenerator.characters[originalPos]; int num = this.DetermineCharacterLine(originalPos, this.cachedInputTextGenerator); if (num <= 0) { return (!goToFirstChar) ? originalPos : 0; } int num2 = this.cachedInputTextGenerator.lines[num].startCharIdx - 1; for (int i = this.cachedInputTextGenerator.lines[num - 1].startCharIdx; i < num2; i++) { if (this.cachedInputTextGenerator.characters[i].cursorPos.x >= uicharInfo.cursorPos.x) { return i; } } return num2; } private int LineDownCharacterPosition(int originalPos, bool goToLastChar) { if (originalPos >= this.cachedInputTextGenerator.characterCountVisible) { return this.text.Length; } UICharInfo uicharInfo = this.cachedInputTextGenerator.characters[originalPos]; int num = this.DetermineCharacterLine(originalPos, this.cachedInputTextGenerator); if (num + 1 >= this.cachedInputTextGenerator.lineCount) { return (!goToLastChar) ? originalPos : this.text.Length; } int lineEndPosition = uGUIInputField.GetLineEndPosition(this.cachedInputTextGenerator, num + 1); for (int i = this.cachedInputTextGenerator.lines[num + 1].startCharIdx; i < lineEndPosition; i++) { if (this.cachedInputTextGenerator.characters[i].cursorPos.x >= uicharInfo.cursorPos.x) { return i; } } return lineEndPosition; } private void MoveDown(bool shift) { this.MoveDown(shift, true); } private void MoveDown(bool shift, bool goToLastChar) { if (this.hasSelection && !shift) { int num = Mathf.Max(this.caretPositionInternal, this.caretSelectPositionInternal); this.caretSelectPositionInternal = num; this.caretPositionInternal = num; } int num2 = (!this.multiLine) ? this.text.Length : this.LineDownCharacterPosition(this.caretSelectPositionInternal, goToLastChar); if (shift) { this.caretSelectPositionInternal = num2; } else { int num = num2; this.caretSelectPositionInternal = num; this.caretPositionInternal = num; } } private void MoveUp(bool shift) { this.MoveUp(shift, true); } private void MoveUp(bool shift, bool goToFirstChar) { if (this.hasSelection && !shift) { int num = Mathf.Min(this.caretPositionInternal, this.caretSelectPositionInternal); this.caretSelectPositionInternal = num; this.caretPositionInternal = num; } int num2 = (!this.multiLine) ? 0 : this.LineUpCharacterPosition(this.caretSelectPositionInternal, goToFirstChar); if (shift) { this.caretSelectPositionInternal = num2; } else { int num = num2; this.caretPositionInternal = num; this.caretSelectPositionInternal = num; } } private void Delete() { if (this.m_ReadOnly) { return; } if (this.caretPositionInternal == this.caretSelectPositionInternal) { return; } if (this.caretPositionInternal < this.caretSelectPositionInternal) { this.m_Text = this.text.Substring(0, this.caretPositionInternal) + this.text.Substring(this.caretSelectPositionInternal, this.text.Length - this.caretSelectPositionInternal); this.caretSelectPositionInternal = this.caretPositionInternal; } else { this.m_Text = this.text.Substring(0, this.caretSelectPositionInternal) + this.text.Substring(this.caretPositionInternal, this.text.Length - this.caretPositionInternal); this.caretPositionInternal = this.caretSelectPositionInternal; } } private void ForwardSpace() { if (this.m_ReadOnly) { return; } if (this.hasSelection) { this.Delete(); this.SendOnValueChangedAndUpdateLabel(); } else if (this.caretPositionInternal < this.text.Length) { this.m_Text = this.text.Remove(this.caretPositionInternal, 1); this.SendOnValueChangedAndUpdateLabel(); } } private void Backspace() { if (this.m_ReadOnly) { return; } if (this.hasSelection) { this.Delete(); this.SendOnValueChangedAndUpdateLabel(); } else if (this.caretPositionInternal > 0) { this.m_Text = this.text.Remove(this.caretPositionInternal - 1, 1); int num = this.caretPositionInternal - 1; this.caretPositionInternal = num; this.caretSelectPositionInternal = num; this.SendOnValueChangedAndUpdateLabel(); } } private void Insert(char c) { if (this.m_ReadOnly) { return; } string text = c.ToString(); this.Delete(); if (this.characterLimit > 0 && this.text.Length >= this.characterLimit) { return; } this.m_Text = this.text.Insert(this.m_CaretPosition, text); this.caretSelectPositionInternal = (this.caretPositionInternal += text.Length); this.SendOnValueChanged(); } private void SendOnValueChangedAndUpdateLabel() { this.SendOnValueChanged(); this.UpdateLabel(); } private void SendOnValueChanged() { if (this.onValueChanged != null) { this.onValueChanged.Invoke(this.text); } } protected void SendOnSubmit() { if (this.onEndEdit != null) { this.onEndEdit.Invoke(this.m_Text); } } protected virtual void Append(string input) { if (this.m_ReadOnly) { return; } if (!this.InPlaceEditing()) { return; } int i = 0; int length = input.Length; while (i < length) { char c = input[i]; if (c >= ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\n') { this.Append(c); } i++; } } protected virtual void Append(char input) { if (this.m_ReadOnly) { return; } if (!this.InPlaceEditing()) { return; } int num = Math.Min(this.selectionFocusPosition, this.selectionAnchorPosition); if (this.onValidateInput != null) { input = this.onValidateInput(this.text, num, input); } else if (this.characterValidation != uGUIInputField.CharacterValidation.None) { input = this.Validate(this.text, num, input); } if (input == '\0') { return; } this.Insert(input); } protected void UpdateLabel() { if (this.m_TextComponent != null && this.m_TextComponent.font != null && !this.m_PreventFontCallback) { this.m_PreventFontCallback = true; string text; if (this.compositionString.Length > 0) { text = this.text.Substring(0, this.m_CaretPosition) + this.compositionString + this.text.Substring(this.m_CaretPosition); } else { text = this.text; } string text2; if (this.inputType == uGUIInputField.InputType.Password) { text2 = new string(this.asteriskChar, text.Length); } else { text2 = text; } bool flag = string.IsNullOrEmpty(text); if (this.m_Placeholder != null) { this.m_Placeholder.enabled = flag; } if (!this.m_AllowInput) { this.m_DrawStart = 0; this.m_DrawEnd = this.m_Text.Length; } if (!flag) { Vector2 size = this.m_TextComponent.rectTransform.rect.size; TextGenerationSettings generationSettings = this.m_TextComponent.GetGenerationSettings(size); generationSettings.generateOutOfBounds = true; this.cachedInputTextGenerator.PopulateWithErrors(text2, generationSettings, base.gameObject); this.SetDrawRangeToContainCaretPosition(this.caretSelectPositionInternal); text2 = text2.Substring(this.m_DrawStart, Mathf.Min(this.m_DrawEnd, text2.Length) - this.m_DrawStart); this.SetCaretVisible(); } this.m_TextComponent.text = text2; this.MarkGeometryAsDirty(); this.m_PreventFontCallback = false; } } private bool IsSelectionVisible() { return this.m_DrawStart <= this.caretPositionInternal && this.m_DrawStart <= this.caretSelectPositionInternal && this.m_DrawEnd >= this.caretPositionInternal && this.m_DrawEnd >= this.caretSelectPositionInternal; } private static int GetLineStartPosition(TextGenerator gen, int line) { line = Mathf.Clamp(line, 0, gen.lines.Count - 1); return gen.lines[line].startCharIdx; } private static int GetLineEndPosition(TextGenerator gen, int line) { line = Mathf.Max(line, 0); if (line + 1 < gen.lines.Count) { return gen.lines[line + 1].startCharIdx - 1; } return gen.characterCountVisible; } private void SetDrawRangeToContainCaretPosition(int caretPos) { if (this.cachedInputTextGenerator.lineCount <= 0) { return; } Vector2 size = this.cachedInputTextGenerator.rectExtents.size; if (this.multiLine) { IList lines = this.cachedInputTextGenerator.lines; int num = this.DetermineCharacterLine(caretPos, this.cachedInputTextGenerator); if (caretPos > this.m_DrawEnd) { this.m_DrawEnd = uGUIInputField.GetLineEndPosition(this.cachedInputTextGenerator, num); float num2 = lines[num].topY - (float)lines[num].height; if (num == lines.Count - 1) { num2 += lines[num].leading; } int i; for (i = num; i > 0; i--) { float topY = lines[i - 1].topY; if (topY - num2 > size.y) { break; } } this.m_DrawStart = uGUIInputField.GetLineStartPosition(this.cachedInputTextGenerator, i); } else { if (caretPos < this.m_DrawStart) { this.m_DrawStart = uGUIInputField.GetLineStartPosition(this.cachedInputTextGenerator, num); } int j = this.DetermineCharacterLine(this.m_DrawStart, this.cachedInputTextGenerator); int k = j; float topY2 = lines[j].topY; float num3 = lines[k].topY - (float)lines[k].height; if (k == lines.Count - 1) { num3 += lines[k].leading; } while (k < lines.Count - 1) { num3 = lines[k + 1].topY - (float)lines[k + 1].height; if (k + 1 == lines.Count - 1) { num3 += lines[k + 1].leading; } if (topY2 - num3 > size.y) { break; } k++; } this.m_DrawEnd = uGUIInputField.GetLineEndPosition(this.cachedInputTextGenerator, k); while (j > 0) { topY2 = lines[j - 1].topY; if (topY2 - num3 > size.y) { break; } j--; } this.m_DrawStart = uGUIInputField.GetLineStartPosition(this.cachedInputTextGenerator, j); } } else { IList characters = this.cachedInputTextGenerator.characters; if (this.m_DrawEnd > this.cachedInputTextGenerator.characterCountVisible) { this.m_DrawEnd = this.cachedInputTextGenerator.characterCountVisible; } float num4 = 0f; if (caretPos > this.m_DrawEnd || (caretPos == this.m_DrawEnd && this.m_DrawStart > 0)) { this.m_DrawEnd = caretPos; this.m_DrawStart = this.m_DrawEnd - 1; while (this.m_DrawStart >= 0) { if (num4 + characters[this.m_DrawStart].charWidth > size.x) { break; } num4 += characters[this.m_DrawStart].charWidth; this.m_DrawStart--; } this.m_DrawStart++; } else { if (caretPos < this.m_DrawStart) { this.m_DrawStart = caretPos; } this.m_DrawEnd = this.m_DrawStart; } while (this.m_DrawEnd < this.cachedInputTextGenerator.characterCountVisible) { num4 += characters[this.m_DrawEnd].charWidth; if (num4 > size.x) { break; } this.m_DrawEnd++; } } } public void ForceLabelUpdate() { this.UpdateLabel(); } private void MarkGeometryAsDirty() { CanvasUpdateRegistry.RegisterCanvasElementForGraphicRebuild(this); } public virtual void Rebuild(CanvasUpdate update) { if (update == CanvasUpdate.LatePreRender) { this.UpdateGeometry(); } } public virtual void LayoutComplete() { } public virtual void GraphicUpdateComplete() { } private void UpdateGeometry() { if (!this.shouldHideMobileInput) { return; } if (this.m_CachedInputRenderer == null && this.m_TextComponent != null) { GameObject gameObject = new GameObject(base.transform.name + " Input Caret", new Type[] { typeof(RectTransform), typeof(CanvasRenderer) }); gameObject.hideFlags = HideFlags.DontSave; gameObject.transform.SetParent(this.m_TextComponent.transform.parent); gameObject.transform.SetAsFirstSibling(); gameObject.layer = base.gameObject.layer; this.caretRectTrans = gameObject.GetComponent(); this.m_CachedInputRenderer = gameObject.GetComponent(); this.m_CachedInputRenderer.SetMaterial(this.m_TextComponent.GetModifiedMaterial(Graphic.defaultGraphicMaterial), Texture2D.whiteTexture); gameObject.AddComponent().ignoreLayout = true; this.AssignPositioningIfNeeded(); } if (this.m_CachedInputRenderer == null) { return; } this.OnFillVBO(this.mesh); this.m_CachedInputRenderer.SetMesh(this.mesh); } private void AssignPositioningIfNeeded() { if (this.m_TextComponent != null && this.caretRectTrans != null && (this.caretRectTrans.localPosition != this.m_TextComponent.rectTransform.localPosition || this.caretRectTrans.localRotation != this.m_TextComponent.rectTransform.localRotation || this.caretRectTrans.localScale != this.m_TextComponent.rectTransform.localScale || this.caretRectTrans.anchorMin != this.m_TextComponent.rectTransform.anchorMin || this.caretRectTrans.anchorMax != this.m_TextComponent.rectTransform.anchorMax || this.caretRectTrans.anchoredPosition != this.m_TextComponent.rectTransform.anchoredPosition || this.caretRectTrans.sizeDelta != this.m_TextComponent.rectTransform.sizeDelta || this.caretRectTrans.pivot != this.m_TextComponent.rectTransform.pivot)) { this.caretRectTrans.localPosition = this.m_TextComponent.rectTransform.localPosition; this.caretRectTrans.localRotation = this.m_TextComponent.rectTransform.localRotation; this.caretRectTrans.localScale = this.m_TextComponent.rectTransform.localScale; this.caretRectTrans.anchorMin = this.m_TextComponent.rectTransform.anchorMin; this.caretRectTrans.anchorMax = this.m_TextComponent.rectTransform.anchorMax; this.caretRectTrans.anchoredPosition = this.m_TextComponent.rectTransform.anchoredPosition; this.caretRectTrans.sizeDelta = this.m_TextComponent.rectTransform.sizeDelta; this.caretRectTrans.pivot = this.m_TextComponent.rectTransform.pivot; } } private void OnFillVBO(Mesh vbo) { using (VertexHelper vertexHelper = new VertexHelper()) { if (!this.isFocused) { vertexHelper.FillMesh(vbo); } else { Vector2 roundingOffset = this.m_TextComponent.PixelAdjustPoint(Vector2.zero); if (!this.hasSelection) { this.GenerateCaret(vertexHelper, roundingOffset); } else { this.GenerateHightlight(vertexHelper, roundingOffset); } vertexHelper.FillMesh(vbo); } } } private void GenerateCaret(VertexHelper vbo, Vector2 roundingOffset) { if (!this.m_CaretVisible) { return; } if (this.m_CursorVerts == null) { this.CreateCursorVerts(); } float num = (float)this.m_CaretWidth; int num2 = Mathf.Max(0, this.caretPositionInternal - this.m_DrawStart); TextGenerator cachedTextGenerator = this.m_TextComponent.cachedTextGenerator; if (cachedTextGenerator == null) { return; } if (cachedTextGenerator.lineCount == 0) { return; } Vector2 vector = Vector2.zero; if (num2 < cachedTextGenerator.characters.Count) { vector.x = cachedTextGenerator.characters[num2].cursorPos.x; } vector.x /= this.m_TextComponent.pixelsPerUnit; if (vector.x > this.m_TextComponent.rectTransform.rect.xMax) { vector.x = this.m_TextComponent.rectTransform.rect.xMax; } int index = this.DetermineCharacterLine(num2, cachedTextGenerator); vector.y = cachedTextGenerator.lines[index].topY / this.m_TextComponent.pixelsPerUnit; float num3 = (float)cachedTextGenerator.lines[index].height / this.m_TextComponent.pixelsPerUnit; for (int i = 0; i < this.m_CursorVerts.Length; i++) { this.m_CursorVerts[i].color = this.caretColor; } vector += this.m_FixCaretPos; this.m_CursorVerts[0].position = new Vector3(vector.x, vector.y - num3, 0f); this.m_CursorVerts[1].position = new Vector3(vector.x + num, vector.y - num3, 0f); this.m_CursorVerts[2].position = new Vector3(vector.x + num, vector.y, 0f); this.m_CursorVerts[3].position = new Vector3(vector.x, vector.y, 0f); if (roundingOffset != Vector2.zero) { for (int j = 0; j < this.m_CursorVerts.Length; j++) { UIVertex uivertex = this.m_CursorVerts[j]; uivertex.position.x = uivertex.position.x + roundingOffset.x; uivertex.position.y = uivertex.position.y + roundingOffset.y; } } vbo.AddUIVertexQuad(this.m_CursorVerts); int num4 = Screen.height; int targetDisplay = this.m_TextComponent.canvas.targetDisplay; if (targetDisplay > 0 && targetDisplay < Display.displays.Length) { num4 = Display.displays[targetDisplay].renderingHeight; } vector.y = (float)num4 - vector.y; this.input.compositionCursorPos = vector; } private void CreateCursorVerts() { this.m_CursorVerts = new UIVertex[4]; for (int i = 0; i < this.m_CursorVerts.Length; i++) { this.m_CursorVerts[i] = UIVertex.simpleVert; this.m_CursorVerts[i].uv0 = Vector2.zero; } } private void GenerateHightlight(VertexHelper vbo, Vector2 roundingOffset) { int num = Mathf.Max(0, this.caretPositionInternal - this.m_DrawStart); int num2 = Mathf.Max(0, this.caretSelectPositionInternal - this.m_DrawStart); if (num > num2) { int num3 = num; num = num2; num2 = num3; } num2--; TextGenerator cachedTextGenerator = this.m_TextComponent.cachedTextGenerator; if (cachedTextGenerator.lineCount <= 0) { return; } int num4 = this.DetermineCharacterLine(num, cachedTextGenerator); int lineEndPosition = uGUIInputField.GetLineEndPosition(cachedTextGenerator, num4); UIVertex simpleVert = UIVertex.simpleVert; simpleVert.uv0 = Vector2.zero; simpleVert.color = this.selectionColor; int num5 = num; while (num5 <= num2 && num5 < cachedTextGenerator.characterCount) { if (num5 == lineEndPosition || num5 == num2) { UICharInfo uicharInfo = cachedTextGenerator.characters[num]; UICharInfo uicharInfo2 = cachedTextGenerator.characters[num5]; Vector2 a = new Vector2(uicharInfo.cursorPos.x / this.m_TextComponent.pixelsPerUnit, cachedTextGenerator.lines[num4].topY / this.m_TextComponent.pixelsPerUnit); Vector2 a2 = new Vector2((uicharInfo2.cursorPos.x + uicharInfo2.charWidth) / this.m_TextComponent.pixelsPerUnit, a.y - (float)cachedTextGenerator.lines[num4].height / this.m_TextComponent.pixelsPerUnit); if (a2.x > this.m_TextComponent.rectTransform.rect.xMax || a2.x < this.m_TextComponent.rectTransform.rect.xMin) { a2.x = this.m_TextComponent.rectTransform.rect.xMax; } a += this.m_FixCaretPos; a2 += this.m_FixCaretPos; int currentVertCount = vbo.currentVertCount; simpleVert.position = new Vector3(a.x, a2.y, 0f) + roundingOffset; vbo.AddVert(simpleVert); simpleVert.position = new Vector3(a2.x, a2.y, 0f) + roundingOffset; vbo.AddVert(simpleVert); simpleVert.position = new Vector3(a2.x, a.y, 0f) + roundingOffset; vbo.AddVert(simpleVert); simpleVert.position = new Vector3(a.x, a.y, 0f) + roundingOffset; vbo.AddVert(simpleVert); vbo.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2); vbo.AddTriangle(currentVertCount + 2, currentVertCount + 3, currentVertCount); num = num5 + 1; num4++; lineEndPosition = uGUIInputField.GetLineEndPosition(cachedTextGenerator, num4); } num5++; } } protected char Validate(string text, int pos, char ch) { if (this.characterValidation == uGUIInputField.CharacterValidation.None || !base.enabled) { return ch; } if (this.characterValidation == uGUIInputField.CharacterValidation.Integer || this.characterValidation == uGUIInputField.CharacterValidation.Decimal) { bool flag = pos == 0 && text.Length > 0 && text[0] == '-'; bool flag2 = this.caretPositionInternal == 0 || this.caretSelectPositionInternal == 0; if (!flag) { if (ch >= '0' && ch <= '9') { return ch; } if (ch == '-' && (pos == 0 || flag2)) { return ch; } if (ch == '.' && this.characterValidation == uGUIInputField.CharacterValidation.Decimal && !text.Contains(".")) { return ch; } } } else if (this.characterValidation == uGUIInputField.CharacterValidation.Alphanumeric) { if (ch >= 'A' && ch <= 'Z') { return ch; } if (ch >= 'a' && ch <= 'z') { return ch; } if (ch >= '0' && ch <= '9') { return ch; } } else if (this.characterValidation == uGUIInputField.CharacterValidation.Name) { if (char.IsLetter(ch)) { if (char.IsLower(ch) && (pos == 0 || text[pos - 1] == ' ')) { return char.ToUpper(ch); } if (char.IsUpper(ch) && pos > 0 && text[pos - 1] != ' ' && text[pos - 1] != '\'') { return char.ToLower(ch); } return ch; } else { if (ch == '\'' && !text.Contains("'") && (pos <= 0 || (text[pos - 1] != ' ' && text[pos - 1] != '\'')) && (pos >= text.Length || (text[pos] != ' ' && text[pos] != '\''))) { return ch; } if (ch == ' ' && (pos <= 0 || (text[pos - 1] != ' ' && text[pos - 1] != '\'')) && (pos >= text.Length || (text[pos] != ' ' && text[pos] != '\''))) { return ch; } } } else if (this.characterValidation == uGUIInputField.CharacterValidation.EmailAddress) { if (ch >= 'A' && ch <= 'Z') { return ch; } if (ch >= 'a' && ch <= 'z') { return ch; } if (ch >= '0' && ch <= '9') { return ch; } if (ch == '@' && text.IndexOf('@') == -1) { return ch; } if ("!#$%&'*+-/=?^_`{|}~".IndexOf(ch) != -1) { return ch; } if (ch == '.') { char c = (text.Length <= 0) ? ' ' : text[Mathf.Clamp(pos, 0, text.Length - 1)]; char c2 = (text.Length <= 0) ? '\n' : text[Mathf.Clamp(pos + 1, 0, text.Length - 1)]; if (c != '.' && c2 != '.') { return ch; } } } return '\0'; } public void ActivateuGUIInputField() { if (this.m_TextComponent == null || this.m_TextComponent.font == null || !this.IsActive() || !this.IsInteractable()) { return; } if (this.isFocused && this.m_Keyboard != null && !this.m_Keyboard.active) { this.m_Keyboard.active = true; this.m_Keyboard.text = this.m_Text; } this.m_ShouldActivateNextUpdate = true; } private void ActivateuGUIInputFieldInternal() { if (EventSystem.current == null) { return; } if (EventSystem.current.currentSelectedGameObject != base.gameObject) { EventSystem.current.SetSelectedGameObject(base.gameObject); } if (TouchScreenKeyboard.isSupported) { if (this.input.touchSupported) { TouchScreenKeyboard.hideInput = this.shouldHideMobileInput; } this.m_Keyboard = ((this.inputType != uGUIInputField.InputType.Password) ? TouchScreenKeyboard.Open(this.m_Text, this.keyboardType, this.inputType == uGUIInputField.InputType.AutoCorrect, this.multiLine) : TouchScreenKeyboard.Open(this.m_Text, this.keyboardType, false, this.multiLine, true)); this.MoveTextEnd(false); } else { this.input.imeCompositionMode = IMECompositionMode.On; this.OnFocus(); } this.m_AllowInput = true; this.m_OriginalText = this.text; this.m_WasCanceled = false; this.SetCaretVisible(); this.UpdateLabel(); } public override void OnSelect(BaseEventData eventData) { base.OnSelect(eventData); if (this.shouldActivateOnSelect) { this.ActivateuGUIInputField(); } } public virtual void OnPointerClick(PointerEventData eventData) { if (eventData.button != PointerEventData.InputButton.Left) { return; } this.ActivateuGUIInputField(); } public void DeactivateuGUIInputField() { if (!this.m_AllowInput) { return; } this.m_HasDoneFocusTransition = false; this.m_AllowInput = false; if (this.m_Placeholder != null) { this.m_Placeholder.enabled = string.IsNullOrEmpty(this.m_Text); } if (this.m_TextComponent != null && this.IsInteractable()) { if (this.m_WasCanceled) { this.text = this.m_OriginalText; } if (this.m_Keyboard != null) { this.m_Keyboard.active = false; this.m_Keyboard = null; } this.m_CaretPosition = (this.m_CaretSelectPosition = 0); this.SendOnSubmit(); this.input.imeCompositionMode = IMECompositionMode.Auto; } this.MarkGeometryAsDirty(); } public override void OnDeselect(BaseEventData eventData) { this.DeactivateuGUIInputField(); base.OnDeselect(eventData); } public virtual void OnSubmit(BaseEventData eventData) { if (!this.IsActive() || !this.IsInteractable()) { return; } if (!this.isFocused) { this.m_ShouldActivateNextUpdate = true; } } private void EnforceContentType() { switch (this.contentType) { case uGUIInputField.ContentType.Standard: this.m_InputType = uGUIInputField.InputType.Standard; this.m_KeyboardType = TouchScreenKeyboardType.Default; this.m_CharacterValidation = uGUIInputField.CharacterValidation.None; break; case uGUIInputField.ContentType.Autocorrected: this.m_InputType = uGUIInputField.InputType.AutoCorrect; this.m_KeyboardType = TouchScreenKeyboardType.Default; this.m_CharacterValidation = uGUIInputField.CharacterValidation.None; break; case uGUIInputField.ContentType.IntegerNumber: this.m_LineType = uGUIInputField.LineType.SingleLine; this.m_InputType = uGUIInputField.InputType.Standard; this.m_KeyboardType = TouchScreenKeyboardType.NumberPad; this.m_CharacterValidation = uGUIInputField.CharacterValidation.Integer; break; case uGUIInputField.ContentType.DecimalNumber: this.m_LineType = uGUIInputField.LineType.SingleLine; this.m_InputType = uGUIInputField.InputType.Standard; this.m_KeyboardType = TouchScreenKeyboardType.NumbersAndPunctuation; this.m_CharacterValidation = uGUIInputField.CharacterValidation.Decimal; break; case uGUIInputField.ContentType.Alphanumeric: this.m_LineType = uGUIInputField.LineType.SingleLine; this.m_InputType = uGUIInputField.InputType.Standard; this.m_KeyboardType = TouchScreenKeyboardType.ASCIICapable; this.m_CharacterValidation = uGUIInputField.CharacterValidation.Alphanumeric; break; case uGUIInputField.ContentType.Name: this.m_LineType = uGUIInputField.LineType.SingleLine; this.m_InputType = uGUIInputField.InputType.Standard; this.m_KeyboardType = TouchScreenKeyboardType.Default; this.m_CharacterValidation = uGUIInputField.CharacterValidation.Name; break; case uGUIInputField.ContentType.EmailAddress: this.m_LineType = uGUIInputField.LineType.SingleLine; this.m_InputType = uGUIInputField.InputType.Standard; this.m_KeyboardType = TouchScreenKeyboardType.EmailAddress; this.m_CharacterValidation = uGUIInputField.CharacterValidation.EmailAddress; break; case uGUIInputField.ContentType.Password: this.m_LineType = uGUIInputField.LineType.SingleLine; this.m_InputType = uGUIInputField.InputType.Password; this.m_KeyboardType = TouchScreenKeyboardType.Default; this.m_CharacterValidation = uGUIInputField.CharacterValidation.None; break; case uGUIInputField.ContentType.Pin: this.m_LineType = uGUIInputField.LineType.SingleLine; this.m_InputType = uGUIInputField.InputType.Password; this.m_KeyboardType = TouchScreenKeyboardType.NumberPad; this.m_CharacterValidation = uGUIInputField.CharacterValidation.Integer; break; } this.EnforceTextHOverflow(); } private void EnforceTextHOverflow() { if (this.m_TextComponent != null) { if (this.multiLine) { this.m_TextComponent.horizontalOverflow = HorizontalWrapMode.Wrap; } else { this.m_TextComponent.horizontalOverflow = HorizontalWrapMode.Overflow; } } } private void SetToCustomIfContentTypeIsNot(params uGUIInputField.ContentType[] allowedContentTypes) { if (this.contentType == uGUIInputField.ContentType.Custom) { return; } for (int i = 0; i < allowedContentTypes.Length; i++) { if (this.contentType == allowedContentTypes[i]) { return; } } this.contentType = uGUIInputField.ContentType.Custom; } private void SetToCustom() { if (this.contentType == uGUIInputField.ContentType.Custom) { return; } this.contentType = uGUIInputField.ContentType.Custom; } protected override void DoStateTransition(Selectable.SelectionState state, bool instant) { if (this.m_HasDoneFocusTransition) { state = Selectable.SelectionState.Highlighted; } else if (state == Selectable.SelectionState.Pressed) { this.m_HasDoneFocusTransition = true; } base.DoStateTransition(state, instant); } public virtual void CalculateLayoutInputHorizontal() { } public virtual void CalculateLayoutInputVertical() { } public virtual float minWidth { get { return 0f; } } public virtual float preferredWidth { get { if (this.textComponent == null) { return 0f; } TextGenerationSettings generationSettings = this.textComponent.GetGenerationSettings(Vector2.zero); return this.textComponent.cachedTextGeneratorForLayout.GetPreferredWidth(this.m_Text, generationSettings) / this.textComponent.pixelsPerUnit; } } public virtual float flexibleWidth { get { return -1f; } } public virtual float minHeight { get { return 0f; } } public virtual float preferredHeight { get { if (this.textComponent == null) { return 0f; } TextGenerationSettings generationSettings = this.textComponent.GetGenerationSettings(new Vector2(this.textComponent.rectTransform.rect.size.x, 0f)); return this.textComponent.cachedTextGeneratorForLayout.GetPreferredHeight(this.m_Text, generationSettings) / this.textComponent.pixelsPerUnit; } } public virtual float flexibleHeight { get { return -1f; } } public virtual int layoutPriority { get { return 1; } } Transform ICanvasElement.get_transform() { return base.transform; } bool ICanvasElement.IsDestroyed() { return base.IsDestroyed(); } protected TouchScreenKeyboard m_Keyboard; private static readonly char[] kSeparators = new char[] { ' ', '.', ',', '\t', '\r', '\n' }; [SerializeField] [FormerlySerializedAs("text")] protected Text m_TextComponent; [SerializeField] protected Graphic m_Placeholder; [SerializeField] private uGUIInputField.ContentType m_ContentType; [FormerlySerializedAs("inputType")] [SerializeField] private uGUIInputField.InputType m_InputType; [FormerlySerializedAs("asteriskChar")] [SerializeField] private char m_AsteriskChar = '*'; [FormerlySerializedAs("keyboardType")] [SerializeField] private TouchScreenKeyboardType m_KeyboardType; [SerializeField] private uGUIInputField.LineType m_LineType; [FormerlySerializedAs("hideMobileInput")] [SerializeField] private bool m_HideMobileInput; [FormerlySerializedAs("validation")] [SerializeField] private uGUIInputField.CharacterValidation m_CharacterValidation; [FormerlySerializedAs("characterLimit")] [SerializeField] private int m_CharacterLimit; [FormerlySerializedAs("onSubmit")] [FormerlySerializedAs("m_OnSubmit")] [FormerlySerializedAs("m_EndEdit")] [SerializeField] private uGUIInputField.SubmitEvent m_OnEndEdit = new uGUIInputField.SubmitEvent(); [FormerlySerializedAs("onValueChange")] [FormerlySerializedAs("m_OnValueChange")] [SerializeField] private uGUIInputField.OnChangeEvent m_OnValueChanged = new uGUIInputField.OnChangeEvent(); [FormerlySerializedAs("onValidateInput")] [SerializeField] private uGUIInputField.OnValidateInput m_OnValidateInput; [SerializeField] private Color m_CaretColor = new Color(0.196078435f, 0.196078435f, 0.196078435f, 1f); [SerializeField] private bool m_CustomCaretColor; [FormerlySerializedAs("selectionColor")] [SerializeField] private Color m_SelectionColor = new Color(0.65882355f, 0.807843149f, 1f, 0.7529412f); [SerializeField] [FormerlySerializedAs("mValue")] protected string m_Text = string.Empty; [SerializeField] [Range(0f, 4f)] private float m_CaretBlinkRate = 0.85f; [SerializeField] private Vector2 m_FixCaretPos = Vector2.zero; [SerializeField] [Range(1f, 5f)] private int m_CaretWidth = 1; [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; private const float kHScrollSpeed = 0.05f; private const float kVScrollSpeed = 0.1f; 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 string m_OriginalText = string.Empty; private bool m_WasCanceled; private bool m_HasDoneFocusTransition; private const string kEmailSpecialCharacters = "!#$%&'*+-/=?^_`{|}~"; private Event m_ProcessingEvent = new Event(); public enum ContentType { Standard, Autocorrected, IntegerNumber, DecimalNumber, Alphanumeric, Name, EmailAddress, Password, Pin, Custom } public enum InputType { Standard, AutoCorrect, Password } public enum CharacterValidation { None, Integer, Decimal, Alphanumeric, Name, EmailAddress } public enum LineType { SingleLine, MultiLineSubmit, MultiLineNewline } public delegate char OnValidateInput(string text, int charIndex, char addedChar); [Serializable] public class SubmitEvent : UnityEvent { } [Serializable] public class OnChangeEvent : UnityEvent { } protected enum EditState { Continue, Finish } } }