12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597 |
- 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<bool>(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<float>(ref this.m_CaretBlinkRate, value) && this.m_AllowInput)
- {
- this.SetCaretActive();
- }
- }
- }
- public int caretWidth
- {
- get
- {
- return this.m_CaretWidth;
- }
- set
- {
- if (SetPropertyUtility.SetStruct<int>(ref this.m_CaretWidth, value))
- {
- this.MarkGeometryAsDirty();
- }
- }
- }
- public Text textComponent
- {
- get
- {
- return this.m_TextComponent;
- }
- set
- {
- if (SetPropertyUtility.SetClass<Text>(ref this.m_TextComponent, value))
- {
- this.EnforceTextHOverflow();
- }
- }
- }
- public Graphic placeholder
- {
- get
- {
- return this.m_Placeholder;
- }
- set
- {
- SetPropertyUtility.SetClass<Graphic>(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<uGUIInputField.SubmitEvent>(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<uGUIInputField.OnChangeEvent>(ref this.m_OnValueChanged, value);
- }
- }
- public uGUIInputField.OnValidateInput onValidateInput
- {
- get
- {
- return this.m_OnValidateInput;
- }
- set
- {
- SetPropertyUtility.SetClass<uGUIInputField.OnValidateInput>(ref this.m_OnValidateInput, value);
- }
- }
- public int characterLimit
- {
- get
- {
- return this.m_CharacterLimit;
- }
- set
- {
- if (SetPropertyUtility.SetStruct<int>(ref this.m_CharacterLimit, Math.Max(0, value)))
- {
- this.UpdateLabel();
- }
- }
- }
- public uGUIInputField.ContentType contentType
- {
- get
- {
- return this.m_ContentType;
- }
- set
- {
- if (SetPropertyUtility.SetStruct<uGUIInputField.ContentType>(ref this.m_ContentType, value))
- {
- this.EnforceContentType();
- }
- }
- }
- public uGUIInputField.LineType lineType
- {
- get
- {
- return this.m_LineType;
- }
- set
- {
- if (SetPropertyUtility.SetStruct<uGUIInputField.LineType>(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<uGUIInputField.InputType>(ref this.m_InputType, value))
- {
- this.SetToCustom();
- }
- }
- }
- public TouchScreenKeyboardType keyboardType
- {
- get
- {
- return this.m_KeyboardType;
- }
- set
- {
- if (SetPropertyUtility.SetStruct<TouchScreenKeyboardType>(ref this.m_KeyboardType, value))
- {
- this.SetToCustom();
- }
- }
- }
- public uGUIInputField.CharacterValidation characterValidation
- {
- get
- {
- return this.m_CharacterValidation;
- }
- set
- {
- if (SetPropertyUtility.SetStruct<uGUIInputField.CharacterValidation>(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<char>(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<UILineInfo> 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<UICharInfo> 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<RectTransform>();
- this.m_CachedInputRenderer = gameObject.GetComponent<CanvasRenderer>();
- this.m_CachedInputRenderer.SetMaterial(this.m_TextComponent.GetModifiedMaterial(Graphic.defaultGraphicMaterial), Texture2D.whiteTexture);
- gameObject.AddComponent<LayoutElement>().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<string>
- {
- }
- [Serializable]
- public class OnChangeEvent : UnityEvent<string>
- {
- }
- protected enum EditState
- {
- Continue,
- Finish
- }
- }
- }
|