//#define TouchScreenKeyboard #define SCKeyboard using SC.XR.Unity.Module_Keyboard; using System; using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace SC.XR.Unity { [AddComponentMenu("UI/UGUI - SC Input Field", 32)] public class UGUI_SCInputField : SCInputField { protected UGUI_SCInputField() { this.EnforceTextHOverflow(); } public override bool shouldHideMobileInput { get { #if SCKeyboard RuntimePlatform platform = Application.platform; return (platform != RuntimePlatform.IPhonePlayer && platform != RuntimePlatform.tvOS) || this.m_HideMobileInput // UGUI_SCInputField is run on android || (platform == RuntimePlatform.Android); #elif TouchScreenKeyboard RuntimePlatform platform = Application.platform; return (platform != RuntimePlatform.IPhonePlayer && platform != RuntimePlatform.Android && platform != RuntimePlatform.tvOS) || this.m_HideMobileInput; #endif } set { SCSetPropertyUtility.SetStruct(ref this.m_HideMobileInput, value); } } #region SCKeyboard private bool shouldDeactivateOnDeselect { get { //TODO return (m_Keyboard == null || m_Keyboard.status > 0) && EventSystem.current.currentSelectedGameObject != this.gameObject; } } #endregion public override string text { get { return this.m_Text; } set { this.SetText(value, true); } } public void SetTextWithoutNotify(string input) { this.SetText(input, false); } private void SetText(string value, bool sendCallback = true) { bool flag = this.text == value; if (!flag) { bool flag2 = value == null; if (flag2) { value = ""; } value = value.Replace("\0", string.Empty); bool flag3 = this.m_LineType == UGUI_SCInputField.LineType.SingleLine; if (flag3) { value = value.Replace("\n", "").Replace("\t", ""); } bool flag4 = this.onValidateInput != null || this.characterValidation > UGUI_SCInputField.CharacterValidation.None; if (flag4) { this.m_Text = ""; UGUI_SCInputField.OnValidateInput validatorMethod = this.onValidateInput ?? new UGUI_SCInputField.OnValidateInput(this.Validate); this.m_CaretPosition = (this.m_CaretSelectPosition = value.Length); int charactersToCheck = (this.characterLimit > 0) ? Math.Min(this.characterLimit, value.Length) : value.Length; for (int i = 0; i < charactersToCheck; i++) { char c = validatorMethod(this.m_Text, this.m_Text.Length, value[i]); bool flag5 = c > '\0'; if (flag5) { this.m_Text += c.ToString(); } } } else { this.m_Text = ((this.characterLimit > 0 && value.Length > this.characterLimit) ? value.Substring(0, this.characterLimit) : value); } bool flag6 = !Application.isPlaying; if (flag6) { this.SendOnValueChangedAndUpdateLabel(); } else { bool flag7 = this.m_Keyboard != null; if (flag7) { this.m_Keyboard.text = this.m_Text; } bool flag8 = this.m_CaretPosition > this.m_Text.Length; if (flag8) { this.m_CaretPosition = (this.m_CaretSelectPosition = this.m_Text.Length); } else { bool flag9 = this.m_CaretSelectPosition > this.m_Text.Length; if (flag9) { this.m_CaretSelectPosition = this.m_Text.Length; } } if (sendCallback) { this.SendOnValueChanged(); } this.UpdateLabel(); } } } public override int characterLimit { get { return this.m_CharacterLimit; } set { bool flag = SCSetPropertyUtility.SetStruct(ref this.m_CharacterLimit, Math.Max(0, value)); if (flag) { this.UpdateLabel(); bool flag2 = this.m_Keyboard != null; if (flag2) { this.m_Keyboard.characterLimit = value; } } } } #if SCKeyboard public SCKeyboard scKeyboard { get { return this.m_Keyboard; } } #elif TouchScreenKeyboard public TouchScreenKeyboard touchScreenKeyboard { get { return this.m_Keyboard; } } #endif #if SCKeyboard public SCKeyboardEnum scKeyboardEnum { get { return this.m_SCKeyboardEnum; } set { bool flag = SCSetPropertyUtility.SetStruct(ref this.m_SCKeyboardEnum, value); if (flag) { this.SetToCustom(); } } } #endif #if SCKeyboard public SCKeyboardType scKeyboardType { get { return this.m_SCKeyboardType; } set { bool flag = SCSetPropertyUtility.SetStruct(ref this.m_SCKeyboardType, value); if (flag) { this.SetToCustom(); } } } #elif TouchScreenKeyboard public override TouchScreenKeyboardType keyboardType { get { return this.m_KeyboardType; } set { bool flag = SCSetPropertyUtility.SetStruct(ref this.m_KeyboardType, value); if (flag) { this.SetToCustom(); } } } #endif #if UNITY_EDITOR protected override void OnValidate() { base.OnValidate(); this.EnforceContentType(); this.EnforceTextHOverflow(); this.m_CharacterLimit = Math.Max(0, this.m_CharacterLimit); bool flag = !this.IsActive(); if (!flag) { this.ClampPos(ref this.m_CaretPosition); this.ClampPos(ref this.m_CaretSelectPosition); this.UpdateLabel(); bool allowInput = this.m_AllowInput; if (allowInput) { this.SetCaretActive(); } } } #endif protected override IEnumerator CaretBlink() { base.CaretBlink(); yield break; } protected override bool InPlaceEditing() { #if SCKeyboard return !SCKeyboard.isSupported || this.m_TouchKeyboardAllowsInPlaceEditing; #elif TouchScreenKeyboard return !TouchScreenKeyboard.isSupported || this.m_TouchKeyboardAllowsInPlaceEditing; #endif } protected override void UpdateCaretFromKeyboard() { RangeInt selectionRange = this.m_Keyboard.selection; int selectionStart = selectionRange.start; int selectionEnd = selectionRange.end; bool caretChanged = false; bool flag = this.caretPositionInternal != selectionStart; if (flag) { caretChanged = true; this.caretPositionInternal = selectionStart; } bool flag2 = this.caretSelectPositionInternal != selectionEnd; if (flag2) { this.caretSelectPositionInternal = selectionEnd; caretChanged = true; } bool flag3 = caretChanged; if (flag3) { this.m_BlinkStartTime = Time.unscaledTime; this.UpdateLabel(); } } protected override void LateUpdate() { bool shouldActivateNextUpdate = this.m_ShouldActivateNextUpdate; if (shouldActivateNextUpdate) { bool flag = !this.isFocused; if (flag) { this.ActivateInputFieldInternal(); this.m_ShouldActivateNextUpdate = false; return; } this.m_ShouldActivateNextUpdate = false; } this.AssignPositioningIfNeeded(); bool flag2 = !this.isFocused || this.InPlaceEditing(); if (!flag2) { #if SCKeyboard bool flag3 = this.m_Keyboard == null || this.m_Keyboard.status > SCKeyboard.Status.Visible; #elif TouchScreenKeyboard bool flag3 = this.m_Keyboard == null || this.m_Keyboard.status > TouchScreenKeyboard.Status.Visible; #endif if (flag3) { bool flag4 = this.m_Keyboard != null; if (flag4) { bool flag5 = !this.m_ReadOnly; if (flag5) { this.text = this.m_Keyboard.text; } #if SCKeyboard bool flag6 = this.m_Keyboard.status == SCKeyboard.Status.Canceled; #elif TouchScreenKeyboard bool flag6 = this.m_Keyboard.status == TouchScreenKeyboard.Status.Canceled; #endif if (flag6) { this.m_WasCanceled = true; } } this.OnDeselect(null); } else { string val = this.m_Keyboard.text; bool flag7 = this.m_Text != val; if (flag7) { bool readOnly = this.m_ReadOnly; if (readOnly) { this.m_Keyboard.text = this.m_Text; } else { this.m_Text = ""; for (int i = 0; i < val.Length; i++) { bool flag8 = val[i] == '\r' || val[i] == '\u0003'; if (flag8) { //TODO val.Remove(i); val.Insert(i, "\n"); } bool flag9 = this.onValidateInput != null; if (flag9) { //TODO char c = val[i]; val.Remove(i); val.Insert(i, this.onValidateInput(this.m_Text, this.m_Text.Length, c).ToString()); } else { bool flag10 = this.characterValidation > UGUI_SCInputField.CharacterValidation.None; if (flag10) { //TODO char c = val[i]; val.Remove(i); val.Insert(i, this.Validate(this.m_Text, this.m_Text.Length, c).ToString()); } } bool flag11 = this.lineType == UGUI_SCInputField.LineType.MultiLineSubmit && val[i] == '\n'; if (flag11) { this.m_Keyboard.text = this.m_Text; this.OnDeselect(null); return; } bool flag12 = val[i] > '\0'; if (flag12) { this.m_Text += val[i].ToString(); } } bool flag13 = this.characterLimit > 0 && this.m_Text.Length > this.characterLimit; if (flag13) { this.m_Text = this.m_Text.Substring(0, this.characterLimit); } bool canGetSelection = this.m_Keyboard.canGetSelection; if (canGetSelection) { this.UpdateCaretFromKeyboard(); } else { this.caretPositionInternal = (this.caretSelectPositionInternal = this.m_Text.Length); } bool flag14 = this.m_Text != val; if (flag14) { this.m_Keyboard.text = this.m_Text; } this.SendOnValueChangedAndUpdateLabel(); } } else { bool flag15 = this.m_HideMobileInput && this.m_Keyboard.canSetSelection; if (flag15) { this.m_Keyboard.selection = new RangeInt(this.caretPositionInternal, this.caretSelectPositionInternal - this.caretPositionInternal); } else { bool flag16 = this.m_Keyboard.canGetSelection && !this.m_HideMobileInput; if (flag16) { this.UpdateCaretFromKeyboard(); } } } #if SCKeyboard bool flag17 = this.m_Keyboard.status > SCKeyboard.Status.Visible; #elif TouchScreenKeyboard bool flag17 = this.m_Keyboard.status > TouchScreenKeyboard.Status.Visible; #endif if (flag17) { #if SCKeyboard bool flag18 = this.m_Keyboard.status == SCKeyboard.Status.Canceled; #elif TouchScreenKeyboard bool flag18 = this.m_Keyboard.status == TouchScreenKeyboard.Status.Canceled; #endif if (flag18) { this.m_WasCanceled = true; } this.OnDeselect(null); } } } #region SCKeyboard if (m_Keyboard != null && m_Keyboard.status > 0 && EventSystem.current.currentSelectedGameObject != this.gameObject) { this.m_ShouldDeactivateNextUpdate = true; } bool shouldDeactivateNextUpdate = this.m_ShouldDeactivateNextUpdate; if (shouldDeactivateNextUpdate) { OnDeselect(null); this.m_ShouldDeactivateNextUpdate = false; } #endregion } protected override bool MayDrag(PointerEventData eventData) { return this.IsActive() && this.IsInteractable() && eventData.button == PointerEventData.InputButton.Left && this.m_TextComponent != null && (this.InPlaceEditing() || this.m_HideMobileInput); } protected override 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; bool multiLine = this.multiLine; if (multiLine) { bool flag = localMousePos.y > rect.yMax; if (flag) { this.MoveUp(true, true); } else { bool flag2 = localMousePos.y < rect.yMin; if (flag2) { this.MoveDown(true, true); } } } else { bool flag3 = localMousePos.x < rect.xMin; if (flag3) { this.MoveLeft(true, false); } else { bool flag4 = localMousePos.x > rect.xMax; if (flag4) { this.MoveRight(true, false); } } } this.UpdateLabel(); float delay = this.multiLine ? 0.1f : 0.05f; bool flag5 = this.m_WaitForSecondsRealtime == null; if (flag5) { this.m_WaitForSecondsRealtime = new WaitForSecondsRealtime(delay); } else { this.m_WaitForSecondsRealtime.waitTime = delay; } yield return this.m_WaitForSecondsRealtime; localMousePos = default(Vector2); rect = default(Rect); } this.m_DragCoroutine = null; yield break; } public override void OnPointerDown(PointerEventData eventData) { bool flag = !this.MayDrag(eventData); if (!flag) { EventSystem.current.SetSelectedGameObject(base.gameObject, eventData); bool hadFocusBefore = this.m_AllowInput; base.OnPointerDown(eventData); bool flag2 = !this.InPlaceEditing(); if (flag2) { bool flag3 = this.m_Keyboard == null || !this.m_Keyboard.active; if (flag3) { this.OnSelect(eventData); return; } } bool flag4 = hadFocusBefore; if (flag4) { Vector2 localMousePos; RectTransformUtility.ScreenPointToLocalPointInRectangle(this.textComponent.rectTransform, eventData.position, eventData.pressEventCamera, out localMousePos); this.caretSelectPositionInternal = (this.caretPositionInternal = this.GetCharacterIndexFromPosition(localMousePos) + this.m_DrawStart); } this.UpdateLabel(); eventData.Use(); } } protected override UGUI_SCInputField.EditState KeyPressed(Event evt) { EventModifiers currentEventModifiers = evt.modifiers; bool ctrl = (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX) ? (((int)currentEventModifiers & 8) > 0) : (((int)currentEventModifiers & 2) > 0); bool shift = ((int)currentEventModifiers & 1) > 0; bool alt = ((int)currentEventModifiers & 4) > 0; bool ctrlOnly = ctrl && !alt && !shift; KeyCode keyCode = evt.keyCode; if (keyCode <= KeyCode.A) { if (keyCode <= KeyCode.Return) { if (keyCode == KeyCode.Backspace) { this.Backspace(); return UGUI_SCInputField.EditState.Continue; } if (keyCode != KeyCode.Return) { goto IL_27D; } } else { if (keyCode == KeyCode.Escape) { this.m_WasCanceled = true; return UGUI_SCInputField.EditState.Finish; } if (keyCode != KeyCode.A) { goto IL_27D; } bool flag = ctrlOnly; if (flag) { this.SelectAll(); return UGUI_SCInputField.EditState.Continue; } goto IL_27D; } } else if (keyCode <= KeyCode.V) { if (keyCode != KeyCode.C) { if (keyCode != KeyCode.V) { goto IL_27D; } bool flag2 = ctrlOnly; if (flag2) { this.Append(UGUI_SCInputField.clipboard); this.UpdateLabel(); return UGUI_SCInputField.EditState.Continue; } goto IL_27D; } else { bool flag3 = ctrlOnly; if (flag3) { bool flag4 = this.inputType != UGUI_SCInputField.InputType.Password; if (flag4) { UGUI_SCInputField.clipboard = this.GetSelectedString(); } else { UGUI_SCInputField.clipboard = ""; } return UGUI_SCInputField.EditState.Continue; } goto IL_27D; } } else if (keyCode != KeyCode.X) { if (keyCode == KeyCode.Delete) { this.ForwardSpace(); return UGUI_SCInputField.EditState.Continue; } switch (keyCode) { case KeyCode.KeypadEnter: break; case KeyCode.KeypadEquals: case KeyCode.Insert: goto IL_27D; case KeyCode.UpArrow: this.MoveUp(shift); return UGUI_SCInputField.EditState.Continue; case KeyCode.DownArrow: this.MoveDown(shift); return UGUI_SCInputField.EditState.Continue; case KeyCode.RightArrow: this.MoveRight(shift, ctrl); return UGUI_SCInputField.EditState.Continue; case KeyCode.LeftArrow: this.MoveLeft(shift, ctrl); return UGUI_SCInputField.EditState.Continue; case KeyCode.Home: this.MoveTextStart(shift); return UGUI_SCInputField.EditState.Continue; case KeyCode.End: this.MoveTextEnd(shift); return UGUI_SCInputField.EditState.Continue; default: goto IL_27D; } } else { bool flag5 = ctrlOnly; if (flag5) { bool flag6 = this.inputType != UGUI_SCInputField.InputType.Password; if (flag6) { UGUI_SCInputField.clipboard = this.GetSelectedString(); } else { UGUI_SCInputField.clipboard = ""; } this.Delete(); this.UpdateTouchKeyboardFromEditChanges(); this.SendOnValueChangedAndUpdateLabel(); return UGUI_SCInputField.EditState.Continue; } goto IL_27D; } bool flag7 = this.lineType != UGUI_SCInputField.LineType.MultiLineNewline; if (flag7) { return UGUI_SCInputField.EditState.Finish; } IL_27D: char c = evt.character; bool flag8 = !this.multiLine && (c == '\t' || c == '\r' || c == '\n'); UGUI_SCInputField.EditState result; if (flag8) { result = UGUI_SCInputField.EditState.Continue; } else { bool flag9 = c == '\r' || c == '\u0003'; if (flag9) { c = '\n'; } bool flag10 = this.IsValidChar(c); if (flag10) { this.Append(c); } bool flag11 = c == '\0'; if (flag11) { bool flag12 = this.compositionString.Length > 0; if (flag12) { this.UpdateLabel(); } } result = UGUI_SCInputField.EditState.Continue; } return result; } protected override bool IsValidChar(char c) { bool flag = c == '\u007f'; bool result; if (flag) { result = false; } else { bool flag2 = c == '\t' || c == '\n'; result = (flag2 || this.m_TextComponent.font.HasCharacter(c)); } return result; } public override void OnUpdateSelected(BaseEventData eventData) { bool flag = !this.isFocused; if (!flag) { bool consumedEvent = false; while (Event.PopEvent(this.m_ProcessingEvent)) { bool flag2 = (int)this.m_ProcessingEvent.rawType == 4; if (flag2) { consumedEvent = true; UGUI_SCInputField.EditState shouldContinue = this.KeyPressed(this.m_ProcessingEvent); bool flag3 = shouldContinue == UGUI_SCInputField.EditState.Finish; if (flag3) { this.DeactivateInputField(); break; } } EventType type = this.m_ProcessingEvent.type; if ((int)type - 13 <= 1) { string commandName = this.m_ProcessingEvent.commandName; if (commandName == "SelectAll") { this.SelectAll(); consumedEvent = true; } } } bool flag4 = consumedEvent; if (flag4) { this.UpdateLabel(); } eventData.Use(); } } protected override int DetermineCharacterLine(int charPos, TextGenerator generator) { for (int i = 0; i < generator.lineCount - 1; i++) { bool flag = generator.lines[i + 1].startCharIdx > charPos; if (flag) { return i; } } return generator.lineCount - 1; } protected override int LineUpCharacterPosition(int originalPos, bool goToFirstChar) { bool flag = originalPos >= this.cachedInputTextGenerator.characters.Count; int result; if (flag) { result = 0; } else { UICharInfo originChar = this.cachedInputTextGenerator.characters[originalPos]; int originLine = this.DetermineCharacterLine(originalPos, this.cachedInputTextGenerator); bool flag2 = originLine <= 0; if (flag2) { result = (goToFirstChar ? 0 : originalPos); } else { int endCharIdx = this.cachedInputTextGenerator.lines[originLine].startCharIdx - 1; for (int i = this.cachedInputTextGenerator.lines[originLine - 1].startCharIdx; i < endCharIdx; i++) { bool flag3 = this.cachedInputTextGenerator.characters[i].cursorPos.x >= originChar.cursorPos.x; if (flag3) { return i; } } result = endCharIdx; } } return result; } protected override int LineDownCharacterPosition(int originalPos, bool goToLastChar) { bool flag = originalPos >= this.cachedInputTextGenerator.characterCountVisible; int result; if (flag) { result = this.text.Length; } else { UICharInfo originChar = this.cachedInputTextGenerator.characters[originalPos]; int originLine = this.DetermineCharacterLine(originalPos, this.cachedInputTextGenerator); bool flag2 = originLine + 1 >= this.cachedInputTextGenerator.lineCount; if (flag2) { result = (goToLastChar ? this.text.Length : originalPos); } else { int endCharIdx = UGUI_SCInputField.GetLineEndPosition(this.cachedInputTextGenerator, originLine + 1); for (int i = this.cachedInputTextGenerator.lines[originLine + 1].startCharIdx; i < endCharIdx; i++) { bool flag3 = this.cachedInputTextGenerator.characters[i].cursorPos.x >= originChar.cursorPos.x; if (flag3) { return i; } } result = endCharIdx; } } return result; } protected override void ForwardSpace() { bool readOnly = this.m_ReadOnly; if (!readOnly) { bool hasSelection = this.hasSelection; if (hasSelection) { this.Delete(); this.UpdateTouchKeyboardFromEditChanges(); this.SendOnValueChangedAndUpdateLabel(); } else { bool flag = this.caretPositionInternal < this.text.Length; if (flag) { this.m_Text = this.text.Remove(this.caretPositionInternal, 1); this.UpdateTouchKeyboardFromEditChanges(); this.SendOnValueChangedAndUpdateLabel(); } } } } protected override void Backspace() { bool readOnly = this.m_ReadOnly; if (!readOnly) { bool hasSelection = this.hasSelection; if (hasSelection) { this.Delete(); this.UpdateTouchKeyboardFromEditChanges(); this.SendOnValueChangedAndUpdateLabel(); } else { bool flag = this.caretPositionInternal > 0; if (flag) { this.m_Text = this.text.Remove(this.caretPositionInternal - 1, 1); this.caretSelectPositionInternal = --this.caretPositionInternal; this.UpdateTouchKeyboardFromEditChanges(); this.SendOnValueChangedAndUpdateLabel(); } } } } protected override void Insert(char c) { bool readOnly = this.m_ReadOnly; if (!readOnly) { string replaceString = c.ToString(); this.Delete(); bool flag = this.characterLimit > 0 && this.text.Length >= this.characterLimit; if (!flag) { this.m_Text = this.text.Insert(this.m_CaretPosition, replaceString); this.caretSelectPositionInternal = (this.caretPositionInternal += replaceString.Length); this.UpdateTouchKeyboardFromEditChanges(); this.SendOnValueChanged(); } } } private void UpdateTouchKeyboardFromEditChanges() { bool flag = this.m_Keyboard != null && this.InPlaceEditing(); if (flag) { this.m_Keyboard.text = this.m_Text; } } protected override void Append(string input) { bool readOnly = this.m_ReadOnly; if (!readOnly) { bool flag = !this.InPlaceEditing(); if (!flag) { int i = 0; int imax = input.Length; while (i < imax) { char c = input[i]; bool flag2 = c >= ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\n'; if (flag2) { this.Append(c); } i++; } } } } protected override void Append(char input) { bool flag = char.IsSurrogate(input); if (!flag) { bool flag2 = this.m_ReadOnly || this.text.Length >= 16382; if (!flag2) { bool flag3 = !this.InPlaceEditing(); if (!flag3) { int insertionPoint = Math.Min(this.selectionFocusPosition, this.selectionAnchorPosition); bool flag4 = this.onValidateInput != null; if (flag4) { input = this.onValidateInput(this.text, insertionPoint, input); } else { bool flag5 = this.characterValidation > UGUI_SCInputField.CharacterValidation.None; if (flag5) { input = this.Validate(this.text, insertionPoint, input); } } bool flag6 = input == '\0'; if (!flag6) { this.Insert(input); } } } } } protected override bool IsSelectionVisible() { bool flag = this.m_DrawStart > this.caretPositionInternal || this.m_DrawStart > this.caretSelectPositionInternal; bool result; if (flag) { result = false; } else { bool flag2 = this.m_DrawEnd < this.caretPositionInternal || this.m_DrawEnd < this.caretSelectPositionInternal; result = !flag2; } return result; } protected override void SetDrawRangeToContainCaretPosition(int caretPos) { bool flag = this.cachedInputTextGenerator.lineCount <= 0; if (!flag) { Vector2 extents = this.cachedInputTextGenerator.rectExtents.size; bool multiLine = this.multiLine; if (multiLine) { IList lines = this.cachedInputTextGenerator.lines; int caretLine = this.DetermineCharacterLine(caretPos, this.cachedInputTextGenerator); bool flag2 = caretPos > this.m_DrawEnd; if (flag2) { this.m_DrawEnd = UGUI_SCInputField.GetLineEndPosition(this.cachedInputTextGenerator, caretLine); float bottomY = lines[caretLine].topY - (float)lines[caretLine].height; bool flag3 = caretLine == lines.Count - 1; if (flag3) { bottomY += lines[caretLine].leading; } int startLine; for (startLine = caretLine; startLine > 0; startLine--) { float topY = lines[startLine - 1].topY; bool flag4 = topY - bottomY > extents.y; if (flag4) { break; } } this.m_DrawStart = UGUI_SCInputField.GetLineStartPosition(this.cachedInputTextGenerator, startLine); } else { bool flag5 = caretPos < this.m_DrawStart; if (flag5) { this.m_DrawStart = UGUI_SCInputField.GetLineStartPosition(this.cachedInputTextGenerator, caretLine); } int startLine2 = this.DetermineCharacterLine(this.m_DrawStart, this.cachedInputTextGenerator); int endLine = startLine2; float topY2 = lines[startLine2].topY; float bottomY2 = lines[endLine].topY - (float)lines[endLine].height; bool flag6 = endLine == lines.Count - 1; if (flag6) { bottomY2 += lines[endLine].leading; } while (endLine < lines.Count - 1) { bottomY2 = lines[endLine + 1].topY - (float)lines[endLine + 1].height; bool flag7 = endLine + 1 == lines.Count - 1; if (flag7) { bottomY2 += lines[endLine + 1].leading; } bool flag8 = topY2 - bottomY2 > extents.y; if (flag8) { break; } endLine++; } this.m_DrawEnd = UGUI_SCInputField.GetLineEndPosition(this.cachedInputTextGenerator, endLine); while (startLine2 > 0) { topY2 = lines[startLine2 - 1].topY; bool flag9 = topY2 - bottomY2 > extents.y; if (flag9) { break; } startLine2--; } this.m_DrawStart = UGUI_SCInputField.GetLineStartPosition(this.cachedInputTextGenerator, startLine2); } } else { IList characters = this.cachedInputTextGenerator.characters; bool flag10 = this.m_DrawEnd > this.cachedInputTextGenerator.characterCountVisible; if (flag10) { this.m_DrawEnd = this.cachedInputTextGenerator.characterCountVisible; } float width = 0f; bool flag11 = caretPos > this.m_DrawEnd || (caretPos == this.m_DrawEnd && this.m_DrawStart > 0); if (flag11) { this.m_DrawEnd = caretPos; this.m_DrawStart = this.m_DrawEnd - 1; while (this.m_DrawStart >= 0) { bool flag12 = width + characters[this.m_DrawStart].charWidth > extents.x; if (flag12) { break; } width += characters[this.m_DrawStart].charWidth; this.m_DrawStart--; } this.m_DrawStart++; } else { bool flag13 = caretPos < this.m_DrawStart; if (flag13) { this.m_DrawStart = caretPos; } this.m_DrawEnd = this.m_DrawStart; } while (this.m_DrawEnd < this.cachedInputTextGenerator.characterCountVisible) { width += characters[this.m_DrawEnd].charWidth; bool flag14 = width > extents.x; if (flag14) { break; } this.m_DrawEnd++; } } } } #if UNITY_EDITOR protected override void MarkGeometryAsDirty() { bool flag = !Application.isPlaying || PrefabUtility.IsPartOfPrefabAsset(base.gameObject); if (!flag) { CanvasUpdateRegistry.RegisterCanvasElementForGraphicRebuild(this); } } #else protected override void MarkGeometryAsDirty() { bool flag = !Application.isPlaying; if (!flag) { CanvasUpdateRegistry.RegisterCanvasElementForGraphicRebuild(this); } } #endif protected override void UpdateGeometry() { bool flag = !Application.isPlaying; if (!flag) { bool flag2 = !this.shouldHideMobileInput; if (!flag2) { bool flag3 = this.m_CachedInputRenderer == null && this.m_TextComponent != null; if (flag3) { GameObject go = new GameObject(base.transform.name + " Input Caret", new Type[] { typeof(RectTransform), typeof(CanvasRenderer) }); go.hideFlags = HideFlags.DontSave; go.transform.SetParent(this.m_TextComponent.transform.parent); go.transform.SetAsFirstSibling(); go.layer = base.gameObject.layer; this.caretRectTrans = go.GetComponent(); this.m_CachedInputRenderer = go.GetComponent(); this.m_CachedInputRenderer.SetMaterial(this.m_TextComponent.GetModifiedMaterial(Graphic.defaultGraphicMaterial), Texture2D.whiteTexture); go.AddComponent().ignoreLayout = true; this.AssignPositioningIfNeeded(); } bool flag4 = this.m_CachedInputRenderer == null; if (!flag4) { this.OnFillVBO(this.mesh); this.m_CachedInputRenderer.SetMesh(this.mesh); } } } } private void GenerateHighlight(VertexHelper vbo, Vector2 roundingOffset) { int startChar = Mathf.Max(0, this.caretPositionInternal - this.m_DrawStart); int endChar = Mathf.Max(0, this.caretSelectPositionInternal - this.m_DrawStart); bool flag = startChar > endChar; if (flag) { int temp = startChar; startChar = endChar; endChar = temp; } endChar--; TextGenerator gen = this.m_TextComponent.cachedTextGenerator; bool flag2 = gen.lineCount <= 0; if (!flag2) { int currentLineIndex = this.DetermineCharacterLine(startChar, gen); int lastCharInLineIndex = UGUI_SCInputField.GetLineEndPosition(gen, currentLineIndex); UIVertex vert = UIVertex.simpleVert; vert.uv0 = Vector2.zero; vert.color = this.selectionColor; int currentChar = startChar; while (currentChar <= endChar && currentChar < gen.characterCount) { bool flag3 = currentChar == lastCharInLineIndex || currentChar == endChar; if (flag3) { UICharInfo startCharInfo = gen.characters[startChar]; UICharInfo endCharInfo = gen.characters[currentChar]; Vector2 startPosition = new Vector2(startCharInfo.cursorPos.x / this.m_TextComponent.pixelsPerUnit, gen.lines[currentLineIndex].topY / this.m_TextComponent.pixelsPerUnit); Vector2 endPosition = new Vector2((endCharInfo.cursorPos.x + endCharInfo.charWidth) / this.m_TextComponent.pixelsPerUnit, startPosition.y - (float)gen.lines[currentLineIndex].height / this.m_TextComponent.pixelsPerUnit); bool flag4 = endPosition.x > this.m_TextComponent.rectTransform.rect.xMax || endPosition.x < this.m_TextComponent.rectTransform.rect.xMin; if (flag4) { endPosition.x = this.m_TextComponent.rectTransform.rect.xMax; } int startIndex = vbo.currentVertCount; vert.position = new Vector3(startPosition.x, endPosition.y, 0f) + new Vector3(roundingOffset.x, roundingOffset.y, 0); vbo.AddVert(vert); vert.position = new Vector3(endPosition.x, endPosition.y, 0f) + new Vector3(roundingOffset.x, roundingOffset.y, 0); vbo.AddVert(vert); vert.position = new Vector3(endPosition.x, startPosition.y, 0f) + new Vector3(roundingOffset.x, roundingOffset.y, 0); vbo.AddVert(vert); vert.position = new Vector3(startPosition.x, startPosition.y, 0f) + new Vector3(roundingOffset.x, roundingOffset.y, 0); vbo.AddVert(vert); vbo.AddTriangle(startIndex, startIndex + 1, startIndex + 2); vbo.AddTriangle(startIndex + 2, startIndex + 3, startIndex); startChar = currentChar + 1; currentLineIndex++; lastCharInLineIndex = UGUI_SCInputField.GetLineEndPosition(gen, currentLineIndex); } currentChar++; } } } protected override char Validate(string text, int pos, char ch) { bool flag = this.characterValidation == UGUI_SCInputField.CharacterValidation.None || !base.enabled; char result; if (flag) { result = ch; } else { bool flag2 = this.characterValidation == UGUI_SCInputField.CharacterValidation.Integer || this.characterValidation == UGUI_SCInputField.CharacterValidation.Decimal; if (flag2) { bool cursorBeforeDash = pos == 0 && text.Length > 0 && text[0] == '-'; bool dashInSelection = text.Length > 0 && text[0] == '-' && ((this.caretPositionInternal == 0 && this.caretSelectPositionInternal > 0) || (this.caretSelectPositionInternal == 0 && this.caretPositionInternal > 0)); bool selectionAtStart = this.caretPositionInternal == 0 || this.caretSelectPositionInternal == 0; bool flag3 = !cursorBeforeDash || dashInSelection; if (flag3) { bool flag4 = ch >= '0' && ch <= '9'; if (flag4) { return ch; } bool flag5 = ch == '-' && (pos == 0 || selectionAtStart); if (flag5) { return ch; } bool flag6 = (ch == '.' || ch == ',') && this.characterValidation == UGUI_SCInputField.CharacterValidation.Decimal && text.IndexOfAny(new char[] { '.', ',' }) == -1; if (flag6) { return ch; } } } else { bool flag7 = this.characterValidation == UGUI_SCInputField.CharacterValidation.Alphanumeric; if (flag7) { bool flag8 = ch >= 'A' && ch <= 'Z'; if (flag8) { return ch; } bool flag9 = ch >= 'a' && ch <= 'z'; if (flag9) { return ch; } bool flag10 = ch >= '0' && ch <= '9'; if (flag10) { return ch; } } else { bool flag11 = this.characterValidation == UGUI_SCInputField.CharacterValidation.Name; if (flag11) { bool flag12 = char.IsLetter(ch); if (flag12) { bool flag13 = char.IsLower(ch) && (pos == 0 || text[pos - 1] == ' '); if (flag13) { return char.ToUpper(ch); } bool flag14 = char.IsUpper(ch) && pos > 0 && text[pos - 1] != ' ' && text[pos - 1] != '\''; if (flag14) { return char.ToLower(ch); } return ch; } else { bool flag15 = ch == '\''; if (flag15) { bool flag16 = !text.Contains("'"); if (flag16) { bool flag17 = (pos <= 0 || (text[pos - 1] != ' ' && text[pos - 1] != '\'')) && (pos >= text.Length || (text[pos] != ' ' && text[pos] != '\'')); if (flag17) { return ch; } } } bool flag18 = ch == ' '; if (flag18) { bool flag19 = pos != 0; if (flag19) { bool flag20 = (pos <= 0 || (text[pos - 1] != ' ' && text[pos - 1] != '\'')) && (pos >= text.Length || (text[pos] != ' ' && text[pos] != '\'')); if (flag20) { return ch; } } } } } else { bool flag21 = this.characterValidation == UGUI_SCInputField.CharacterValidation.EmailAddress; if (flag21) { bool flag22 = ch >= 'A' && ch <= 'Z'; if (flag22) { return ch; } bool flag23 = ch >= 'a' && ch <= 'z'; if (flag23) { return ch; } bool flag24 = ch >= '0' && ch <= '9'; if (flag24) { return ch; } bool flag25 = ch == '@' && text.IndexOf('@') == -1; if (flag25) { return ch; } bool flag26 = "!#$%&'*+-/=?^_`{|}~".IndexOf(ch) != -1; if (flag26) { return ch; } bool flag27 = ch == '.'; if (flag27) { char lastChar = (text.Length > 0) ? text[Mathf.Clamp(pos, 0, text.Length - 1)] : ' '; char nextChar = (text.Length > 0) ? text[Mathf.Clamp(pos + 1, 0, text.Length - 1)] : '\n'; bool flag28 = lastChar != '.' && nextChar != '.'; if (flag28) { return ch; } } } } } } result = '\0'; } return result; } public override void ActivateInputField() { bool flag = this.m_TextComponent == null || this.m_TextComponent.font == null || !this.IsActive() || !this.IsInteractable(); if (!flag) { bool isFocused = this.isFocused; if (isFocused) { bool flag2 = this.m_Keyboard != null && !this.m_Keyboard.active; if (flag2) { this.m_Keyboard.active = true; this.m_Keyboard.text = this.m_Text; } } this.m_ShouldActivateNextUpdate = true; } } protected override void ActivateInputFieldInternal() { bool flag = EventSystem.current == null; if (!flag) { bool flag2 = EventSystem.current.currentSelectedGameObject != base.gameObject; if (flag2) { EventSystem.current.SetSelectedGameObject(base.gameObject); } #if SCKeyboard bool isSupported = SCKeyboard.isSupported; #elif TouchScreenKeyboard bool isSupported = TouchScreenKeyboard.isSupported; #endif if (isSupported) { bool touchSupported = this.input.touchSupported; if (touchSupported) { #if SCKeyboard SCKeyboard.hideInput = this.shouldHideMobileInput; #elif TouchScreenKeyboard TouchScreenKeyboard.hideInput = this.shouldHideMobileInput; #endif } #if SCKeyboard // Set SCKeyboard Transform m_Keyboard = SetKeyboardTransform(); // Set SCKeyboard Order In Layer SetKeyboardOrderInLayer(m_OrderInLayer); // Set Keyboard Regist Events SetKeyboardRegistEvents(m_Keyboard); //m_Keyboard.SetTextOnOpen(text); this.m_TouchKeyboardAllowsInPlaceEditing = SCKeyboard.isInPlaceEditingAllowed; #elif TouchScreenKeyboard this.m_Keyboard = ((this.inputType == UGUI_SCInputField.InputType.Password) ? TouchScreenKeyboard.Open(this.m_Text, this.keyboardType, false, this.multiLine, true, false, "", this.characterLimit) : TouchScreenKeyboard.Open(this.m_Text, this.keyboardType, this.inputType == UGUI_SCInputField.InputType.AutoCorrect, this.multiLine, false, false, "", this.characterLimit)); this.m_TouchKeyboardAllowsInPlaceEditing = TouchScreenKeyboard.isInPlaceEditingAllowed; #endif 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 OnPointerClick(PointerEventData eventData) { bool flag = eventData.button > PointerEventData.InputButton.Left; if (!flag) { this.ActivateInputField(); } } public override void DeactivateInputField() { bool flag = !this.m_AllowInput; if (!flag) { this.m_HasDoneFocusTransition = false; this.m_AllowInput = false; bool flag2 = this.m_Placeholder != null; if (flag2) { this.m_Placeholder.enabled = string.IsNullOrEmpty(this.m_Text); } bool flag3 = this.m_TextComponent != null && this.IsInteractable(); if (flag3) { bool wasCanceled = this.m_WasCanceled; if (wasCanceled) { this.text = this.m_OriginalText; } this.SendOnSubmit(); bool flag4 = this.m_Keyboard != null; if (flag4) { this.m_Keyboard.active = false; this.m_Keyboard = null; } this.m_CaretPosition = (this.m_CaretSelectPosition = 0); if (this.input != null) this.input.imeCompositionMode = IMECompositionMode.Auto; } this.MarkGeometryAsDirty(); } } public override void OnDeselect(BaseEventData eventData) { if (shouldDeactivateOnDeselect) { //this.DeactivateInputField(); base.OnDeselect(eventData); } } protected override void DoStateTransition(Selectable.SelectionState state, bool instant) { bool hasDoneFocusTransition = this.m_HasDoneFocusTransition; if (hasDoneFocusTransition) { state = Selectable.SelectionState.Selected; } else { bool flag = state == Selectable.SelectionState.Pressed; if (flag) { this.m_HasDoneFocusTransition = true; } } base.DoStateTransition(state, instant); } //Transform ICanvasElement.get_transform() //{ // return base.transform; //} #if SCKeyboard protected new SCKeyboard m_Keyboard; #elif TouchScreenKeyboard protected TouchScreenKeyboard m_Keyboard; #endif private bool m_ShouldDeactivateNextUpdate = false; private WaitForSecondsRealtime m_WaitForSecondsRealtime; private bool m_TouchKeyboardAllowsInPlaceEditing = false; private const int k_MaxTextLength = 16382; #region SCKeyboard [SerializeField] public SCKeyboardType m_SCKeyboardType = SCKeyboardType.Default; [SerializeField] public SCKeyboardSpaceEnum m_SCKeyboardSpaceEnum = SCKeyboardSpaceEnum.WorldSpace; [SerializeField] protected float m_CustomDistance = 1.0f; [SerializeField] protected Vector2 m_CustomOffset = Vector2.down * 0.2f; [SerializeField] protected bool m_UseCustomOrderInLayer = false; [SerializeField] protected int m_OrderInLayer = 10; #endregion public void SetKeyboardLocalTransform(Vector3 position, Quaternion rotation, Vector3 localScale) { m_UseCustomTransform = true; m_SCKeyboardSpaceEnum = SCKeyboardSpaceEnum.LocalSpace; m_CustomPosition = position; m_CustomRotation = rotation.eulerAngles; m_CustomLocalScale = localScale; ResetKeyboardTransform(); } public void SetKeyboardWorldTransform(Vector3 position, Quaternion rotation, Vector3 localScale) { m_UseCustomTransform = true; m_SCKeyboardSpaceEnum = SCKeyboardSpaceEnum.WorldSpace; m_CustomPosition = position; m_CustomRotation = rotation.eulerAngles; m_CustomLocalScale = localScale; ResetKeyboardTransform(); } public void SetKeyboardOriginTransform(float distance, Vector2 offset, Quaternion rotation, Vector3 localScale) { m_UseCustomTransform = true; m_SCKeyboardSpaceEnum = SCKeyboardSpaceEnum.OriginSpace; m_CustomDistance = distance; m_CustomOffset = offset; m_CustomRotation = rotation.eulerAngles; m_CustomLocalScale = localScale; ResetKeyboardTransform(); } public virtual void ResetKeyboardTransform() { if (m_Keyboard != null) { SetKeyboardTransform(); } } private SCKeyboard SetKeyboardTransform() { SCKeyboard scKeyboard; Vector3 position = Vector3.zero; Quaternion rotation = Quaternion.identity; Vector3 localScale = Vector3.one; GetKeyboardTransform(ref position, ref rotation, ref localScale); scKeyboard = SCKeyboard.Open(this.scKeyboardEnum, m_Text, this.scKeyboardType, position, rotation, localScale); scKeyboard.transform.SetParent(this.transform); return scKeyboard; } private void SetKeyboardRegistEvents(SCKeyboard scKeyboard) { scKeyboard.Clear(); scKeyboard.RegisterOnKeyClickEvent((str) => { Append(str); this.UpdateLabel(); }); scKeyboard.RegisterOnSpecialKeyClickEvent(Module_Keyboard.SpecialKeyEnum.Delete, Backspace); } private void GetKeyboardTransform(ref Vector3 position, ref Quaternion rotation, ref Vector3 localScale) { Transform head = Camera.main.transform.transform; if (m_UseCustomTransform) { switch (m_SCKeyboardSpaceEnum) { case SCKeyboardSpaceEnum.OriginSpace: Vector3 direction = Vector3.ProjectOnPlane(head.forward, Vector3.up); position = head.position + direction * m_CustomDistance + (Vector3)m_CustomOffset; rotation = Quaternion.AngleAxis(head.rotation.eulerAngles.y, Vector3.up) * Quaternion.Euler(m_CustomRotation); localScale = m_CustomLocalScale; break; case SCKeyboardSpaceEnum.WorldSpace: case SCKeyboardSpaceEnum.LocalSpace: position = m_CustomPosition; rotation = Quaternion.Euler(m_CustomRotation); localScale = m_CustomLocalScale; break; } } else { Vector3 direction = Vector3.ProjectOnPlane(head.forward, Vector3.up); position = head.position + direction * 1 + Vector3.down * 0.2f; rotation = Quaternion.AngleAxis(head.rotation.eulerAngles.y, Vector3.up) * Quaternion.Euler(Vector3.right * 30); localScale = Vector3.one; } } private void SetKeyboardOrderInLayer(int value) { switch (m_SCKeyboardEnum) { case SCKeyboardEnum.SCKeyboard2D: Canvas canvas = m_Keyboard.transform.GetComponentInChildren(); canvas.overrideSorting = true; canvas.sortingOrder = value; break; case SCKeyboardEnum.SCKeyboard3D: break; } } } #region SCKeyboard [Serializable] public enum SCKeyboardSpaceEnum { OriginSpace = 0, WorldSpace = 1, LocalSpace = 2 } #endregion }