123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749 |
- //#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<bool>(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<int>(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<SCKeyboardEnum>(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<SCKeyboardType>(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<TouchScreenKeyboardType>(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<UILineInfo> 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<UICharInfo> 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<RectTransform>();
- this.m_CachedInputRenderer = go.GetComponent<CanvasRenderer>();
- this.m_CachedInputRenderer.SetMaterial(this.m_TextComponent.GetModifiedMaterial(Graphic.defaultGraphicMaterial), Texture2D.whiteTexture);
- go.AddComponent<LayoutElement>().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>();
- canvas.overrideSorting = true;
- canvas.sortingOrder = value;
- break;
- case SCKeyboardEnum.SCKeyboard3D:
- break;
- }
- }
- }
- #region SCKeyboard
- [Serializable]
- public enum SCKeyboardSpaceEnum
- {
- OriginSpace = 0,
- WorldSpace = 1,
- LocalSpace = 2
- }
- #endregion
- }
|