uGUIInputField.cs 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine.Events;
  5. using UnityEngine.EventSystems;
  6. using UnityEngine.Serialization;
  7. namespace UnityEngine.UI
  8. {
  9. public class uGUIInputField : Selectable, IUpdateSelectedHandler, IBeginDragHandler, IDragHandler, IEndDragHandler, IPointerClickHandler, ISubmitHandler, ICanvasElement, ILayoutElement, IEventSystemHandler
  10. {
  11. protected uGUIInputField()
  12. {
  13. this.EnforceTextHOverflow();
  14. }
  15. private BaseInput input
  16. {
  17. get
  18. {
  19. if (EventSystem.current && EventSystem.current.currentInputModule)
  20. {
  21. return EventSystem.current.currentInputModule.input;
  22. }
  23. return null;
  24. }
  25. }
  26. private string compositionString
  27. {
  28. get
  29. {
  30. return (!(this.input != null)) ? Input.compositionString : this.input.compositionString;
  31. }
  32. }
  33. protected Mesh mesh
  34. {
  35. get
  36. {
  37. if (this.m_Mesh == null)
  38. {
  39. this.m_Mesh = new Mesh();
  40. }
  41. return this.m_Mesh;
  42. }
  43. }
  44. protected TextGenerator cachedInputTextGenerator
  45. {
  46. get
  47. {
  48. if (this.m_InputTextCache == null)
  49. {
  50. this.m_InputTextCache = new TextGenerator();
  51. }
  52. return this.m_InputTextCache;
  53. }
  54. }
  55. public bool shouldHideMobileInput
  56. {
  57. get
  58. {
  59. RuntimePlatform platform = Application.platform;
  60. switch (platform)
  61. {
  62. case RuntimePlatform.IPhonePlayer:
  63. case RuntimePlatform.Android:
  64. break;
  65. default:
  66. if (platform != RuntimePlatform.TizenPlayer && platform != RuntimePlatform.tvOS)
  67. {
  68. return true;
  69. }
  70. break;
  71. }
  72. return this.m_HideMobileInput;
  73. }
  74. set
  75. {
  76. SetPropertyUtility.SetStruct<bool>(ref this.m_HideMobileInput, value);
  77. }
  78. }
  79. private bool shouldActivateOnSelect
  80. {
  81. get
  82. {
  83. return Application.platform != RuntimePlatform.tvOS;
  84. }
  85. }
  86. public string text
  87. {
  88. get
  89. {
  90. return this.m_Text;
  91. }
  92. set
  93. {
  94. if (this.text == value)
  95. {
  96. return;
  97. }
  98. if (value == null)
  99. {
  100. value = string.Empty;
  101. }
  102. value = value.Replace("\0", string.Empty);
  103. if (this.m_LineType == uGUIInputField.LineType.SingleLine)
  104. {
  105. value = value.Replace("\n", string.Empty).Replace("\t", string.Empty);
  106. }
  107. if (this.onValidateInput != null || this.characterValidation != uGUIInputField.CharacterValidation.None)
  108. {
  109. this.m_Text = string.Empty;
  110. uGUIInputField.OnValidateInput onValidateInput = this.onValidateInput ?? new uGUIInputField.OnValidateInput(this.Validate);
  111. this.m_CaretPosition = (this.m_CaretSelectPosition = value.Length);
  112. int num = (this.characterLimit <= 0) ? value.Length : Math.Min(this.characterLimit, value.Length);
  113. for (int i = 0; i < num; i++)
  114. {
  115. char c = onValidateInput(this.m_Text, this.m_Text.Length, value[i]);
  116. if (c != '\0')
  117. {
  118. this.m_Text += c;
  119. }
  120. }
  121. }
  122. else
  123. {
  124. this.m_Text = ((this.characterLimit <= 0 || value.Length <= this.characterLimit) ? value : value.Substring(0, this.characterLimit));
  125. }
  126. if (this.m_Keyboard != null)
  127. {
  128. this.m_Keyboard.text = this.m_Text;
  129. }
  130. if (this.m_CaretPosition > this.m_Text.Length)
  131. {
  132. this.m_CaretPosition = (this.m_CaretSelectPosition = this.m_Text.Length);
  133. }
  134. else if (this.m_CaretSelectPosition > this.m_Text.Length)
  135. {
  136. this.m_CaretSelectPosition = this.m_Text.Length;
  137. }
  138. this.SendOnValueChangedAndUpdateLabel();
  139. }
  140. }
  141. public bool isFocused
  142. {
  143. get
  144. {
  145. return this.m_AllowInput;
  146. }
  147. }
  148. public float caretBlinkRate
  149. {
  150. get
  151. {
  152. return this.m_CaretBlinkRate;
  153. }
  154. set
  155. {
  156. if (SetPropertyUtility.SetStruct<float>(ref this.m_CaretBlinkRate, value) && this.m_AllowInput)
  157. {
  158. this.SetCaretActive();
  159. }
  160. }
  161. }
  162. public int caretWidth
  163. {
  164. get
  165. {
  166. return this.m_CaretWidth;
  167. }
  168. set
  169. {
  170. if (SetPropertyUtility.SetStruct<int>(ref this.m_CaretWidth, value))
  171. {
  172. this.MarkGeometryAsDirty();
  173. }
  174. }
  175. }
  176. public Text textComponent
  177. {
  178. get
  179. {
  180. return this.m_TextComponent;
  181. }
  182. set
  183. {
  184. if (SetPropertyUtility.SetClass<Text>(ref this.m_TextComponent, value))
  185. {
  186. this.EnforceTextHOverflow();
  187. }
  188. }
  189. }
  190. public Graphic placeholder
  191. {
  192. get
  193. {
  194. return this.m_Placeholder;
  195. }
  196. set
  197. {
  198. SetPropertyUtility.SetClass<Graphic>(ref this.m_Placeholder, value);
  199. }
  200. }
  201. public Color caretColor
  202. {
  203. get
  204. {
  205. return (!this.customCaretColor) ? this.textComponent.color : this.m_CaretColor;
  206. }
  207. set
  208. {
  209. if (SetPropertyUtility.SetColor(ref this.m_CaretColor, value))
  210. {
  211. this.MarkGeometryAsDirty();
  212. }
  213. }
  214. }
  215. public bool customCaretColor
  216. {
  217. get
  218. {
  219. return this.m_CustomCaretColor;
  220. }
  221. set
  222. {
  223. if (this.m_CustomCaretColor != value)
  224. {
  225. this.m_CustomCaretColor = value;
  226. this.MarkGeometryAsDirty();
  227. }
  228. }
  229. }
  230. public Color selectionColor
  231. {
  232. get
  233. {
  234. return this.m_SelectionColor;
  235. }
  236. set
  237. {
  238. if (SetPropertyUtility.SetColor(ref this.m_SelectionColor, value))
  239. {
  240. this.MarkGeometryAsDirty();
  241. }
  242. }
  243. }
  244. public uGUIInputField.SubmitEvent onEndEdit
  245. {
  246. get
  247. {
  248. return this.m_OnEndEdit;
  249. }
  250. set
  251. {
  252. SetPropertyUtility.SetClass<uGUIInputField.SubmitEvent>(ref this.m_OnEndEdit, value);
  253. }
  254. }
  255. [Obsolete("onValueChange has been renamed to onValueChanged")]
  256. public uGUIInputField.OnChangeEvent onValueChange
  257. {
  258. get
  259. {
  260. return this.onValueChanged;
  261. }
  262. set
  263. {
  264. this.onValueChanged = value;
  265. }
  266. }
  267. public uGUIInputField.OnChangeEvent onValueChanged
  268. {
  269. get
  270. {
  271. return this.m_OnValueChanged;
  272. }
  273. set
  274. {
  275. SetPropertyUtility.SetClass<uGUIInputField.OnChangeEvent>(ref this.m_OnValueChanged, value);
  276. }
  277. }
  278. public uGUIInputField.OnValidateInput onValidateInput
  279. {
  280. get
  281. {
  282. return this.m_OnValidateInput;
  283. }
  284. set
  285. {
  286. SetPropertyUtility.SetClass<uGUIInputField.OnValidateInput>(ref this.m_OnValidateInput, value);
  287. }
  288. }
  289. public int characterLimit
  290. {
  291. get
  292. {
  293. return this.m_CharacterLimit;
  294. }
  295. set
  296. {
  297. if (SetPropertyUtility.SetStruct<int>(ref this.m_CharacterLimit, Math.Max(0, value)))
  298. {
  299. this.UpdateLabel();
  300. }
  301. }
  302. }
  303. public uGUIInputField.ContentType contentType
  304. {
  305. get
  306. {
  307. return this.m_ContentType;
  308. }
  309. set
  310. {
  311. if (SetPropertyUtility.SetStruct<uGUIInputField.ContentType>(ref this.m_ContentType, value))
  312. {
  313. this.EnforceContentType();
  314. }
  315. }
  316. }
  317. public uGUIInputField.LineType lineType
  318. {
  319. get
  320. {
  321. return this.m_LineType;
  322. }
  323. set
  324. {
  325. if (SetPropertyUtility.SetStruct<uGUIInputField.LineType>(ref this.m_LineType, value))
  326. {
  327. this.SetToCustomIfContentTypeIsNot(new uGUIInputField.ContentType[]
  328. {
  329. uGUIInputField.ContentType.Standard,
  330. uGUIInputField.ContentType.Autocorrected
  331. });
  332. this.EnforceTextHOverflow();
  333. }
  334. }
  335. }
  336. public uGUIInputField.InputType inputType
  337. {
  338. get
  339. {
  340. return this.m_InputType;
  341. }
  342. set
  343. {
  344. if (SetPropertyUtility.SetStruct<uGUIInputField.InputType>(ref this.m_InputType, value))
  345. {
  346. this.SetToCustom();
  347. }
  348. }
  349. }
  350. public TouchScreenKeyboardType keyboardType
  351. {
  352. get
  353. {
  354. return this.m_KeyboardType;
  355. }
  356. set
  357. {
  358. if (SetPropertyUtility.SetStruct<TouchScreenKeyboardType>(ref this.m_KeyboardType, value))
  359. {
  360. this.SetToCustom();
  361. }
  362. }
  363. }
  364. public uGUIInputField.CharacterValidation characterValidation
  365. {
  366. get
  367. {
  368. return this.m_CharacterValidation;
  369. }
  370. set
  371. {
  372. if (SetPropertyUtility.SetStruct<uGUIInputField.CharacterValidation>(ref this.m_CharacterValidation, value))
  373. {
  374. this.SetToCustom();
  375. }
  376. }
  377. }
  378. public bool readOnly
  379. {
  380. get
  381. {
  382. return this.m_ReadOnly;
  383. }
  384. set
  385. {
  386. this.m_ReadOnly = value;
  387. }
  388. }
  389. public bool multiLine
  390. {
  391. get
  392. {
  393. return this.m_LineType == uGUIInputField.LineType.MultiLineNewline || this.lineType == uGUIInputField.LineType.MultiLineSubmit;
  394. }
  395. }
  396. public char asteriskChar
  397. {
  398. get
  399. {
  400. return this.m_AsteriskChar;
  401. }
  402. set
  403. {
  404. if (SetPropertyUtility.SetStruct<char>(ref this.m_AsteriskChar, value))
  405. {
  406. this.UpdateLabel();
  407. }
  408. }
  409. }
  410. public bool wasCanceled
  411. {
  412. get
  413. {
  414. return this.m_WasCanceled;
  415. }
  416. }
  417. protected void ClampPos(ref int pos)
  418. {
  419. if (pos < 0)
  420. {
  421. pos = 0;
  422. }
  423. else if (pos > this.text.Length)
  424. {
  425. pos = this.text.Length;
  426. }
  427. }
  428. protected int caretPositionInternal
  429. {
  430. get
  431. {
  432. return this.m_CaretPosition + this.compositionString.Length;
  433. }
  434. set
  435. {
  436. this.m_CaretPosition = value;
  437. this.ClampPos(ref this.m_CaretPosition);
  438. }
  439. }
  440. protected int caretSelectPositionInternal
  441. {
  442. get
  443. {
  444. return this.m_CaretSelectPosition + this.compositionString.Length;
  445. }
  446. set
  447. {
  448. this.m_CaretSelectPosition = value;
  449. this.ClampPos(ref this.m_CaretSelectPosition);
  450. }
  451. }
  452. private bool hasSelection
  453. {
  454. get
  455. {
  456. return this.caretPositionInternal != this.caretSelectPositionInternal;
  457. }
  458. }
  459. public int caretPosition
  460. {
  461. get
  462. {
  463. return this.m_CaretSelectPosition + this.compositionString.Length;
  464. }
  465. set
  466. {
  467. this.selectionAnchorPosition = value;
  468. this.selectionFocusPosition = value;
  469. }
  470. }
  471. public int selectionAnchorPosition
  472. {
  473. get
  474. {
  475. return this.m_CaretPosition + this.compositionString.Length;
  476. }
  477. set
  478. {
  479. if (this.compositionString.Length != 0)
  480. {
  481. return;
  482. }
  483. this.m_CaretPosition = value;
  484. this.ClampPos(ref this.m_CaretPosition);
  485. }
  486. }
  487. public int selectionFocusPosition
  488. {
  489. get
  490. {
  491. return this.m_CaretSelectPosition + this.compositionString.Length;
  492. }
  493. set
  494. {
  495. if (this.compositionString.Length != 0)
  496. {
  497. return;
  498. }
  499. this.m_CaretSelectPosition = value;
  500. this.ClampPos(ref this.m_CaretSelectPosition);
  501. }
  502. }
  503. protected override void OnEnable()
  504. {
  505. base.OnEnable();
  506. if (this.m_Text == null)
  507. {
  508. this.m_Text = string.Empty;
  509. }
  510. this.m_DrawStart = 0;
  511. this.m_DrawEnd = this.m_Text.Length;
  512. if (this.m_CachedInputRenderer != null)
  513. {
  514. this.m_CachedInputRenderer.SetMaterial(this.m_TextComponent.GetModifiedMaterial(Graphic.defaultGraphicMaterial), Texture2D.whiteTexture);
  515. }
  516. if (this.m_TextComponent != null)
  517. {
  518. this.m_TextComponent.RegisterDirtyVerticesCallback(new UnityAction(this.MarkGeometryAsDirty));
  519. this.m_TextComponent.RegisterDirtyVerticesCallback(new UnityAction(this.UpdateLabel));
  520. this.m_TextComponent.RegisterDirtyMaterialCallback(new UnityAction(this.UpdateCaretMaterial));
  521. this.UpdateLabel();
  522. }
  523. }
  524. protected override void OnDisable()
  525. {
  526. this.m_BlinkCoroutine = null;
  527. this.DeactivateuGUIInputField();
  528. if (this.m_TextComponent != null)
  529. {
  530. this.m_TextComponent.UnregisterDirtyVerticesCallback(new UnityAction(this.MarkGeometryAsDirty));
  531. this.m_TextComponent.UnregisterDirtyVerticesCallback(new UnityAction(this.UpdateLabel));
  532. this.m_TextComponent.UnregisterDirtyMaterialCallback(new UnityAction(this.UpdateCaretMaterial));
  533. }
  534. CanvasUpdateRegistry.UnRegisterCanvasElementForRebuild(this);
  535. if (this.m_CachedInputRenderer != null)
  536. {
  537. this.m_CachedInputRenderer.Clear();
  538. }
  539. if (this.m_Mesh != null)
  540. {
  541. Object.DestroyImmediate(this.m_Mesh);
  542. }
  543. this.m_Mesh = null;
  544. base.OnDisable();
  545. }
  546. private IEnumerator CaretBlink()
  547. {
  548. this.m_CaretVisible = true;
  549. yield return null;
  550. while (this.isFocused && this.m_CaretBlinkRate > 0f)
  551. {
  552. float blinkPeriod = 1f / this.m_CaretBlinkRate;
  553. bool blinkState = (Time.unscaledTime - this.m_BlinkStartTime) % blinkPeriod < blinkPeriod / 2f;
  554. if (this.m_CaretVisible != blinkState)
  555. {
  556. this.m_CaretVisible = blinkState;
  557. if (!this.hasSelection)
  558. {
  559. this.MarkGeometryAsDirty();
  560. }
  561. }
  562. yield return null;
  563. }
  564. this.m_BlinkCoroutine = null;
  565. yield break;
  566. }
  567. private void SetCaretVisible()
  568. {
  569. if (!this.m_AllowInput)
  570. {
  571. return;
  572. }
  573. this.m_CaretVisible = true;
  574. this.m_BlinkStartTime = Time.unscaledTime;
  575. this.SetCaretActive();
  576. }
  577. private void SetCaretActive()
  578. {
  579. if (!this.m_AllowInput)
  580. {
  581. return;
  582. }
  583. if (this.m_CaretBlinkRate > 0f)
  584. {
  585. if (this.m_BlinkCoroutine == null)
  586. {
  587. this.m_BlinkCoroutine = base.StartCoroutine(this.CaretBlink());
  588. }
  589. }
  590. else
  591. {
  592. this.m_CaretVisible = true;
  593. }
  594. }
  595. private void UpdateCaretMaterial()
  596. {
  597. if (this.m_TextComponent != null && this.m_CachedInputRenderer != null)
  598. {
  599. this.m_CachedInputRenderer.SetMaterial(this.m_TextComponent.GetModifiedMaterial(Graphic.defaultGraphicMaterial), Texture2D.whiteTexture);
  600. }
  601. }
  602. protected void OnFocus()
  603. {
  604. this.SelectAll();
  605. }
  606. protected void SelectAll()
  607. {
  608. this.caretPositionInternal = this.text.Length;
  609. this.caretSelectPositionInternal = 0;
  610. }
  611. public void MoveTextEnd(bool shift)
  612. {
  613. int length = this.text.Length;
  614. if (shift)
  615. {
  616. this.caretSelectPositionInternal = length;
  617. }
  618. else
  619. {
  620. this.caretPositionInternal = length;
  621. this.caretSelectPositionInternal = this.caretPositionInternal;
  622. }
  623. this.UpdateLabel();
  624. }
  625. public void MoveTextStart(bool shift)
  626. {
  627. int num = 0;
  628. if (shift)
  629. {
  630. this.caretSelectPositionInternal = num;
  631. }
  632. else
  633. {
  634. this.caretPositionInternal = num;
  635. this.caretSelectPositionInternal = this.caretPositionInternal;
  636. }
  637. this.UpdateLabel();
  638. }
  639. private static string clipboard
  640. {
  641. get
  642. {
  643. return GUIUtility.systemCopyBuffer;
  644. }
  645. set
  646. {
  647. GUIUtility.systemCopyBuffer = value;
  648. }
  649. }
  650. private bool InPlaceEditing()
  651. {
  652. return !TouchScreenKeyboard.isSupported;
  653. }
  654. private void UpdateCaretFromKeyboard()
  655. {
  656. RangeInt selection = this.m_Keyboard.selection;
  657. int start = selection.start;
  658. int end = selection.end;
  659. bool flag = false;
  660. if (this.caretPositionInternal != start)
  661. {
  662. flag = true;
  663. this.caretPositionInternal = start;
  664. }
  665. if (this.caretSelectPositionInternal != end)
  666. {
  667. this.caretSelectPositionInternal = end;
  668. flag = true;
  669. }
  670. if (flag)
  671. {
  672. this.m_BlinkStartTime = Time.unscaledTime;
  673. this.UpdateLabel();
  674. }
  675. }
  676. protected virtual void LateUpdate()
  677. {
  678. if (this.m_ShouldActivateNextUpdate)
  679. {
  680. if (!this.isFocused)
  681. {
  682. this.ActivateuGUIInputFieldInternal();
  683. this.m_ShouldActivateNextUpdate = false;
  684. return;
  685. }
  686. this.m_ShouldActivateNextUpdate = false;
  687. }
  688. if (this.InPlaceEditing() || !this.isFocused)
  689. {
  690. return;
  691. }
  692. this.AssignPositioningIfNeeded();
  693. if (this.m_Keyboard == null || this.m_Keyboard.done)
  694. {
  695. if (this.m_Keyboard != null)
  696. {
  697. if (!this.m_ReadOnly)
  698. {
  699. this.text = this.m_Keyboard.text;
  700. }
  701. if (this.m_Keyboard.wasCanceled)
  702. {
  703. this.m_WasCanceled = true;
  704. }
  705. this.m_Text = this.m_Keyboard.text;
  706. this.SendOnValueChangedAndUpdateLabel();
  707. }
  708. this.OnDeselect(null);
  709. return;
  710. }
  711. string text = this.m_Keyboard.text;
  712. if (this.m_Text != text)
  713. {
  714. if (this.m_ReadOnly)
  715. {
  716. this.m_Keyboard.text = this.m_Text;
  717. }
  718. else
  719. {
  720. this.m_Text = string.Empty;
  721. foreach (char c in text)
  722. {
  723. if (c == '\r' || c == '\u0003')
  724. {
  725. c = '\n';
  726. }
  727. if (this.onValidateInput != null)
  728. {
  729. c = this.onValidateInput(this.m_Text, this.m_Text.Length, c);
  730. }
  731. else if (this.characterValidation != uGUIInputField.CharacterValidation.None)
  732. {
  733. c = this.Validate(this.m_Text, this.m_Text.Length, c);
  734. }
  735. if (this.lineType == uGUIInputField.LineType.MultiLineSubmit && c == '\n')
  736. {
  737. this.m_Keyboard.text = this.m_Text;
  738. this.OnDeselect(null);
  739. return;
  740. }
  741. if (c != '\0')
  742. {
  743. this.m_Text += c;
  744. }
  745. }
  746. if (this.characterLimit > 0 && this.m_Text.Length > this.characterLimit)
  747. {
  748. this.m_Text = this.m_Text.Substring(0, this.characterLimit);
  749. }
  750. if (this.m_Keyboard.canGetSelection)
  751. {
  752. this.UpdateCaretFromKeyboard();
  753. }
  754. else
  755. {
  756. int length = this.m_Text.Length;
  757. this.caretSelectPositionInternal = length;
  758. this.caretPositionInternal = length;
  759. }
  760. if (this.m_Text != text)
  761. {
  762. this.m_Keyboard.text = this.m_Text;
  763. }
  764. this.SendOnValueChangedAndUpdateLabel();
  765. }
  766. }
  767. else if (this.m_Keyboard.canGetSelection)
  768. {
  769. this.UpdateCaretFromKeyboard();
  770. }
  771. if (this.m_Keyboard.done)
  772. {
  773. if (this.m_Keyboard.wasCanceled)
  774. {
  775. this.m_WasCanceled = true;
  776. }
  777. this.OnDeselect(null);
  778. }
  779. }
  780. [Obsolete("This function is no longer used. Please use RectTransformUtility.ScreenPointToLocalPointInRectangle() instead.")]
  781. public Vector2 ScreenToLocal(Vector2 screen)
  782. {
  783. Canvas canvas = this.m_TextComponent.canvas;
  784. if (canvas == null)
  785. {
  786. return screen;
  787. }
  788. Vector3 vector = Vector3.zero;
  789. if (canvas.renderMode == RenderMode.ScreenSpaceOverlay)
  790. {
  791. vector = this.m_TextComponent.transform.InverseTransformPoint(screen);
  792. }
  793. else if (canvas.worldCamera != null)
  794. {
  795. Ray ray = canvas.worldCamera.ScreenPointToRay(screen);
  796. Plane plane = new Plane(this.m_TextComponent.transform.forward, this.m_TextComponent.transform.position);
  797. float distance;
  798. plane.Raycast(ray, out distance);
  799. vector = this.m_TextComponent.transform.InverseTransformPoint(ray.GetPoint(distance));
  800. }
  801. return new Vector2(vector.x, vector.y);
  802. }
  803. private int GetUnclampedCharacterLineFromPosition(Vector2 pos, TextGenerator generator)
  804. {
  805. if (!this.multiLine)
  806. {
  807. return 0;
  808. }
  809. float num = pos.y * this.m_TextComponent.pixelsPerUnit;
  810. float num2 = 0f;
  811. int i = 0;
  812. while (i < generator.lineCount)
  813. {
  814. float topY = generator.lines[i].topY;
  815. float num3 = topY - (float)generator.lines[i].height;
  816. if (num > topY)
  817. {
  818. float num4 = topY - num2;
  819. if (num > topY - 0.5f * num4)
  820. {
  821. return i - 1;
  822. }
  823. return i;
  824. }
  825. else
  826. {
  827. if (num > num3)
  828. {
  829. return i;
  830. }
  831. num2 = num3;
  832. i++;
  833. }
  834. }
  835. return generator.lineCount;
  836. }
  837. protected int GetCharacterIndexFromPosition(Vector2 pos)
  838. {
  839. TextGenerator cachedTextGenerator = this.m_TextComponent.cachedTextGenerator;
  840. if (cachedTextGenerator.lineCount == 0)
  841. {
  842. return 0;
  843. }
  844. int unclampedCharacterLineFromPosition = this.GetUnclampedCharacterLineFromPosition(pos, cachedTextGenerator);
  845. if (unclampedCharacterLineFromPosition < 0)
  846. {
  847. return 0;
  848. }
  849. if (unclampedCharacterLineFromPosition >= cachedTextGenerator.lineCount)
  850. {
  851. return cachedTextGenerator.characterCountVisible;
  852. }
  853. int startCharIdx = cachedTextGenerator.lines[unclampedCharacterLineFromPosition].startCharIdx;
  854. int lineEndPosition = uGUIInputField.GetLineEndPosition(cachedTextGenerator, unclampedCharacterLineFromPosition);
  855. for (int i = startCharIdx; i < lineEndPosition; i++)
  856. {
  857. if (i >= cachedTextGenerator.characterCountVisible)
  858. {
  859. break;
  860. }
  861. UICharInfo uicharInfo = cachedTextGenerator.characters[i];
  862. Vector2 vector = uicharInfo.cursorPos / this.m_TextComponent.pixelsPerUnit;
  863. float num = pos.x - vector.x;
  864. float num2 = vector.x + uicharInfo.charWidth / this.m_TextComponent.pixelsPerUnit - pos.x;
  865. if (num < num2)
  866. {
  867. return i;
  868. }
  869. }
  870. return lineEndPosition;
  871. }
  872. private bool MayDrag(PointerEventData eventData)
  873. {
  874. return this.IsActive() && this.IsInteractable() && eventData.button == PointerEventData.InputButton.Left && this.m_TextComponent != null && this.m_Keyboard == null;
  875. }
  876. public virtual void OnBeginDrag(PointerEventData eventData)
  877. {
  878. if (!this.MayDrag(eventData))
  879. {
  880. return;
  881. }
  882. this.m_UpdateDrag = true;
  883. }
  884. public virtual void OnDrag(PointerEventData eventData)
  885. {
  886. if (!this.MayDrag(eventData))
  887. {
  888. return;
  889. }
  890. Vector2 pos;
  891. RectTransformUtility.ScreenPointToLocalPointInRectangle(this.textComponent.rectTransform, eventData.position, eventData.pressEventCamera, out pos);
  892. this.caretSelectPositionInternal = this.GetCharacterIndexFromPosition(pos) + this.m_DrawStart;
  893. this.MarkGeometryAsDirty();
  894. this.m_DragPositionOutOfBounds = !RectTransformUtility.RectangleContainsScreenPoint(this.textComponent.rectTransform, eventData.position, eventData.pressEventCamera);
  895. if (this.m_DragPositionOutOfBounds && this.m_DragCoroutine == null)
  896. {
  897. this.m_DragCoroutine = base.StartCoroutine(this.MouseDragOutsideRect(eventData));
  898. }
  899. eventData.Use();
  900. }
  901. private IEnumerator MouseDragOutsideRect(PointerEventData eventData)
  902. {
  903. while (this.m_UpdateDrag && this.m_DragPositionOutOfBounds)
  904. {
  905. Vector2 localMousePos;
  906. RectTransformUtility.ScreenPointToLocalPointInRectangle(this.textComponent.rectTransform, eventData.position, eventData.pressEventCamera, out localMousePos);
  907. Rect rect = this.textComponent.rectTransform.rect;
  908. if (this.multiLine)
  909. {
  910. if (localMousePos.y > rect.yMax)
  911. {
  912. this.MoveUp(true, true);
  913. }
  914. else if (localMousePos.y < rect.yMin)
  915. {
  916. this.MoveDown(true, true);
  917. }
  918. }
  919. else if (localMousePos.x < rect.xMin)
  920. {
  921. this.MoveLeft(true, false);
  922. }
  923. else if (localMousePos.x > rect.xMax)
  924. {
  925. this.MoveRight(true, false);
  926. }
  927. this.UpdateLabel();
  928. float delay = (!this.multiLine) ? 0.05f : 0.1f;
  929. yield return new WaitForSecondsRealtime(delay);
  930. }
  931. this.m_DragCoroutine = null;
  932. yield break;
  933. }
  934. public virtual void OnEndDrag(PointerEventData eventData)
  935. {
  936. if (!this.MayDrag(eventData))
  937. {
  938. return;
  939. }
  940. this.m_UpdateDrag = false;
  941. }
  942. public override void OnPointerDown(PointerEventData eventData)
  943. {
  944. if (!this.MayDrag(eventData))
  945. {
  946. return;
  947. }
  948. EventSystem.current.SetSelectedGameObject(base.gameObject, eventData);
  949. bool allowInput = this.m_AllowInput;
  950. base.OnPointerDown(eventData);
  951. if (!this.InPlaceEditing() && (this.m_Keyboard == null || !this.m_Keyboard.active))
  952. {
  953. this.OnSelect(eventData);
  954. return;
  955. }
  956. if (allowInput)
  957. {
  958. Vector2 pos;
  959. RectTransformUtility.ScreenPointToLocalPointInRectangle(this.textComponent.rectTransform, eventData.position, eventData.pressEventCamera, out pos);
  960. int num = this.GetCharacterIndexFromPosition(pos) + this.m_DrawStart;
  961. this.caretPositionInternal = num;
  962. this.caretSelectPositionInternal = num;
  963. }
  964. this.UpdateLabel();
  965. eventData.Use();
  966. }
  967. protected uGUIInputField.EditState KeyPressed(Event evt)
  968. {
  969. EventModifiers modifiers = evt.modifiers;
  970. bool flag = (SystemInfo.operatingSystemFamily != OperatingSystemFamily.MacOSX) ? ((modifiers & EventModifiers.Control) != EventModifiers.None) : ((modifiers & EventModifiers.Command) != EventModifiers.None);
  971. bool flag2 = (modifiers & EventModifiers.Shift) != EventModifiers.None;
  972. bool flag3 = (modifiers & EventModifiers.Alt) != EventModifiers.None;
  973. bool flag4 = flag && !flag3 && !flag2;
  974. KeyCode keyCode = evt.keyCode;
  975. switch (keyCode)
  976. {
  977. case KeyCode.KeypadEnter:
  978. break;
  979. default:
  980. switch (keyCode)
  981. {
  982. case KeyCode.A:
  983. if (flag4)
  984. {
  985. this.SelectAll();
  986. return uGUIInputField.EditState.Continue;
  987. }
  988. goto IL_1E5;
  989. default:
  990. switch (keyCode)
  991. {
  992. case KeyCode.V:
  993. if (flag4)
  994. {
  995. this.Append(uGUIInputField.clipboard);
  996. return uGUIInputField.EditState.Continue;
  997. }
  998. goto IL_1E5;
  999. default:
  1000. if (keyCode == KeyCode.Backspace)
  1001. {
  1002. this.Backspace();
  1003. return uGUIInputField.EditState.Continue;
  1004. }
  1005. if (keyCode != KeyCode.Return)
  1006. {
  1007. if (keyCode == KeyCode.Escape)
  1008. {
  1009. this.m_WasCanceled = true;
  1010. return uGUIInputField.EditState.Finish;
  1011. }
  1012. if (keyCode != KeyCode.Delete)
  1013. {
  1014. goto IL_1E5;
  1015. }
  1016. this.ForwardSpace();
  1017. return uGUIInputField.EditState.Continue;
  1018. }
  1019. break;
  1020. case KeyCode.X:
  1021. if (flag4)
  1022. {
  1023. if (this.inputType != uGUIInputField.InputType.Password)
  1024. {
  1025. uGUIInputField.clipboard = this.GetSelectedString();
  1026. }
  1027. else
  1028. {
  1029. uGUIInputField.clipboard = string.Empty;
  1030. }
  1031. this.Delete();
  1032. this.SendOnValueChangedAndUpdateLabel();
  1033. return uGUIInputField.EditState.Continue;
  1034. }
  1035. goto IL_1E5;
  1036. }
  1037. break;
  1038. case KeyCode.C:
  1039. if (flag4)
  1040. {
  1041. if (this.inputType != uGUIInputField.InputType.Password)
  1042. {
  1043. uGUIInputField.clipboard = this.GetSelectedString();
  1044. }
  1045. else
  1046. {
  1047. uGUIInputField.clipboard = string.Empty;
  1048. }
  1049. return uGUIInputField.EditState.Continue;
  1050. }
  1051. goto IL_1E5;
  1052. }
  1053. break;
  1054. case KeyCode.UpArrow:
  1055. this.MoveUp(flag2);
  1056. return uGUIInputField.EditState.Continue;
  1057. case KeyCode.DownArrow:
  1058. this.MoveDown(flag2);
  1059. return uGUIInputField.EditState.Continue;
  1060. case KeyCode.RightArrow:
  1061. this.MoveRight(flag2, flag);
  1062. return uGUIInputField.EditState.Continue;
  1063. case KeyCode.LeftArrow:
  1064. this.MoveLeft(flag2, flag);
  1065. return uGUIInputField.EditState.Continue;
  1066. case KeyCode.Home:
  1067. this.MoveTextStart(flag2);
  1068. return uGUIInputField.EditState.Continue;
  1069. case KeyCode.End:
  1070. this.MoveTextEnd(flag2);
  1071. return uGUIInputField.EditState.Continue;
  1072. }
  1073. if (this.lineType != uGUIInputField.LineType.MultiLineNewline)
  1074. {
  1075. return uGUIInputField.EditState.Finish;
  1076. }
  1077. IL_1E5:
  1078. char c = evt.character;
  1079. if (!this.multiLine && (c == '\t' || c == '\r' || c == '\n'))
  1080. {
  1081. return uGUIInputField.EditState.Continue;
  1082. }
  1083. if (c == '\r' || c == '\u0003')
  1084. {
  1085. c = '\n';
  1086. }
  1087. if (this.IsValidChar(c))
  1088. {
  1089. this.Append(c);
  1090. }
  1091. if (c == '\0' && this.compositionString.Length > 0)
  1092. {
  1093. this.UpdateLabel();
  1094. }
  1095. return uGUIInputField.EditState.Continue;
  1096. }
  1097. private bool IsValidChar(char c)
  1098. {
  1099. return c != '\u007f' && (c == '\t' || c == '\n' || this.m_TextComponent.font.HasCharacter(c));
  1100. }
  1101. public void ProcessEvent(Event e)
  1102. {
  1103. this.KeyPressed(e);
  1104. }
  1105. public virtual void OnUpdateSelected(BaseEventData eventData)
  1106. {
  1107. if (!this.isFocused)
  1108. {
  1109. return;
  1110. }
  1111. bool flag = false;
  1112. while (Event.PopEvent(this.m_ProcessingEvent))
  1113. {
  1114. if (this.m_ProcessingEvent.rawType == EventType.KeyDown)
  1115. {
  1116. flag = true;
  1117. uGUIInputField.EditState editState = this.KeyPressed(this.m_ProcessingEvent);
  1118. if (editState == uGUIInputField.EditState.Finish)
  1119. {
  1120. this.DeactivateuGUIInputField();
  1121. break;
  1122. }
  1123. }
  1124. EventType type = this.m_ProcessingEvent.type;
  1125. if (type == EventType.ValidateCommand || type == EventType.ExecuteCommand)
  1126. {
  1127. string commandName = this.m_ProcessingEvent.commandName;
  1128. if (commandName != null)
  1129. {
  1130. if (commandName == "SelectAll")
  1131. {
  1132. this.SelectAll();
  1133. flag = true;
  1134. }
  1135. }
  1136. }
  1137. }
  1138. if (flag)
  1139. {
  1140. this.UpdateLabel();
  1141. }
  1142. eventData.Use();
  1143. }
  1144. private string GetSelectedString()
  1145. {
  1146. if (!this.hasSelection)
  1147. {
  1148. return string.Empty;
  1149. }
  1150. int num = this.caretPositionInternal;
  1151. int num2 = this.caretSelectPositionInternal;
  1152. if (num > num2)
  1153. {
  1154. int num3 = num;
  1155. num = num2;
  1156. num2 = num3;
  1157. }
  1158. return this.text.Substring(num, num2 - num);
  1159. }
  1160. private int FindtNextWordBegin()
  1161. {
  1162. if (this.caretSelectPositionInternal + 1 >= this.text.Length)
  1163. {
  1164. return this.text.Length;
  1165. }
  1166. int num = this.text.IndexOfAny(uGUIInputField.kSeparators, this.caretSelectPositionInternal + 1);
  1167. if (num == -1)
  1168. {
  1169. num = this.text.Length;
  1170. }
  1171. else
  1172. {
  1173. num++;
  1174. }
  1175. return num;
  1176. }
  1177. private void MoveRight(bool shift, bool ctrl)
  1178. {
  1179. if (this.hasSelection && !shift)
  1180. {
  1181. int num = Mathf.Max(this.caretPositionInternal, this.caretSelectPositionInternal);
  1182. this.caretSelectPositionInternal = num;
  1183. this.caretPositionInternal = num;
  1184. return;
  1185. }
  1186. int num2;
  1187. if (ctrl)
  1188. {
  1189. num2 = this.FindtNextWordBegin();
  1190. }
  1191. else
  1192. {
  1193. num2 = this.caretSelectPositionInternal + 1;
  1194. }
  1195. if (shift)
  1196. {
  1197. this.caretSelectPositionInternal = num2;
  1198. }
  1199. else
  1200. {
  1201. int num = num2;
  1202. this.caretPositionInternal = num;
  1203. this.caretSelectPositionInternal = num;
  1204. }
  1205. }
  1206. private int FindtPrevWordBegin()
  1207. {
  1208. if (this.caretSelectPositionInternal - 2 < 0)
  1209. {
  1210. return 0;
  1211. }
  1212. int num = this.text.LastIndexOfAny(uGUIInputField.kSeparators, this.caretSelectPositionInternal - 2);
  1213. if (num == -1)
  1214. {
  1215. num = 0;
  1216. }
  1217. else
  1218. {
  1219. num++;
  1220. }
  1221. return num;
  1222. }
  1223. private void MoveLeft(bool shift, bool ctrl)
  1224. {
  1225. if (this.hasSelection && !shift)
  1226. {
  1227. int num = Mathf.Min(this.caretPositionInternal, this.caretSelectPositionInternal);
  1228. this.caretSelectPositionInternal = num;
  1229. this.caretPositionInternal = num;
  1230. return;
  1231. }
  1232. int num2;
  1233. if (ctrl)
  1234. {
  1235. num2 = this.FindtPrevWordBegin();
  1236. }
  1237. else
  1238. {
  1239. num2 = this.caretSelectPositionInternal - 1;
  1240. }
  1241. if (shift)
  1242. {
  1243. this.caretSelectPositionInternal = num2;
  1244. }
  1245. else
  1246. {
  1247. int num = num2;
  1248. this.caretPositionInternal = num;
  1249. this.caretSelectPositionInternal = num;
  1250. }
  1251. }
  1252. private int DetermineCharacterLine(int charPos, TextGenerator generator)
  1253. {
  1254. for (int i = 0; i < generator.lineCount - 1; i++)
  1255. {
  1256. if (generator.lines[i + 1].startCharIdx > charPos)
  1257. {
  1258. return i;
  1259. }
  1260. }
  1261. return generator.lineCount - 1;
  1262. }
  1263. private int LineUpCharacterPosition(int originalPos, bool goToFirstChar)
  1264. {
  1265. if (originalPos >= this.cachedInputTextGenerator.characters.Count)
  1266. {
  1267. return 0;
  1268. }
  1269. UICharInfo uicharInfo = this.cachedInputTextGenerator.characters[originalPos];
  1270. int num = this.DetermineCharacterLine(originalPos, this.cachedInputTextGenerator);
  1271. if (num <= 0)
  1272. {
  1273. return (!goToFirstChar) ? originalPos : 0;
  1274. }
  1275. int num2 = this.cachedInputTextGenerator.lines[num].startCharIdx - 1;
  1276. for (int i = this.cachedInputTextGenerator.lines[num - 1].startCharIdx; i < num2; i++)
  1277. {
  1278. if (this.cachedInputTextGenerator.characters[i].cursorPos.x >= uicharInfo.cursorPos.x)
  1279. {
  1280. return i;
  1281. }
  1282. }
  1283. return num2;
  1284. }
  1285. private int LineDownCharacterPosition(int originalPos, bool goToLastChar)
  1286. {
  1287. if (originalPos >= this.cachedInputTextGenerator.characterCountVisible)
  1288. {
  1289. return this.text.Length;
  1290. }
  1291. UICharInfo uicharInfo = this.cachedInputTextGenerator.characters[originalPos];
  1292. int num = this.DetermineCharacterLine(originalPos, this.cachedInputTextGenerator);
  1293. if (num + 1 >= this.cachedInputTextGenerator.lineCount)
  1294. {
  1295. return (!goToLastChar) ? originalPos : this.text.Length;
  1296. }
  1297. int lineEndPosition = uGUIInputField.GetLineEndPosition(this.cachedInputTextGenerator, num + 1);
  1298. for (int i = this.cachedInputTextGenerator.lines[num + 1].startCharIdx; i < lineEndPosition; i++)
  1299. {
  1300. if (this.cachedInputTextGenerator.characters[i].cursorPos.x >= uicharInfo.cursorPos.x)
  1301. {
  1302. return i;
  1303. }
  1304. }
  1305. return lineEndPosition;
  1306. }
  1307. private void MoveDown(bool shift)
  1308. {
  1309. this.MoveDown(shift, true);
  1310. }
  1311. private void MoveDown(bool shift, bool goToLastChar)
  1312. {
  1313. if (this.hasSelection && !shift)
  1314. {
  1315. int num = Mathf.Max(this.caretPositionInternal, this.caretSelectPositionInternal);
  1316. this.caretSelectPositionInternal = num;
  1317. this.caretPositionInternal = num;
  1318. }
  1319. int num2 = (!this.multiLine) ? this.text.Length : this.LineDownCharacterPosition(this.caretSelectPositionInternal, goToLastChar);
  1320. if (shift)
  1321. {
  1322. this.caretSelectPositionInternal = num2;
  1323. }
  1324. else
  1325. {
  1326. int num = num2;
  1327. this.caretSelectPositionInternal = num;
  1328. this.caretPositionInternal = num;
  1329. }
  1330. }
  1331. private void MoveUp(bool shift)
  1332. {
  1333. this.MoveUp(shift, true);
  1334. }
  1335. private void MoveUp(bool shift, bool goToFirstChar)
  1336. {
  1337. if (this.hasSelection && !shift)
  1338. {
  1339. int num = Mathf.Min(this.caretPositionInternal, this.caretSelectPositionInternal);
  1340. this.caretSelectPositionInternal = num;
  1341. this.caretPositionInternal = num;
  1342. }
  1343. int num2 = (!this.multiLine) ? 0 : this.LineUpCharacterPosition(this.caretSelectPositionInternal, goToFirstChar);
  1344. if (shift)
  1345. {
  1346. this.caretSelectPositionInternal = num2;
  1347. }
  1348. else
  1349. {
  1350. int num = num2;
  1351. this.caretPositionInternal = num;
  1352. this.caretSelectPositionInternal = num;
  1353. }
  1354. }
  1355. private void Delete()
  1356. {
  1357. if (this.m_ReadOnly)
  1358. {
  1359. return;
  1360. }
  1361. if (this.caretPositionInternal == this.caretSelectPositionInternal)
  1362. {
  1363. return;
  1364. }
  1365. if (this.caretPositionInternal < this.caretSelectPositionInternal)
  1366. {
  1367. this.m_Text = this.text.Substring(0, this.caretPositionInternal) + this.text.Substring(this.caretSelectPositionInternal, this.text.Length - this.caretSelectPositionInternal);
  1368. this.caretSelectPositionInternal = this.caretPositionInternal;
  1369. }
  1370. else
  1371. {
  1372. this.m_Text = this.text.Substring(0, this.caretSelectPositionInternal) + this.text.Substring(this.caretPositionInternal, this.text.Length - this.caretPositionInternal);
  1373. this.caretPositionInternal = this.caretSelectPositionInternal;
  1374. }
  1375. }
  1376. private void ForwardSpace()
  1377. {
  1378. if (this.m_ReadOnly)
  1379. {
  1380. return;
  1381. }
  1382. if (this.hasSelection)
  1383. {
  1384. this.Delete();
  1385. this.SendOnValueChangedAndUpdateLabel();
  1386. }
  1387. else if (this.caretPositionInternal < this.text.Length)
  1388. {
  1389. this.m_Text = this.text.Remove(this.caretPositionInternal, 1);
  1390. this.SendOnValueChangedAndUpdateLabel();
  1391. }
  1392. }
  1393. private void Backspace()
  1394. {
  1395. if (this.m_ReadOnly)
  1396. {
  1397. return;
  1398. }
  1399. if (this.hasSelection)
  1400. {
  1401. this.Delete();
  1402. this.SendOnValueChangedAndUpdateLabel();
  1403. }
  1404. else if (this.caretPositionInternal > 0)
  1405. {
  1406. this.m_Text = this.text.Remove(this.caretPositionInternal - 1, 1);
  1407. int num = this.caretPositionInternal - 1;
  1408. this.caretPositionInternal = num;
  1409. this.caretSelectPositionInternal = num;
  1410. this.SendOnValueChangedAndUpdateLabel();
  1411. }
  1412. }
  1413. private void Insert(char c)
  1414. {
  1415. if (this.m_ReadOnly)
  1416. {
  1417. return;
  1418. }
  1419. string text = c.ToString();
  1420. this.Delete();
  1421. if (this.characterLimit > 0 && this.text.Length >= this.characterLimit)
  1422. {
  1423. return;
  1424. }
  1425. this.m_Text = this.text.Insert(this.m_CaretPosition, text);
  1426. this.caretSelectPositionInternal = (this.caretPositionInternal += text.Length);
  1427. this.SendOnValueChanged();
  1428. }
  1429. private void SendOnValueChangedAndUpdateLabel()
  1430. {
  1431. this.SendOnValueChanged();
  1432. this.UpdateLabel();
  1433. }
  1434. private void SendOnValueChanged()
  1435. {
  1436. if (this.onValueChanged != null)
  1437. {
  1438. this.onValueChanged.Invoke(this.text);
  1439. }
  1440. }
  1441. protected void SendOnSubmit()
  1442. {
  1443. if (this.onEndEdit != null)
  1444. {
  1445. this.onEndEdit.Invoke(this.m_Text);
  1446. }
  1447. }
  1448. protected virtual void Append(string input)
  1449. {
  1450. if (this.m_ReadOnly)
  1451. {
  1452. return;
  1453. }
  1454. if (!this.InPlaceEditing())
  1455. {
  1456. return;
  1457. }
  1458. int i = 0;
  1459. int length = input.Length;
  1460. while (i < length)
  1461. {
  1462. char c = input[i];
  1463. if (c >= ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\n')
  1464. {
  1465. this.Append(c);
  1466. }
  1467. i++;
  1468. }
  1469. }
  1470. protected virtual void Append(char input)
  1471. {
  1472. if (this.m_ReadOnly)
  1473. {
  1474. return;
  1475. }
  1476. if (!this.InPlaceEditing())
  1477. {
  1478. return;
  1479. }
  1480. int num = Math.Min(this.selectionFocusPosition, this.selectionAnchorPosition);
  1481. if (this.onValidateInput != null)
  1482. {
  1483. input = this.onValidateInput(this.text, num, input);
  1484. }
  1485. else if (this.characterValidation != uGUIInputField.CharacterValidation.None)
  1486. {
  1487. input = this.Validate(this.text, num, input);
  1488. }
  1489. if (input == '\0')
  1490. {
  1491. return;
  1492. }
  1493. this.Insert(input);
  1494. }
  1495. protected void UpdateLabel()
  1496. {
  1497. if (this.m_TextComponent != null && this.m_TextComponent.font != null && !this.m_PreventFontCallback)
  1498. {
  1499. this.m_PreventFontCallback = true;
  1500. string text;
  1501. if (this.compositionString.Length > 0)
  1502. {
  1503. text = this.text.Substring(0, this.m_CaretPosition) + this.compositionString + this.text.Substring(this.m_CaretPosition);
  1504. }
  1505. else
  1506. {
  1507. text = this.text;
  1508. }
  1509. string text2;
  1510. if (this.inputType == uGUIInputField.InputType.Password)
  1511. {
  1512. text2 = new string(this.asteriskChar, text.Length);
  1513. }
  1514. else
  1515. {
  1516. text2 = text;
  1517. }
  1518. bool flag = string.IsNullOrEmpty(text);
  1519. if (this.m_Placeholder != null)
  1520. {
  1521. this.m_Placeholder.enabled = flag;
  1522. }
  1523. if (!this.m_AllowInput)
  1524. {
  1525. this.m_DrawStart = 0;
  1526. this.m_DrawEnd = this.m_Text.Length;
  1527. }
  1528. if (!flag)
  1529. {
  1530. Vector2 size = this.m_TextComponent.rectTransform.rect.size;
  1531. TextGenerationSettings generationSettings = this.m_TextComponent.GetGenerationSettings(size);
  1532. generationSettings.generateOutOfBounds = true;
  1533. this.cachedInputTextGenerator.PopulateWithErrors(text2, generationSettings, base.gameObject);
  1534. this.SetDrawRangeToContainCaretPosition(this.caretSelectPositionInternal);
  1535. text2 = text2.Substring(this.m_DrawStart, Mathf.Min(this.m_DrawEnd, text2.Length) - this.m_DrawStart);
  1536. this.SetCaretVisible();
  1537. }
  1538. this.m_TextComponent.text = text2;
  1539. this.MarkGeometryAsDirty();
  1540. this.m_PreventFontCallback = false;
  1541. }
  1542. }
  1543. private bool IsSelectionVisible()
  1544. {
  1545. return this.m_DrawStart <= this.caretPositionInternal && this.m_DrawStart <= this.caretSelectPositionInternal && this.m_DrawEnd >= this.caretPositionInternal && this.m_DrawEnd >= this.caretSelectPositionInternal;
  1546. }
  1547. private static int GetLineStartPosition(TextGenerator gen, int line)
  1548. {
  1549. line = Mathf.Clamp(line, 0, gen.lines.Count - 1);
  1550. return gen.lines[line].startCharIdx;
  1551. }
  1552. private static int GetLineEndPosition(TextGenerator gen, int line)
  1553. {
  1554. line = Mathf.Max(line, 0);
  1555. if (line + 1 < gen.lines.Count)
  1556. {
  1557. return gen.lines[line + 1].startCharIdx - 1;
  1558. }
  1559. return gen.characterCountVisible;
  1560. }
  1561. private void SetDrawRangeToContainCaretPosition(int caretPos)
  1562. {
  1563. if (this.cachedInputTextGenerator.lineCount <= 0)
  1564. {
  1565. return;
  1566. }
  1567. Vector2 size = this.cachedInputTextGenerator.rectExtents.size;
  1568. if (this.multiLine)
  1569. {
  1570. IList<UILineInfo> lines = this.cachedInputTextGenerator.lines;
  1571. int num = this.DetermineCharacterLine(caretPos, this.cachedInputTextGenerator);
  1572. if (caretPos > this.m_DrawEnd)
  1573. {
  1574. this.m_DrawEnd = uGUIInputField.GetLineEndPosition(this.cachedInputTextGenerator, num);
  1575. float num2 = lines[num].topY - (float)lines[num].height;
  1576. if (num == lines.Count - 1)
  1577. {
  1578. num2 += lines[num].leading;
  1579. }
  1580. int i;
  1581. for (i = num; i > 0; i--)
  1582. {
  1583. float topY = lines[i - 1].topY;
  1584. if (topY - num2 > size.y)
  1585. {
  1586. break;
  1587. }
  1588. }
  1589. this.m_DrawStart = uGUIInputField.GetLineStartPosition(this.cachedInputTextGenerator, i);
  1590. }
  1591. else
  1592. {
  1593. if (caretPos < this.m_DrawStart)
  1594. {
  1595. this.m_DrawStart = uGUIInputField.GetLineStartPosition(this.cachedInputTextGenerator, num);
  1596. }
  1597. int j = this.DetermineCharacterLine(this.m_DrawStart, this.cachedInputTextGenerator);
  1598. int k = j;
  1599. float topY2 = lines[j].topY;
  1600. float num3 = lines[k].topY - (float)lines[k].height;
  1601. if (k == lines.Count - 1)
  1602. {
  1603. num3 += lines[k].leading;
  1604. }
  1605. while (k < lines.Count - 1)
  1606. {
  1607. num3 = lines[k + 1].topY - (float)lines[k + 1].height;
  1608. if (k + 1 == lines.Count - 1)
  1609. {
  1610. num3 += lines[k + 1].leading;
  1611. }
  1612. if (topY2 - num3 > size.y)
  1613. {
  1614. break;
  1615. }
  1616. k++;
  1617. }
  1618. this.m_DrawEnd = uGUIInputField.GetLineEndPosition(this.cachedInputTextGenerator, k);
  1619. while (j > 0)
  1620. {
  1621. topY2 = lines[j - 1].topY;
  1622. if (topY2 - num3 > size.y)
  1623. {
  1624. break;
  1625. }
  1626. j--;
  1627. }
  1628. this.m_DrawStart = uGUIInputField.GetLineStartPosition(this.cachedInputTextGenerator, j);
  1629. }
  1630. }
  1631. else
  1632. {
  1633. IList<UICharInfo> characters = this.cachedInputTextGenerator.characters;
  1634. if (this.m_DrawEnd > this.cachedInputTextGenerator.characterCountVisible)
  1635. {
  1636. this.m_DrawEnd = this.cachedInputTextGenerator.characterCountVisible;
  1637. }
  1638. float num4 = 0f;
  1639. if (caretPos > this.m_DrawEnd || (caretPos == this.m_DrawEnd && this.m_DrawStart > 0))
  1640. {
  1641. this.m_DrawEnd = caretPos;
  1642. this.m_DrawStart = this.m_DrawEnd - 1;
  1643. while (this.m_DrawStart >= 0)
  1644. {
  1645. if (num4 + characters[this.m_DrawStart].charWidth > size.x)
  1646. {
  1647. break;
  1648. }
  1649. num4 += characters[this.m_DrawStart].charWidth;
  1650. this.m_DrawStart--;
  1651. }
  1652. this.m_DrawStart++;
  1653. }
  1654. else
  1655. {
  1656. if (caretPos < this.m_DrawStart)
  1657. {
  1658. this.m_DrawStart = caretPos;
  1659. }
  1660. this.m_DrawEnd = this.m_DrawStart;
  1661. }
  1662. while (this.m_DrawEnd < this.cachedInputTextGenerator.characterCountVisible)
  1663. {
  1664. num4 += characters[this.m_DrawEnd].charWidth;
  1665. if (num4 > size.x)
  1666. {
  1667. break;
  1668. }
  1669. this.m_DrawEnd++;
  1670. }
  1671. }
  1672. }
  1673. public void ForceLabelUpdate()
  1674. {
  1675. this.UpdateLabel();
  1676. }
  1677. private void MarkGeometryAsDirty()
  1678. {
  1679. CanvasUpdateRegistry.RegisterCanvasElementForGraphicRebuild(this);
  1680. }
  1681. public virtual void Rebuild(CanvasUpdate update)
  1682. {
  1683. if (update == CanvasUpdate.LatePreRender)
  1684. {
  1685. this.UpdateGeometry();
  1686. }
  1687. }
  1688. public virtual void LayoutComplete()
  1689. {
  1690. }
  1691. public virtual void GraphicUpdateComplete()
  1692. {
  1693. }
  1694. private void UpdateGeometry()
  1695. {
  1696. if (!this.shouldHideMobileInput)
  1697. {
  1698. return;
  1699. }
  1700. if (this.m_CachedInputRenderer == null && this.m_TextComponent != null)
  1701. {
  1702. GameObject gameObject = new GameObject(base.transform.name + " Input Caret", new Type[]
  1703. {
  1704. typeof(RectTransform),
  1705. typeof(CanvasRenderer)
  1706. });
  1707. gameObject.hideFlags = HideFlags.DontSave;
  1708. gameObject.transform.SetParent(this.m_TextComponent.transform.parent);
  1709. gameObject.transform.SetAsFirstSibling();
  1710. gameObject.layer = base.gameObject.layer;
  1711. this.caretRectTrans = gameObject.GetComponent<RectTransform>();
  1712. this.m_CachedInputRenderer = gameObject.GetComponent<CanvasRenderer>();
  1713. this.m_CachedInputRenderer.SetMaterial(this.m_TextComponent.GetModifiedMaterial(Graphic.defaultGraphicMaterial), Texture2D.whiteTexture);
  1714. gameObject.AddComponent<LayoutElement>().ignoreLayout = true;
  1715. this.AssignPositioningIfNeeded();
  1716. }
  1717. if (this.m_CachedInputRenderer == null)
  1718. {
  1719. return;
  1720. }
  1721. this.OnFillVBO(this.mesh);
  1722. this.m_CachedInputRenderer.SetMesh(this.mesh);
  1723. }
  1724. private void AssignPositioningIfNeeded()
  1725. {
  1726. 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))
  1727. {
  1728. this.caretRectTrans.localPosition = this.m_TextComponent.rectTransform.localPosition;
  1729. this.caretRectTrans.localRotation = this.m_TextComponent.rectTransform.localRotation;
  1730. this.caretRectTrans.localScale = this.m_TextComponent.rectTransform.localScale;
  1731. this.caretRectTrans.anchorMin = this.m_TextComponent.rectTransform.anchorMin;
  1732. this.caretRectTrans.anchorMax = this.m_TextComponent.rectTransform.anchorMax;
  1733. this.caretRectTrans.anchoredPosition = this.m_TextComponent.rectTransform.anchoredPosition;
  1734. this.caretRectTrans.sizeDelta = this.m_TextComponent.rectTransform.sizeDelta;
  1735. this.caretRectTrans.pivot = this.m_TextComponent.rectTransform.pivot;
  1736. }
  1737. }
  1738. private void OnFillVBO(Mesh vbo)
  1739. {
  1740. using (VertexHelper vertexHelper = new VertexHelper())
  1741. {
  1742. if (!this.isFocused)
  1743. {
  1744. vertexHelper.FillMesh(vbo);
  1745. }
  1746. else
  1747. {
  1748. Vector2 roundingOffset = this.m_TextComponent.PixelAdjustPoint(Vector2.zero);
  1749. if (!this.hasSelection)
  1750. {
  1751. this.GenerateCaret(vertexHelper, roundingOffset);
  1752. }
  1753. else
  1754. {
  1755. this.GenerateHightlight(vertexHelper, roundingOffset);
  1756. }
  1757. vertexHelper.FillMesh(vbo);
  1758. }
  1759. }
  1760. }
  1761. private void GenerateCaret(VertexHelper vbo, Vector2 roundingOffset)
  1762. {
  1763. if (!this.m_CaretVisible)
  1764. {
  1765. return;
  1766. }
  1767. if (this.m_CursorVerts == null)
  1768. {
  1769. this.CreateCursorVerts();
  1770. }
  1771. float num = (float)this.m_CaretWidth;
  1772. int num2 = Mathf.Max(0, this.caretPositionInternal - this.m_DrawStart);
  1773. TextGenerator cachedTextGenerator = this.m_TextComponent.cachedTextGenerator;
  1774. if (cachedTextGenerator == null)
  1775. {
  1776. return;
  1777. }
  1778. if (cachedTextGenerator.lineCount == 0)
  1779. {
  1780. return;
  1781. }
  1782. Vector2 vector = Vector2.zero;
  1783. if (num2 < cachedTextGenerator.characters.Count)
  1784. {
  1785. vector.x = cachedTextGenerator.characters[num2].cursorPos.x;
  1786. }
  1787. vector.x /= this.m_TextComponent.pixelsPerUnit;
  1788. if (vector.x > this.m_TextComponent.rectTransform.rect.xMax)
  1789. {
  1790. vector.x = this.m_TextComponent.rectTransform.rect.xMax;
  1791. }
  1792. int index = this.DetermineCharacterLine(num2, cachedTextGenerator);
  1793. vector.y = cachedTextGenerator.lines[index].topY / this.m_TextComponent.pixelsPerUnit;
  1794. float num3 = (float)cachedTextGenerator.lines[index].height / this.m_TextComponent.pixelsPerUnit;
  1795. for (int i = 0; i < this.m_CursorVerts.Length; i++)
  1796. {
  1797. this.m_CursorVerts[i].color = this.caretColor;
  1798. }
  1799. vector += this.m_FixCaretPos;
  1800. this.m_CursorVerts[0].position = new Vector3(vector.x, vector.y - num3, 0f);
  1801. this.m_CursorVerts[1].position = new Vector3(vector.x + num, vector.y - num3, 0f);
  1802. this.m_CursorVerts[2].position = new Vector3(vector.x + num, vector.y, 0f);
  1803. this.m_CursorVerts[3].position = new Vector3(vector.x, vector.y, 0f);
  1804. if (roundingOffset != Vector2.zero)
  1805. {
  1806. for (int j = 0; j < this.m_CursorVerts.Length; j++)
  1807. {
  1808. UIVertex uivertex = this.m_CursorVerts[j];
  1809. uivertex.position.x = uivertex.position.x + roundingOffset.x;
  1810. uivertex.position.y = uivertex.position.y + roundingOffset.y;
  1811. }
  1812. }
  1813. vbo.AddUIVertexQuad(this.m_CursorVerts);
  1814. int num4 = Screen.height;
  1815. int targetDisplay = this.m_TextComponent.canvas.targetDisplay;
  1816. if (targetDisplay > 0 && targetDisplay < Display.displays.Length)
  1817. {
  1818. num4 = Display.displays[targetDisplay].renderingHeight;
  1819. }
  1820. vector.y = (float)num4 - vector.y;
  1821. this.input.compositionCursorPos = vector;
  1822. }
  1823. private void CreateCursorVerts()
  1824. {
  1825. this.m_CursorVerts = new UIVertex[4];
  1826. for (int i = 0; i < this.m_CursorVerts.Length; i++)
  1827. {
  1828. this.m_CursorVerts[i] = UIVertex.simpleVert;
  1829. this.m_CursorVerts[i].uv0 = Vector2.zero;
  1830. }
  1831. }
  1832. private void GenerateHightlight(VertexHelper vbo, Vector2 roundingOffset)
  1833. {
  1834. int num = Mathf.Max(0, this.caretPositionInternal - this.m_DrawStart);
  1835. int num2 = Mathf.Max(0, this.caretSelectPositionInternal - this.m_DrawStart);
  1836. if (num > num2)
  1837. {
  1838. int num3 = num;
  1839. num = num2;
  1840. num2 = num3;
  1841. }
  1842. num2--;
  1843. TextGenerator cachedTextGenerator = this.m_TextComponent.cachedTextGenerator;
  1844. if (cachedTextGenerator.lineCount <= 0)
  1845. {
  1846. return;
  1847. }
  1848. int num4 = this.DetermineCharacterLine(num, cachedTextGenerator);
  1849. int lineEndPosition = uGUIInputField.GetLineEndPosition(cachedTextGenerator, num4);
  1850. UIVertex simpleVert = UIVertex.simpleVert;
  1851. simpleVert.uv0 = Vector2.zero;
  1852. simpleVert.color = this.selectionColor;
  1853. int num5 = num;
  1854. while (num5 <= num2 && num5 < cachedTextGenerator.characterCount)
  1855. {
  1856. if (num5 == lineEndPosition || num5 == num2)
  1857. {
  1858. UICharInfo uicharInfo = cachedTextGenerator.characters[num];
  1859. UICharInfo uicharInfo2 = cachedTextGenerator.characters[num5];
  1860. Vector2 a = new Vector2(uicharInfo.cursorPos.x / this.m_TextComponent.pixelsPerUnit, cachedTextGenerator.lines[num4].topY / this.m_TextComponent.pixelsPerUnit);
  1861. Vector2 a2 = new Vector2((uicharInfo2.cursorPos.x + uicharInfo2.charWidth) / this.m_TextComponent.pixelsPerUnit, a.y - (float)cachedTextGenerator.lines[num4].height / this.m_TextComponent.pixelsPerUnit);
  1862. if (a2.x > this.m_TextComponent.rectTransform.rect.xMax || a2.x < this.m_TextComponent.rectTransform.rect.xMin)
  1863. {
  1864. a2.x = this.m_TextComponent.rectTransform.rect.xMax;
  1865. }
  1866. a += this.m_FixCaretPos;
  1867. a2 += this.m_FixCaretPos;
  1868. int currentVertCount = vbo.currentVertCount;
  1869. simpleVert.position = new Vector3(a.x, a2.y, 0f) + roundingOffset;
  1870. vbo.AddVert(simpleVert);
  1871. simpleVert.position = new Vector3(a2.x, a2.y, 0f) + roundingOffset;
  1872. vbo.AddVert(simpleVert);
  1873. simpleVert.position = new Vector3(a2.x, a.y, 0f) + roundingOffset;
  1874. vbo.AddVert(simpleVert);
  1875. simpleVert.position = new Vector3(a.x, a.y, 0f) + roundingOffset;
  1876. vbo.AddVert(simpleVert);
  1877. vbo.AddTriangle(currentVertCount, currentVertCount + 1, currentVertCount + 2);
  1878. vbo.AddTriangle(currentVertCount + 2, currentVertCount + 3, currentVertCount);
  1879. num = num5 + 1;
  1880. num4++;
  1881. lineEndPosition = uGUIInputField.GetLineEndPosition(cachedTextGenerator, num4);
  1882. }
  1883. num5++;
  1884. }
  1885. }
  1886. protected char Validate(string text, int pos, char ch)
  1887. {
  1888. if (this.characterValidation == uGUIInputField.CharacterValidation.None || !base.enabled)
  1889. {
  1890. return ch;
  1891. }
  1892. if (this.characterValidation == uGUIInputField.CharacterValidation.Integer || this.characterValidation == uGUIInputField.CharacterValidation.Decimal)
  1893. {
  1894. bool flag = pos == 0 && text.Length > 0 && text[0] == '-';
  1895. bool flag2 = this.caretPositionInternal == 0 || this.caretSelectPositionInternal == 0;
  1896. if (!flag)
  1897. {
  1898. if (ch >= '0' && ch <= '9')
  1899. {
  1900. return ch;
  1901. }
  1902. if (ch == '-' && (pos == 0 || flag2))
  1903. {
  1904. return ch;
  1905. }
  1906. if (ch == '.' && this.characterValidation == uGUIInputField.CharacterValidation.Decimal && !text.Contains("."))
  1907. {
  1908. return ch;
  1909. }
  1910. }
  1911. }
  1912. else if (this.characterValidation == uGUIInputField.CharacterValidation.Alphanumeric)
  1913. {
  1914. if (ch >= 'A' && ch <= 'Z')
  1915. {
  1916. return ch;
  1917. }
  1918. if (ch >= 'a' && ch <= 'z')
  1919. {
  1920. return ch;
  1921. }
  1922. if (ch >= '0' && ch <= '9')
  1923. {
  1924. return ch;
  1925. }
  1926. }
  1927. else if (this.characterValidation == uGUIInputField.CharacterValidation.Name)
  1928. {
  1929. if (char.IsLetter(ch))
  1930. {
  1931. if (char.IsLower(ch) && (pos == 0 || text[pos - 1] == ' '))
  1932. {
  1933. return char.ToUpper(ch);
  1934. }
  1935. if (char.IsUpper(ch) && pos > 0 && text[pos - 1] != ' ' && text[pos - 1] != '\'')
  1936. {
  1937. return char.ToLower(ch);
  1938. }
  1939. return ch;
  1940. }
  1941. else
  1942. {
  1943. if (ch == '\'' && !text.Contains("'") && (pos <= 0 || (text[pos - 1] != ' ' && text[pos - 1] != '\'')) && (pos >= text.Length || (text[pos] != ' ' && text[pos] != '\'')))
  1944. {
  1945. return ch;
  1946. }
  1947. if (ch == ' ' && (pos <= 0 || (text[pos - 1] != ' ' && text[pos - 1] != '\'')) && (pos >= text.Length || (text[pos] != ' ' && text[pos] != '\'')))
  1948. {
  1949. return ch;
  1950. }
  1951. }
  1952. }
  1953. else if (this.characterValidation == uGUIInputField.CharacterValidation.EmailAddress)
  1954. {
  1955. if (ch >= 'A' && ch <= 'Z')
  1956. {
  1957. return ch;
  1958. }
  1959. if (ch >= 'a' && ch <= 'z')
  1960. {
  1961. return ch;
  1962. }
  1963. if (ch >= '0' && ch <= '9')
  1964. {
  1965. return ch;
  1966. }
  1967. if (ch == '@' && text.IndexOf('@') == -1)
  1968. {
  1969. return ch;
  1970. }
  1971. if ("!#$%&'*+-/=?^_`{|}~".IndexOf(ch) != -1)
  1972. {
  1973. return ch;
  1974. }
  1975. if (ch == '.')
  1976. {
  1977. char c = (text.Length <= 0) ? ' ' : text[Mathf.Clamp(pos, 0, text.Length - 1)];
  1978. char c2 = (text.Length <= 0) ? '\n' : text[Mathf.Clamp(pos + 1, 0, text.Length - 1)];
  1979. if (c != '.' && c2 != '.')
  1980. {
  1981. return ch;
  1982. }
  1983. }
  1984. }
  1985. return '\0';
  1986. }
  1987. public void ActivateuGUIInputField()
  1988. {
  1989. if (this.m_TextComponent == null || this.m_TextComponent.font == null || !this.IsActive() || !this.IsInteractable())
  1990. {
  1991. return;
  1992. }
  1993. if (this.isFocused && this.m_Keyboard != null && !this.m_Keyboard.active)
  1994. {
  1995. this.m_Keyboard.active = true;
  1996. this.m_Keyboard.text = this.m_Text;
  1997. }
  1998. this.m_ShouldActivateNextUpdate = true;
  1999. }
  2000. private void ActivateuGUIInputFieldInternal()
  2001. {
  2002. if (EventSystem.current == null)
  2003. {
  2004. return;
  2005. }
  2006. if (EventSystem.current.currentSelectedGameObject != base.gameObject)
  2007. {
  2008. EventSystem.current.SetSelectedGameObject(base.gameObject);
  2009. }
  2010. if (TouchScreenKeyboard.isSupported)
  2011. {
  2012. if (this.input.touchSupported)
  2013. {
  2014. TouchScreenKeyboard.hideInput = this.shouldHideMobileInput;
  2015. }
  2016. 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));
  2017. this.MoveTextEnd(false);
  2018. }
  2019. else
  2020. {
  2021. this.input.imeCompositionMode = IMECompositionMode.On;
  2022. this.OnFocus();
  2023. }
  2024. this.m_AllowInput = true;
  2025. this.m_OriginalText = this.text;
  2026. this.m_WasCanceled = false;
  2027. this.SetCaretVisible();
  2028. this.UpdateLabel();
  2029. }
  2030. public override void OnSelect(BaseEventData eventData)
  2031. {
  2032. base.OnSelect(eventData);
  2033. if (this.shouldActivateOnSelect)
  2034. {
  2035. this.ActivateuGUIInputField();
  2036. }
  2037. }
  2038. public virtual void OnPointerClick(PointerEventData eventData)
  2039. {
  2040. if (eventData.button != PointerEventData.InputButton.Left)
  2041. {
  2042. return;
  2043. }
  2044. this.ActivateuGUIInputField();
  2045. }
  2046. public void DeactivateuGUIInputField()
  2047. {
  2048. if (!this.m_AllowInput)
  2049. {
  2050. return;
  2051. }
  2052. this.m_HasDoneFocusTransition = false;
  2053. this.m_AllowInput = false;
  2054. if (this.m_Placeholder != null)
  2055. {
  2056. this.m_Placeholder.enabled = string.IsNullOrEmpty(this.m_Text);
  2057. }
  2058. if (this.m_TextComponent != null && this.IsInteractable())
  2059. {
  2060. if (this.m_WasCanceled)
  2061. {
  2062. this.text = this.m_OriginalText;
  2063. }
  2064. if (this.m_Keyboard != null)
  2065. {
  2066. this.m_Keyboard.active = false;
  2067. this.m_Keyboard = null;
  2068. }
  2069. this.m_CaretPosition = (this.m_CaretSelectPosition = 0);
  2070. this.SendOnSubmit();
  2071. this.input.imeCompositionMode = IMECompositionMode.Auto;
  2072. }
  2073. this.MarkGeometryAsDirty();
  2074. }
  2075. public override void OnDeselect(BaseEventData eventData)
  2076. {
  2077. this.DeactivateuGUIInputField();
  2078. base.OnDeselect(eventData);
  2079. }
  2080. public virtual void OnSubmit(BaseEventData eventData)
  2081. {
  2082. if (!this.IsActive() || !this.IsInteractable())
  2083. {
  2084. return;
  2085. }
  2086. if (!this.isFocused)
  2087. {
  2088. this.m_ShouldActivateNextUpdate = true;
  2089. }
  2090. }
  2091. private void EnforceContentType()
  2092. {
  2093. switch (this.contentType)
  2094. {
  2095. case uGUIInputField.ContentType.Standard:
  2096. this.m_InputType = uGUIInputField.InputType.Standard;
  2097. this.m_KeyboardType = TouchScreenKeyboardType.Default;
  2098. this.m_CharacterValidation = uGUIInputField.CharacterValidation.None;
  2099. break;
  2100. case uGUIInputField.ContentType.Autocorrected:
  2101. this.m_InputType = uGUIInputField.InputType.AutoCorrect;
  2102. this.m_KeyboardType = TouchScreenKeyboardType.Default;
  2103. this.m_CharacterValidation = uGUIInputField.CharacterValidation.None;
  2104. break;
  2105. case uGUIInputField.ContentType.IntegerNumber:
  2106. this.m_LineType = uGUIInputField.LineType.SingleLine;
  2107. this.m_InputType = uGUIInputField.InputType.Standard;
  2108. this.m_KeyboardType = TouchScreenKeyboardType.NumberPad;
  2109. this.m_CharacterValidation = uGUIInputField.CharacterValidation.Integer;
  2110. break;
  2111. case uGUIInputField.ContentType.DecimalNumber:
  2112. this.m_LineType = uGUIInputField.LineType.SingleLine;
  2113. this.m_InputType = uGUIInputField.InputType.Standard;
  2114. this.m_KeyboardType = TouchScreenKeyboardType.NumbersAndPunctuation;
  2115. this.m_CharacterValidation = uGUIInputField.CharacterValidation.Decimal;
  2116. break;
  2117. case uGUIInputField.ContentType.Alphanumeric:
  2118. this.m_LineType = uGUIInputField.LineType.SingleLine;
  2119. this.m_InputType = uGUIInputField.InputType.Standard;
  2120. this.m_KeyboardType = TouchScreenKeyboardType.ASCIICapable;
  2121. this.m_CharacterValidation = uGUIInputField.CharacterValidation.Alphanumeric;
  2122. break;
  2123. case uGUIInputField.ContentType.Name:
  2124. this.m_LineType = uGUIInputField.LineType.SingleLine;
  2125. this.m_InputType = uGUIInputField.InputType.Standard;
  2126. this.m_KeyboardType = TouchScreenKeyboardType.Default;
  2127. this.m_CharacterValidation = uGUIInputField.CharacterValidation.Name;
  2128. break;
  2129. case uGUIInputField.ContentType.EmailAddress:
  2130. this.m_LineType = uGUIInputField.LineType.SingleLine;
  2131. this.m_InputType = uGUIInputField.InputType.Standard;
  2132. this.m_KeyboardType = TouchScreenKeyboardType.EmailAddress;
  2133. this.m_CharacterValidation = uGUIInputField.CharacterValidation.EmailAddress;
  2134. break;
  2135. case uGUIInputField.ContentType.Password:
  2136. this.m_LineType = uGUIInputField.LineType.SingleLine;
  2137. this.m_InputType = uGUIInputField.InputType.Password;
  2138. this.m_KeyboardType = TouchScreenKeyboardType.Default;
  2139. this.m_CharacterValidation = uGUIInputField.CharacterValidation.None;
  2140. break;
  2141. case uGUIInputField.ContentType.Pin:
  2142. this.m_LineType = uGUIInputField.LineType.SingleLine;
  2143. this.m_InputType = uGUIInputField.InputType.Password;
  2144. this.m_KeyboardType = TouchScreenKeyboardType.NumberPad;
  2145. this.m_CharacterValidation = uGUIInputField.CharacterValidation.Integer;
  2146. break;
  2147. }
  2148. this.EnforceTextHOverflow();
  2149. }
  2150. private void EnforceTextHOverflow()
  2151. {
  2152. if (this.m_TextComponent != null)
  2153. {
  2154. if (this.multiLine)
  2155. {
  2156. this.m_TextComponent.horizontalOverflow = HorizontalWrapMode.Wrap;
  2157. }
  2158. else
  2159. {
  2160. this.m_TextComponent.horizontalOverflow = HorizontalWrapMode.Overflow;
  2161. }
  2162. }
  2163. }
  2164. private void SetToCustomIfContentTypeIsNot(params uGUIInputField.ContentType[] allowedContentTypes)
  2165. {
  2166. if (this.contentType == uGUIInputField.ContentType.Custom)
  2167. {
  2168. return;
  2169. }
  2170. for (int i = 0; i < allowedContentTypes.Length; i++)
  2171. {
  2172. if (this.contentType == allowedContentTypes[i])
  2173. {
  2174. return;
  2175. }
  2176. }
  2177. this.contentType = uGUIInputField.ContentType.Custom;
  2178. }
  2179. private void SetToCustom()
  2180. {
  2181. if (this.contentType == uGUIInputField.ContentType.Custom)
  2182. {
  2183. return;
  2184. }
  2185. this.contentType = uGUIInputField.ContentType.Custom;
  2186. }
  2187. protected override void DoStateTransition(Selectable.SelectionState state, bool instant)
  2188. {
  2189. if (this.m_HasDoneFocusTransition)
  2190. {
  2191. state = Selectable.SelectionState.Highlighted;
  2192. }
  2193. else if (state == Selectable.SelectionState.Pressed)
  2194. {
  2195. this.m_HasDoneFocusTransition = true;
  2196. }
  2197. base.DoStateTransition(state, instant);
  2198. }
  2199. public virtual void CalculateLayoutInputHorizontal()
  2200. {
  2201. }
  2202. public virtual void CalculateLayoutInputVertical()
  2203. {
  2204. }
  2205. public virtual float minWidth
  2206. {
  2207. get
  2208. {
  2209. return 0f;
  2210. }
  2211. }
  2212. public virtual float preferredWidth
  2213. {
  2214. get
  2215. {
  2216. if (this.textComponent == null)
  2217. {
  2218. return 0f;
  2219. }
  2220. TextGenerationSettings generationSettings = this.textComponent.GetGenerationSettings(Vector2.zero);
  2221. return this.textComponent.cachedTextGeneratorForLayout.GetPreferredWidth(this.m_Text, generationSettings) / this.textComponent.pixelsPerUnit;
  2222. }
  2223. }
  2224. public virtual float flexibleWidth
  2225. {
  2226. get
  2227. {
  2228. return -1f;
  2229. }
  2230. }
  2231. public virtual float minHeight
  2232. {
  2233. get
  2234. {
  2235. return 0f;
  2236. }
  2237. }
  2238. public virtual float preferredHeight
  2239. {
  2240. get
  2241. {
  2242. if (this.textComponent == null)
  2243. {
  2244. return 0f;
  2245. }
  2246. TextGenerationSettings generationSettings = this.textComponent.GetGenerationSettings(new Vector2(this.textComponent.rectTransform.rect.size.x, 0f));
  2247. return this.textComponent.cachedTextGeneratorForLayout.GetPreferredHeight(this.m_Text, generationSettings) / this.textComponent.pixelsPerUnit;
  2248. }
  2249. }
  2250. public virtual float flexibleHeight
  2251. {
  2252. get
  2253. {
  2254. return -1f;
  2255. }
  2256. }
  2257. public virtual int layoutPriority
  2258. {
  2259. get
  2260. {
  2261. return 1;
  2262. }
  2263. }
  2264. Transform ICanvasElement.get_transform()
  2265. {
  2266. return base.transform;
  2267. }
  2268. bool ICanvasElement.IsDestroyed()
  2269. {
  2270. return base.IsDestroyed();
  2271. }
  2272. protected TouchScreenKeyboard m_Keyboard;
  2273. private static readonly char[] kSeparators = new char[]
  2274. {
  2275. ' ',
  2276. '.',
  2277. ',',
  2278. '\t',
  2279. '\r',
  2280. '\n'
  2281. };
  2282. [SerializeField]
  2283. [FormerlySerializedAs("text")]
  2284. protected Text m_TextComponent;
  2285. [SerializeField]
  2286. protected Graphic m_Placeholder;
  2287. [SerializeField]
  2288. private uGUIInputField.ContentType m_ContentType;
  2289. [FormerlySerializedAs("inputType")]
  2290. [SerializeField]
  2291. private uGUIInputField.InputType m_InputType;
  2292. [FormerlySerializedAs("asteriskChar")]
  2293. [SerializeField]
  2294. private char m_AsteriskChar = '*';
  2295. [FormerlySerializedAs("keyboardType")]
  2296. [SerializeField]
  2297. private TouchScreenKeyboardType m_KeyboardType;
  2298. [SerializeField]
  2299. private uGUIInputField.LineType m_LineType;
  2300. [FormerlySerializedAs("hideMobileInput")]
  2301. [SerializeField]
  2302. private bool m_HideMobileInput;
  2303. [FormerlySerializedAs("validation")]
  2304. [SerializeField]
  2305. private uGUIInputField.CharacterValidation m_CharacterValidation;
  2306. [FormerlySerializedAs("characterLimit")]
  2307. [SerializeField]
  2308. private int m_CharacterLimit;
  2309. [FormerlySerializedAs("onSubmit")]
  2310. [FormerlySerializedAs("m_OnSubmit")]
  2311. [FormerlySerializedAs("m_EndEdit")]
  2312. [SerializeField]
  2313. private uGUIInputField.SubmitEvent m_OnEndEdit = new uGUIInputField.SubmitEvent();
  2314. [FormerlySerializedAs("onValueChange")]
  2315. [FormerlySerializedAs("m_OnValueChange")]
  2316. [SerializeField]
  2317. private uGUIInputField.OnChangeEvent m_OnValueChanged = new uGUIInputField.OnChangeEvent();
  2318. [FormerlySerializedAs("onValidateInput")]
  2319. [SerializeField]
  2320. private uGUIInputField.OnValidateInput m_OnValidateInput;
  2321. [SerializeField]
  2322. private Color m_CaretColor = new Color(0.196078435f, 0.196078435f, 0.196078435f, 1f);
  2323. [SerializeField]
  2324. private bool m_CustomCaretColor;
  2325. [FormerlySerializedAs("selectionColor")]
  2326. [SerializeField]
  2327. private Color m_SelectionColor = new Color(0.65882355f, 0.807843149f, 1f, 0.7529412f);
  2328. [SerializeField]
  2329. [FormerlySerializedAs("mValue")]
  2330. protected string m_Text = string.Empty;
  2331. [SerializeField]
  2332. [Range(0f, 4f)]
  2333. private float m_CaretBlinkRate = 0.85f;
  2334. [SerializeField]
  2335. private Vector2 m_FixCaretPos = Vector2.zero;
  2336. [SerializeField]
  2337. [Range(1f, 5f)]
  2338. private int m_CaretWidth = 1;
  2339. [SerializeField]
  2340. private bool m_ReadOnly;
  2341. protected int m_CaretPosition;
  2342. protected int m_CaretSelectPosition;
  2343. private RectTransform caretRectTrans;
  2344. protected UIVertex[] m_CursorVerts;
  2345. private TextGenerator m_InputTextCache;
  2346. private CanvasRenderer m_CachedInputRenderer;
  2347. private bool m_PreventFontCallback;
  2348. [NonSerialized]
  2349. protected Mesh m_Mesh;
  2350. private bool m_AllowInput;
  2351. private bool m_ShouldActivateNextUpdate;
  2352. private bool m_UpdateDrag;
  2353. private bool m_DragPositionOutOfBounds;
  2354. private const float kHScrollSpeed = 0.05f;
  2355. private const float kVScrollSpeed = 0.1f;
  2356. protected bool m_CaretVisible;
  2357. private Coroutine m_BlinkCoroutine;
  2358. private float m_BlinkStartTime;
  2359. protected int m_DrawStart;
  2360. protected int m_DrawEnd;
  2361. private Coroutine m_DragCoroutine;
  2362. private string m_OriginalText = string.Empty;
  2363. private bool m_WasCanceled;
  2364. private bool m_HasDoneFocusTransition;
  2365. private const string kEmailSpecialCharacters = "!#$%&'*+-/=?^_`{|}~";
  2366. private Event m_ProcessingEvent = new Event();
  2367. public enum ContentType
  2368. {
  2369. Standard,
  2370. Autocorrected,
  2371. IntegerNumber,
  2372. DecimalNumber,
  2373. Alphanumeric,
  2374. Name,
  2375. EmailAddress,
  2376. Password,
  2377. Pin,
  2378. Custom
  2379. }
  2380. public enum InputType
  2381. {
  2382. Standard,
  2383. AutoCorrect,
  2384. Password
  2385. }
  2386. public enum CharacterValidation
  2387. {
  2388. None,
  2389. Integer,
  2390. Decimal,
  2391. Alphanumeric,
  2392. Name,
  2393. EmailAddress
  2394. }
  2395. public enum LineType
  2396. {
  2397. SingleLine,
  2398. MultiLineSubmit,
  2399. MultiLineNewline
  2400. }
  2401. public delegate char OnValidateInput(string text, int charIndex, char addedChar);
  2402. [Serializable]
  2403. public class SubmitEvent : UnityEvent<string>
  2404. {
  2405. }
  2406. [Serializable]
  2407. public class OnChangeEvent : UnityEvent<string>
  2408. {
  2409. }
  2410. protected enum EditState
  2411. {
  2412. Continue,
  2413. Finish
  2414. }
  2415. }
  2416. }