UGUI_SCInputField.cs 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749
  1. //#define TouchScreenKeyboard
  2. #define SCKeyboard
  3. using SC.XR.Unity.Module_Keyboard;
  4. using System;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7. using UnityEditor;
  8. using UnityEngine;
  9. using UnityEngine.EventSystems;
  10. using UnityEngine.UI;
  11. namespace SC.XR.Unity
  12. {
  13. [AddComponentMenu("UI/UGUI - SC Input Field", 32)]
  14. public class UGUI_SCInputField : SCInputField
  15. {
  16. protected UGUI_SCInputField()
  17. {
  18. this.EnforceTextHOverflow();
  19. }
  20. public override bool shouldHideMobileInput
  21. {
  22. get
  23. {
  24. #if SCKeyboard
  25. RuntimePlatform platform = Application.platform;
  26. return (platform != RuntimePlatform.IPhonePlayer &&
  27. platform != RuntimePlatform.tvOS)
  28. || this.m_HideMobileInput
  29. // UGUI_SCInputField is run on android
  30. || (platform == RuntimePlatform.Android);
  31. #elif TouchScreenKeyboard
  32. RuntimePlatform platform = Application.platform;
  33. return (platform != RuntimePlatform.IPhonePlayer && platform != RuntimePlatform.Android && platform != RuntimePlatform.tvOS) || this.m_HideMobileInput;
  34. #endif
  35. }
  36. set
  37. {
  38. SCSetPropertyUtility.SetStruct<bool>(ref this.m_HideMobileInput, value);
  39. }
  40. }
  41. #region SCKeyboard
  42. private bool shouldDeactivateOnDeselect
  43. {
  44. get
  45. {
  46. //TODO
  47. return (m_Keyboard == null || m_Keyboard.status > 0)
  48. && EventSystem.current.currentSelectedGameObject != this.gameObject;
  49. }
  50. }
  51. #endregion
  52. public override string text
  53. {
  54. get
  55. {
  56. return this.m_Text;
  57. }
  58. set
  59. {
  60. this.SetText(value, true);
  61. }
  62. }
  63. public void SetTextWithoutNotify(string input)
  64. {
  65. this.SetText(input, false);
  66. }
  67. private void SetText(string value, bool sendCallback = true)
  68. {
  69. bool flag = this.text == value;
  70. if (!flag)
  71. {
  72. bool flag2 = value == null;
  73. if (flag2)
  74. {
  75. value = "";
  76. }
  77. value = value.Replace("\0", string.Empty);
  78. bool flag3 = this.m_LineType == UGUI_SCInputField.LineType.SingleLine;
  79. if (flag3)
  80. {
  81. value = value.Replace("\n", "").Replace("\t", "");
  82. }
  83. bool flag4 = this.onValidateInput != null || this.characterValidation > UGUI_SCInputField.CharacterValidation.None;
  84. if (flag4)
  85. {
  86. this.m_Text = "";
  87. UGUI_SCInputField.OnValidateInput validatorMethod = this.onValidateInput ?? new UGUI_SCInputField.OnValidateInput(this.Validate);
  88. this.m_CaretPosition = (this.m_CaretSelectPosition = value.Length);
  89. int charactersToCheck = (this.characterLimit > 0) ? Math.Min(this.characterLimit, value.Length) : value.Length;
  90. for (int i = 0; i < charactersToCheck; i++)
  91. {
  92. char c = validatorMethod(this.m_Text, this.m_Text.Length, value[i]);
  93. bool flag5 = c > '\0';
  94. if (flag5)
  95. {
  96. this.m_Text += c.ToString();
  97. }
  98. }
  99. }
  100. else
  101. {
  102. this.m_Text = ((this.characterLimit > 0 && value.Length > this.characterLimit) ? value.Substring(0, this.characterLimit) : value);
  103. }
  104. bool flag6 = !Application.isPlaying;
  105. if (flag6)
  106. {
  107. this.SendOnValueChangedAndUpdateLabel();
  108. }
  109. else
  110. {
  111. bool flag7 = this.m_Keyboard != null;
  112. if (flag7)
  113. {
  114. this.m_Keyboard.text = this.m_Text;
  115. }
  116. bool flag8 = this.m_CaretPosition > this.m_Text.Length;
  117. if (flag8)
  118. {
  119. this.m_CaretPosition = (this.m_CaretSelectPosition = this.m_Text.Length);
  120. }
  121. else
  122. {
  123. bool flag9 = this.m_CaretSelectPosition > this.m_Text.Length;
  124. if (flag9)
  125. {
  126. this.m_CaretSelectPosition = this.m_Text.Length;
  127. }
  128. }
  129. if (sendCallback)
  130. {
  131. this.SendOnValueChanged();
  132. }
  133. this.UpdateLabel();
  134. }
  135. }
  136. }
  137. public override int characterLimit
  138. {
  139. get
  140. {
  141. return this.m_CharacterLimit;
  142. }
  143. set
  144. {
  145. bool flag = SCSetPropertyUtility.SetStruct<int>(ref this.m_CharacterLimit, Math.Max(0, value));
  146. if (flag)
  147. {
  148. this.UpdateLabel();
  149. bool flag2 = this.m_Keyboard != null;
  150. if (flag2)
  151. {
  152. this.m_Keyboard.characterLimit = value;
  153. }
  154. }
  155. }
  156. }
  157. #if SCKeyboard
  158. public SCKeyboard scKeyboard
  159. {
  160. get
  161. {
  162. return this.m_Keyboard;
  163. }
  164. }
  165. #elif TouchScreenKeyboard
  166. public TouchScreenKeyboard touchScreenKeyboard
  167. {
  168. get
  169. {
  170. return this.m_Keyboard;
  171. }
  172. }
  173. #endif
  174. #if SCKeyboard
  175. public SCKeyboardEnum scKeyboardEnum
  176. {
  177. get
  178. {
  179. return this.m_SCKeyboardEnum;
  180. }
  181. set
  182. {
  183. bool flag = SCSetPropertyUtility.SetStruct<SCKeyboardEnum>(ref this.m_SCKeyboardEnum, value);
  184. if (flag)
  185. {
  186. this.SetToCustom();
  187. }
  188. }
  189. }
  190. #endif
  191. #if SCKeyboard
  192. public SCKeyboardType scKeyboardType
  193. {
  194. get
  195. {
  196. return this.m_SCKeyboardType;
  197. }
  198. set
  199. {
  200. bool flag = SCSetPropertyUtility.SetStruct<SCKeyboardType>(ref this.m_SCKeyboardType, value);
  201. if (flag)
  202. {
  203. this.SetToCustom();
  204. }
  205. }
  206. }
  207. #elif TouchScreenKeyboard
  208. public override TouchScreenKeyboardType keyboardType
  209. {
  210. get
  211. {
  212. return this.m_KeyboardType;
  213. }
  214. set
  215. {
  216. bool flag = SCSetPropertyUtility.SetStruct<TouchScreenKeyboardType>(ref this.m_KeyboardType, value);
  217. if (flag)
  218. {
  219. this.SetToCustom();
  220. }
  221. }
  222. }
  223. #endif
  224. #if UNITY_EDITOR
  225. protected override void OnValidate()
  226. {
  227. base.OnValidate();
  228. this.EnforceContentType();
  229. this.EnforceTextHOverflow();
  230. this.m_CharacterLimit = Math.Max(0, this.m_CharacterLimit);
  231. bool flag = !this.IsActive();
  232. if (!flag)
  233. {
  234. this.ClampPos(ref this.m_CaretPosition);
  235. this.ClampPos(ref this.m_CaretSelectPosition);
  236. this.UpdateLabel();
  237. bool allowInput = this.m_AllowInput;
  238. if (allowInput)
  239. {
  240. this.SetCaretActive();
  241. }
  242. }
  243. }
  244. #endif
  245. protected override IEnumerator CaretBlink()
  246. {
  247. base.CaretBlink();
  248. yield break;
  249. }
  250. protected override bool InPlaceEditing()
  251. {
  252. #if SCKeyboard
  253. return !SCKeyboard.isSupported || this.m_TouchKeyboardAllowsInPlaceEditing;
  254. #elif TouchScreenKeyboard
  255. return !TouchScreenKeyboard.isSupported || this.m_TouchKeyboardAllowsInPlaceEditing;
  256. #endif
  257. }
  258. protected override void UpdateCaretFromKeyboard()
  259. {
  260. RangeInt selectionRange = this.m_Keyboard.selection;
  261. int selectionStart = selectionRange.start;
  262. int selectionEnd = selectionRange.end;
  263. bool caretChanged = false;
  264. bool flag = this.caretPositionInternal != selectionStart;
  265. if (flag)
  266. {
  267. caretChanged = true;
  268. this.caretPositionInternal = selectionStart;
  269. }
  270. bool flag2 = this.caretSelectPositionInternal != selectionEnd;
  271. if (flag2)
  272. {
  273. this.caretSelectPositionInternal = selectionEnd;
  274. caretChanged = true;
  275. }
  276. bool flag3 = caretChanged;
  277. if (flag3)
  278. {
  279. this.m_BlinkStartTime = Time.unscaledTime;
  280. this.UpdateLabel();
  281. }
  282. }
  283. protected override void LateUpdate()
  284. {
  285. bool shouldActivateNextUpdate = this.m_ShouldActivateNextUpdate;
  286. if (shouldActivateNextUpdate)
  287. {
  288. bool flag = !this.isFocused;
  289. if (flag)
  290. {
  291. this.ActivateInputFieldInternal();
  292. this.m_ShouldActivateNextUpdate = false;
  293. return;
  294. }
  295. this.m_ShouldActivateNextUpdate = false;
  296. }
  297. this.AssignPositioningIfNeeded();
  298. bool flag2 = !this.isFocused || this.InPlaceEditing();
  299. if (!flag2)
  300. {
  301. #if SCKeyboard
  302. bool flag3 = this.m_Keyboard == null || this.m_Keyboard.status > SCKeyboard.Status.Visible;
  303. #elif TouchScreenKeyboard
  304. bool flag3 = this.m_Keyboard == null || this.m_Keyboard.status > TouchScreenKeyboard.Status.Visible;
  305. #endif
  306. if (flag3)
  307. {
  308. bool flag4 = this.m_Keyboard != null;
  309. if (flag4)
  310. {
  311. bool flag5 = !this.m_ReadOnly;
  312. if (flag5)
  313. {
  314. this.text = this.m_Keyboard.text;
  315. }
  316. #if SCKeyboard
  317. bool flag6 = this.m_Keyboard.status == SCKeyboard.Status.Canceled;
  318. #elif TouchScreenKeyboard
  319. bool flag6 = this.m_Keyboard.status == TouchScreenKeyboard.Status.Canceled;
  320. #endif
  321. if (flag6)
  322. {
  323. this.m_WasCanceled = true;
  324. }
  325. }
  326. this.OnDeselect(null);
  327. }
  328. else
  329. {
  330. string val = this.m_Keyboard.text;
  331. bool flag7 = this.m_Text != val;
  332. if (flag7)
  333. {
  334. bool readOnly = this.m_ReadOnly;
  335. if (readOnly)
  336. {
  337. this.m_Keyboard.text = this.m_Text;
  338. }
  339. else
  340. {
  341. this.m_Text = "";
  342. for (int i = 0; i < val.Length; i++)
  343. {
  344. bool flag8 = val[i] == '\r' || val[i] == '\u0003';
  345. if (flag8)
  346. {
  347. //TODO
  348. val.Remove(i);
  349. val.Insert(i, "\n");
  350. }
  351. bool flag9 = this.onValidateInput != null;
  352. if (flag9)
  353. {
  354. //TODO
  355. char c = val[i];
  356. val.Remove(i);
  357. val.Insert(i, this.onValidateInput(this.m_Text, this.m_Text.Length, c).ToString());
  358. }
  359. else
  360. {
  361. bool flag10 = this.characterValidation > UGUI_SCInputField.CharacterValidation.None;
  362. if (flag10)
  363. {
  364. //TODO
  365. char c = val[i];
  366. val.Remove(i);
  367. val.Insert(i, this.Validate(this.m_Text, this.m_Text.Length, c).ToString());
  368. }
  369. }
  370. bool flag11 = this.lineType == UGUI_SCInputField.LineType.MultiLineSubmit && val[i] == '\n';
  371. if (flag11)
  372. {
  373. this.m_Keyboard.text = this.m_Text;
  374. this.OnDeselect(null);
  375. return;
  376. }
  377. bool flag12 = val[i] > '\0';
  378. if (flag12)
  379. {
  380. this.m_Text += val[i].ToString();
  381. }
  382. }
  383. bool flag13 = this.characterLimit > 0 && this.m_Text.Length > this.characterLimit;
  384. if (flag13)
  385. {
  386. this.m_Text = this.m_Text.Substring(0, this.characterLimit);
  387. }
  388. bool canGetSelection = this.m_Keyboard.canGetSelection;
  389. if (canGetSelection)
  390. {
  391. this.UpdateCaretFromKeyboard();
  392. }
  393. else
  394. {
  395. this.caretPositionInternal = (this.caretSelectPositionInternal = this.m_Text.Length);
  396. }
  397. bool flag14 = this.m_Text != val;
  398. if (flag14)
  399. {
  400. this.m_Keyboard.text = this.m_Text;
  401. }
  402. this.SendOnValueChangedAndUpdateLabel();
  403. }
  404. }
  405. else
  406. {
  407. bool flag15 = this.m_HideMobileInput && this.m_Keyboard.canSetSelection;
  408. if (flag15)
  409. {
  410. this.m_Keyboard.selection = new RangeInt(this.caretPositionInternal, this.caretSelectPositionInternal - this.caretPositionInternal);
  411. }
  412. else
  413. {
  414. bool flag16 = this.m_Keyboard.canGetSelection && !this.m_HideMobileInput;
  415. if (flag16)
  416. {
  417. this.UpdateCaretFromKeyboard();
  418. }
  419. }
  420. }
  421. #if SCKeyboard
  422. bool flag17 = this.m_Keyboard.status > SCKeyboard.Status.Visible;
  423. #elif TouchScreenKeyboard
  424. bool flag17 = this.m_Keyboard.status > TouchScreenKeyboard.Status.Visible;
  425. #endif
  426. if (flag17)
  427. {
  428. #if SCKeyboard
  429. bool flag18 = this.m_Keyboard.status == SCKeyboard.Status.Canceled;
  430. #elif TouchScreenKeyboard
  431. bool flag18 = this.m_Keyboard.status == TouchScreenKeyboard.Status.Canceled;
  432. #endif
  433. if (flag18)
  434. {
  435. this.m_WasCanceled = true;
  436. }
  437. this.OnDeselect(null);
  438. }
  439. }
  440. }
  441. #region SCKeyboard
  442. if (m_Keyboard != null && m_Keyboard.status > 0 && EventSystem.current.currentSelectedGameObject != this.gameObject)
  443. {
  444. this.m_ShouldDeactivateNextUpdate = true;
  445. }
  446. bool shouldDeactivateNextUpdate = this.m_ShouldDeactivateNextUpdate;
  447. if (shouldDeactivateNextUpdate)
  448. {
  449. OnDeselect(null);
  450. this.m_ShouldDeactivateNextUpdate = false;
  451. }
  452. #endregion
  453. }
  454. protected override bool MayDrag(PointerEventData eventData)
  455. {
  456. return this.IsActive() &&
  457. this.IsInteractable() &&
  458. eventData.button == PointerEventData.InputButton.Left &&
  459. this.m_TextComponent != null &&
  460. (this.InPlaceEditing() || this.m_HideMobileInput);
  461. }
  462. protected override IEnumerator MouseDragOutsideRect(PointerEventData eventData)
  463. {
  464. while (this.m_UpdateDrag && this.m_DragPositionOutOfBounds)
  465. {
  466. Vector2 localMousePos;
  467. RectTransformUtility.ScreenPointToLocalPointInRectangle(this.textComponent.rectTransform, eventData.position, eventData.pressEventCamera, out localMousePos);
  468. Rect rect = this.textComponent.rectTransform.rect;
  469. bool multiLine = this.multiLine;
  470. if (multiLine)
  471. {
  472. bool flag = localMousePos.y > rect.yMax;
  473. if (flag)
  474. {
  475. this.MoveUp(true, true);
  476. }
  477. else
  478. {
  479. bool flag2 = localMousePos.y < rect.yMin;
  480. if (flag2)
  481. {
  482. this.MoveDown(true, true);
  483. }
  484. }
  485. }
  486. else
  487. {
  488. bool flag3 = localMousePos.x < rect.xMin;
  489. if (flag3)
  490. {
  491. this.MoveLeft(true, false);
  492. }
  493. else
  494. {
  495. bool flag4 = localMousePos.x > rect.xMax;
  496. if (flag4)
  497. {
  498. this.MoveRight(true, false);
  499. }
  500. }
  501. }
  502. this.UpdateLabel();
  503. float delay = this.multiLine ? 0.1f : 0.05f;
  504. bool flag5 = this.m_WaitForSecondsRealtime == null;
  505. if (flag5)
  506. {
  507. this.m_WaitForSecondsRealtime = new WaitForSecondsRealtime(delay);
  508. }
  509. else
  510. {
  511. this.m_WaitForSecondsRealtime.waitTime = delay;
  512. }
  513. yield return this.m_WaitForSecondsRealtime;
  514. localMousePos = default(Vector2);
  515. rect = default(Rect);
  516. }
  517. this.m_DragCoroutine = null;
  518. yield break;
  519. }
  520. public override void OnPointerDown(PointerEventData eventData)
  521. {
  522. bool flag = !this.MayDrag(eventData);
  523. if (!flag)
  524. {
  525. EventSystem.current.SetSelectedGameObject(base.gameObject, eventData);
  526. bool hadFocusBefore = this.m_AllowInput;
  527. base.OnPointerDown(eventData);
  528. bool flag2 = !this.InPlaceEditing();
  529. if (flag2)
  530. {
  531. bool flag3 = this.m_Keyboard == null || !this.m_Keyboard.active;
  532. if (flag3)
  533. {
  534. this.OnSelect(eventData);
  535. return;
  536. }
  537. }
  538. bool flag4 = hadFocusBefore;
  539. if (flag4)
  540. {
  541. Vector2 localMousePos;
  542. RectTransformUtility.ScreenPointToLocalPointInRectangle(this.textComponent.rectTransform, eventData.position, eventData.pressEventCamera, out localMousePos);
  543. this.caretSelectPositionInternal = (this.caretPositionInternal = this.GetCharacterIndexFromPosition(localMousePos) + this.m_DrawStart);
  544. }
  545. this.UpdateLabel();
  546. eventData.Use();
  547. }
  548. }
  549. protected override UGUI_SCInputField.EditState KeyPressed(Event evt)
  550. {
  551. EventModifiers currentEventModifiers = evt.modifiers;
  552. bool ctrl = (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX) ? (((int)currentEventModifiers & 8) > 0) : (((int)currentEventModifiers & 2) > 0);
  553. bool shift = ((int)currentEventModifiers & 1) > 0;
  554. bool alt = ((int)currentEventModifiers & 4) > 0;
  555. bool ctrlOnly = ctrl && !alt && !shift;
  556. KeyCode keyCode = evt.keyCode;
  557. if (keyCode <= KeyCode.A)
  558. {
  559. if (keyCode <= KeyCode.Return)
  560. {
  561. if (keyCode == KeyCode.Backspace)
  562. {
  563. this.Backspace();
  564. return UGUI_SCInputField.EditState.Continue;
  565. }
  566. if (keyCode != KeyCode.Return)
  567. {
  568. goto IL_27D;
  569. }
  570. }
  571. else
  572. {
  573. if (keyCode == KeyCode.Escape)
  574. {
  575. this.m_WasCanceled = true;
  576. return UGUI_SCInputField.EditState.Finish;
  577. }
  578. if (keyCode != KeyCode.A)
  579. {
  580. goto IL_27D;
  581. }
  582. bool flag = ctrlOnly;
  583. if (flag)
  584. {
  585. this.SelectAll();
  586. return UGUI_SCInputField.EditState.Continue;
  587. }
  588. goto IL_27D;
  589. }
  590. }
  591. else if (keyCode <= KeyCode.V)
  592. {
  593. if (keyCode != KeyCode.C)
  594. {
  595. if (keyCode != KeyCode.V)
  596. {
  597. goto IL_27D;
  598. }
  599. bool flag2 = ctrlOnly;
  600. if (flag2)
  601. {
  602. this.Append(UGUI_SCInputField.clipboard);
  603. this.UpdateLabel();
  604. return UGUI_SCInputField.EditState.Continue;
  605. }
  606. goto IL_27D;
  607. }
  608. else
  609. {
  610. bool flag3 = ctrlOnly;
  611. if (flag3)
  612. {
  613. bool flag4 = this.inputType != UGUI_SCInputField.InputType.Password;
  614. if (flag4)
  615. {
  616. UGUI_SCInputField.clipboard = this.GetSelectedString();
  617. }
  618. else
  619. {
  620. UGUI_SCInputField.clipboard = "";
  621. }
  622. return UGUI_SCInputField.EditState.Continue;
  623. }
  624. goto IL_27D;
  625. }
  626. }
  627. else if (keyCode != KeyCode.X)
  628. {
  629. if (keyCode == KeyCode.Delete)
  630. {
  631. this.ForwardSpace();
  632. return UGUI_SCInputField.EditState.Continue;
  633. }
  634. switch (keyCode)
  635. {
  636. case KeyCode.KeypadEnter:
  637. break;
  638. case KeyCode.KeypadEquals:
  639. case KeyCode.Insert:
  640. goto IL_27D;
  641. case KeyCode.UpArrow:
  642. this.MoveUp(shift);
  643. return UGUI_SCInputField.EditState.Continue;
  644. case KeyCode.DownArrow:
  645. this.MoveDown(shift);
  646. return UGUI_SCInputField.EditState.Continue;
  647. case KeyCode.RightArrow:
  648. this.MoveRight(shift, ctrl);
  649. return UGUI_SCInputField.EditState.Continue;
  650. case KeyCode.LeftArrow:
  651. this.MoveLeft(shift, ctrl);
  652. return UGUI_SCInputField.EditState.Continue;
  653. case KeyCode.Home:
  654. this.MoveTextStart(shift);
  655. return UGUI_SCInputField.EditState.Continue;
  656. case KeyCode.End:
  657. this.MoveTextEnd(shift);
  658. return UGUI_SCInputField.EditState.Continue;
  659. default:
  660. goto IL_27D;
  661. }
  662. }
  663. else
  664. {
  665. bool flag5 = ctrlOnly;
  666. if (flag5)
  667. {
  668. bool flag6 = this.inputType != UGUI_SCInputField.InputType.Password;
  669. if (flag6)
  670. {
  671. UGUI_SCInputField.clipboard = this.GetSelectedString();
  672. }
  673. else
  674. {
  675. UGUI_SCInputField.clipboard = "";
  676. }
  677. this.Delete();
  678. this.UpdateTouchKeyboardFromEditChanges();
  679. this.SendOnValueChangedAndUpdateLabel();
  680. return UGUI_SCInputField.EditState.Continue;
  681. }
  682. goto IL_27D;
  683. }
  684. bool flag7 = this.lineType != UGUI_SCInputField.LineType.MultiLineNewline;
  685. if (flag7)
  686. {
  687. return UGUI_SCInputField.EditState.Finish;
  688. }
  689. IL_27D:
  690. char c = evt.character;
  691. bool flag8 = !this.multiLine && (c == '\t' || c == '\r' || c == '\n');
  692. UGUI_SCInputField.EditState result;
  693. if (flag8)
  694. {
  695. result = UGUI_SCInputField.EditState.Continue;
  696. }
  697. else
  698. {
  699. bool flag9 = c == '\r' || c == '\u0003';
  700. if (flag9)
  701. {
  702. c = '\n';
  703. }
  704. bool flag10 = this.IsValidChar(c);
  705. if (flag10)
  706. {
  707. this.Append(c);
  708. }
  709. bool flag11 = c == '\0';
  710. if (flag11)
  711. {
  712. bool flag12 = this.compositionString.Length > 0;
  713. if (flag12)
  714. {
  715. this.UpdateLabel();
  716. }
  717. }
  718. result = UGUI_SCInputField.EditState.Continue;
  719. }
  720. return result;
  721. }
  722. protected override bool IsValidChar(char c)
  723. {
  724. bool flag = c == '\u007f';
  725. bool result;
  726. if (flag)
  727. {
  728. result = false;
  729. }
  730. else
  731. {
  732. bool flag2 = c == '\t' || c == '\n';
  733. result = (flag2 || this.m_TextComponent.font.HasCharacter(c));
  734. }
  735. return result;
  736. }
  737. public override void OnUpdateSelected(BaseEventData eventData)
  738. {
  739. bool flag = !this.isFocused;
  740. if (!flag)
  741. {
  742. bool consumedEvent = false;
  743. while (Event.PopEvent(this.m_ProcessingEvent))
  744. {
  745. bool flag2 = (int)this.m_ProcessingEvent.rawType == 4;
  746. if (flag2)
  747. {
  748. consumedEvent = true;
  749. UGUI_SCInputField.EditState shouldContinue = this.KeyPressed(this.m_ProcessingEvent);
  750. bool flag3 = shouldContinue == UGUI_SCInputField.EditState.Finish;
  751. if (flag3)
  752. {
  753. this.DeactivateInputField();
  754. break;
  755. }
  756. }
  757. EventType type = this.m_ProcessingEvent.type;
  758. if ((int)type - 13 <= 1)
  759. {
  760. string commandName = this.m_ProcessingEvent.commandName;
  761. if (commandName == "SelectAll")
  762. {
  763. this.SelectAll();
  764. consumedEvent = true;
  765. }
  766. }
  767. }
  768. bool flag4 = consumedEvent;
  769. if (flag4)
  770. {
  771. this.UpdateLabel();
  772. }
  773. eventData.Use();
  774. }
  775. }
  776. protected override int DetermineCharacterLine(int charPos, TextGenerator generator)
  777. {
  778. for (int i = 0; i < generator.lineCount - 1; i++)
  779. {
  780. bool flag = generator.lines[i + 1].startCharIdx > charPos;
  781. if (flag)
  782. {
  783. return i;
  784. }
  785. }
  786. return generator.lineCount - 1;
  787. }
  788. protected override int LineUpCharacterPosition(int originalPos, bool goToFirstChar)
  789. {
  790. bool flag = originalPos >= this.cachedInputTextGenerator.characters.Count;
  791. int result;
  792. if (flag)
  793. {
  794. result = 0;
  795. }
  796. else
  797. {
  798. UICharInfo originChar = this.cachedInputTextGenerator.characters[originalPos];
  799. int originLine = this.DetermineCharacterLine(originalPos, this.cachedInputTextGenerator);
  800. bool flag2 = originLine <= 0;
  801. if (flag2)
  802. {
  803. result = (goToFirstChar ? 0 : originalPos);
  804. }
  805. else
  806. {
  807. int endCharIdx = this.cachedInputTextGenerator.lines[originLine].startCharIdx - 1;
  808. for (int i = this.cachedInputTextGenerator.lines[originLine - 1].startCharIdx; i < endCharIdx; i++)
  809. {
  810. bool flag3 = this.cachedInputTextGenerator.characters[i].cursorPos.x >= originChar.cursorPos.x;
  811. if (flag3)
  812. {
  813. return i;
  814. }
  815. }
  816. result = endCharIdx;
  817. }
  818. }
  819. return result;
  820. }
  821. protected override int LineDownCharacterPosition(int originalPos, bool goToLastChar)
  822. {
  823. bool flag = originalPos >= this.cachedInputTextGenerator.characterCountVisible;
  824. int result;
  825. if (flag)
  826. {
  827. result = this.text.Length;
  828. }
  829. else
  830. {
  831. UICharInfo originChar = this.cachedInputTextGenerator.characters[originalPos];
  832. int originLine = this.DetermineCharacterLine(originalPos, this.cachedInputTextGenerator);
  833. bool flag2 = originLine + 1 >= this.cachedInputTextGenerator.lineCount;
  834. if (flag2)
  835. {
  836. result = (goToLastChar ? this.text.Length : originalPos);
  837. }
  838. else
  839. {
  840. int endCharIdx = UGUI_SCInputField.GetLineEndPosition(this.cachedInputTextGenerator, originLine + 1);
  841. for (int i = this.cachedInputTextGenerator.lines[originLine + 1].startCharIdx; i < endCharIdx; i++)
  842. {
  843. bool flag3 = this.cachedInputTextGenerator.characters[i].cursorPos.x >= originChar.cursorPos.x;
  844. if (flag3)
  845. {
  846. return i;
  847. }
  848. }
  849. result = endCharIdx;
  850. }
  851. }
  852. return result;
  853. }
  854. protected override void ForwardSpace()
  855. {
  856. bool readOnly = this.m_ReadOnly;
  857. if (!readOnly)
  858. {
  859. bool hasSelection = this.hasSelection;
  860. if (hasSelection)
  861. {
  862. this.Delete();
  863. this.UpdateTouchKeyboardFromEditChanges();
  864. this.SendOnValueChangedAndUpdateLabel();
  865. }
  866. else
  867. {
  868. bool flag = this.caretPositionInternal < this.text.Length;
  869. if (flag)
  870. {
  871. this.m_Text = this.text.Remove(this.caretPositionInternal, 1);
  872. this.UpdateTouchKeyboardFromEditChanges();
  873. this.SendOnValueChangedAndUpdateLabel();
  874. }
  875. }
  876. }
  877. }
  878. protected override void Backspace()
  879. {
  880. bool readOnly = this.m_ReadOnly;
  881. if (!readOnly)
  882. {
  883. bool hasSelection = this.hasSelection;
  884. if (hasSelection)
  885. {
  886. this.Delete();
  887. this.UpdateTouchKeyboardFromEditChanges();
  888. this.SendOnValueChangedAndUpdateLabel();
  889. }
  890. else
  891. {
  892. bool flag = this.caretPositionInternal > 0;
  893. if (flag)
  894. {
  895. this.m_Text = this.text.Remove(this.caretPositionInternal - 1, 1);
  896. this.caretSelectPositionInternal = --this.caretPositionInternal;
  897. this.UpdateTouchKeyboardFromEditChanges();
  898. this.SendOnValueChangedAndUpdateLabel();
  899. }
  900. }
  901. }
  902. }
  903. protected override void Insert(char c)
  904. {
  905. bool readOnly = this.m_ReadOnly;
  906. if (!readOnly)
  907. {
  908. string replaceString = c.ToString();
  909. this.Delete();
  910. bool flag = this.characterLimit > 0 && this.text.Length >= this.characterLimit;
  911. if (!flag)
  912. {
  913. this.m_Text = this.text.Insert(this.m_CaretPosition, replaceString);
  914. this.caretSelectPositionInternal = (this.caretPositionInternal += replaceString.Length);
  915. this.UpdateTouchKeyboardFromEditChanges();
  916. this.SendOnValueChanged();
  917. }
  918. }
  919. }
  920. private void UpdateTouchKeyboardFromEditChanges()
  921. {
  922. bool flag = this.m_Keyboard != null && this.InPlaceEditing();
  923. if (flag)
  924. {
  925. this.m_Keyboard.text = this.m_Text;
  926. }
  927. }
  928. protected override void Append(string input)
  929. {
  930. bool readOnly = this.m_ReadOnly;
  931. if (!readOnly)
  932. {
  933. bool flag = !this.InPlaceEditing();
  934. if (!flag)
  935. {
  936. int i = 0;
  937. int imax = input.Length;
  938. while (i < imax)
  939. {
  940. char c = input[i];
  941. bool flag2 = c >= ' ' || c == '\t' || c == '\r' || c == '\n' || c == '\n';
  942. if (flag2)
  943. {
  944. this.Append(c);
  945. }
  946. i++;
  947. }
  948. }
  949. }
  950. }
  951. protected override void Append(char input)
  952. {
  953. bool flag = char.IsSurrogate(input);
  954. if (!flag)
  955. {
  956. bool flag2 = this.m_ReadOnly || this.text.Length >= 16382;
  957. if (!flag2)
  958. {
  959. bool flag3 = !this.InPlaceEditing();
  960. if (!flag3)
  961. {
  962. int insertionPoint = Math.Min(this.selectionFocusPosition, this.selectionAnchorPosition);
  963. bool flag4 = this.onValidateInput != null;
  964. if (flag4)
  965. {
  966. input = this.onValidateInput(this.text, insertionPoint, input);
  967. }
  968. else
  969. {
  970. bool flag5 = this.characterValidation > UGUI_SCInputField.CharacterValidation.None;
  971. if (flag5)
  972. {
  973. input = this.Validate(this.text, insertionPoint, input);
  974. }
  975. }
  976. bool flag6 = input == '\0';
  977. if (!flag6)
  978. {
  979. this.Insert(input);
  980. }
  981. }
  982. }
  983. }
  984. }
  985. protected override bool IsSelectionVisible()
  986. {
  987. bool flag = this.m_DrawStart > this.caretPositionInternal || this.m_DrawStart > this.caretSelectPositionInternal;
  988. bool result;
  989. if (flag)
  990. {
  991. result = false;
  992. }
  993. else
  994. {
  995. bool flag2 = this.m_DrawEnd < this.caretPositionInternal || this.m_DrawEnd < this.caretSelectPositionInternal;
  996. result = !flag2;
  997. }
  998. return result;
  999. }
  1000. protected override void SetDrawRangeToContainCaretPosition(int caretPos)
  1001. {
  1002. bool flag = this.cachedInputTextGenerator.lineCount <= 0;
  1003. if (!flag)
  1004. {
  1005. Vector2 extents = this.cachedInputTextGenerator.rectExtents.size;
  1006. bool multiLine = this.multiLine;
  1007. if (multiLine)
  1008. {
  1009. IList<UILineInfo> lines = this.cachedInputTextGenerator.lines;
  1010. int caretLine = this.DetermineCharacterLine(caretPos, this.cachedInputTextGenerator);
  1011. bool flag2 = caretPos > this.m_DrawEnd;
  1012. if (flag2)
  1013. {
  1014. this.m_DrawEnd = UGUI_SCInputField.GetLineEndPosition(this.cachedInputTextGenerator, caretLine);
  1015. float bottomY = lines[caretLine].topY - (float)lines[caretLine].height;
  1016. bool flag3 = caretLine == lines.Count - 1;
  1017. if (flag3)
  1018. {
  1019. bottomY += lines[caretLine].leading;
  1020. }
  1021. int startLine;
  1022. for (startLine = caretLine; startLine > 0; startLine--)
  1023. {
  1024. float topY = lines[startLine - 1].topY;
  1025. bool flag4 = topY - bottomY > extents.y;
  1026. if (flag4)
  1027. {
  1028. break;
  1029. }
  1030. }
  1031. this.m_DrawStart = UGUI_SCInputField.GetLineStartPosition(this.cachedInputTextGenerator, startLine);
  1032. }
  1033. else
  1034. {
  1035. bool flag5 = caretPos < this.m_DrawStart;
  1036. if (flag5)
  1037. {
  1038. this.m_DrawStart = UGUI_SCInputField.GetLineStartPosition(this.cachedInputTextGenerator, caretLine);
  1039. }
  1040. int startLine2 = this.DetermineCharacterLine(this.m_DrawStart, this.cachedInputTextGenerator);
  1041. int endLine = startLine2;
  1042. float topY2 = lines[startLine2].topY;
  1043. float bottomY2 = lines[endLine].topY - (float)lines[endLine].height;
  1044. bool flag6 = endLine == lines.Count - 1;
  1045. if (flag6)
  1046. {
  1047. bottomY2 += lines[endLine].leading;
  1048. }
  1049. while (endLine < lines.Count - 1)
  1050. {
  1051. bottomY2 = lines[endLine + 1].topY - (float)lines[endLine + 1].height;
  1052. bool flag7 = endLine + 1 == lines.Count - 1;
  1053. if (flag7)
  1054. {
  1055. bottomY2 += lines[endLine + 1].leading;
  1056. }
  1057. bool flag8 = topY2 - bottomY2 > extents.y;
  1058. if (flag8)
  1059. {
  1060. break;
  1061. }
  1062. endLine++;
  1063. }
  1064. this.m_DrawEnd = UGUI_SCInputField.GetLineEndPosition(this.cachedInputTextGenerator, endLine);
  1065. while (startLine2 > 0)
  1066. {
  1067. topY2 = lines[startLine2 - 1].topY;
  1068. bool flag9 = topY2 - bottomY2 > extents.y;
  1069. if (flag9)
  1070. {
  1071. break;
  1072. }
  1073. startLine2--;
  1074. }
  1075. this.m_DrawStart = UGUI_SCInputField.GetLineStartPosition(this.cachedInputTextGenerator, startLine2);
  1076. }
  1077. }
  1078. else
  1079. {
  1080. IList<UICharInfo> characters = this.cachedInputTextGenerator.characters;
  1081. bool flag10 = this.m_DrawEnd > this.cachedInputTextGenerator.characterCountVisible;
  1082. if (flag10)
  1083. {
  1084. this.m_DrawEnd = this.cachedInputTextGenerator.characterCountVisible;
  1085. }
  1086. float width = 0f;
  1087. bool flag11 = caretPos > this.m_DrawEnd || (caretPos == this.m_DrawEnd && this.m_DrawStart > 0);
  1088. if (flag11)
  1089. {
  1090. this.m_DrawEnd = caretPos;
  1091. this.m_DrawStart = this.m_DrawEnd - 1;
  1092. while (this.m_DrawStart >= 0)
  1093. {
  1094. bool flag12 = width + characters[this.m_DrawStart].charWidth > extents.x;
  1095. if (flag12)
  1096. {
  1097. break;
  1098. }
  1099. width += characters[this.m_DrawStart].charWidth;
  1100. this.m_DrawStart--;
  1101. }
  1102. this.m_DrawStart++;
  1103. }
  1104. else
  1105. {
  1106. bool flag13 = caretPos < this.m_DrawStart;
  1107. if (flag13)
  1108. {
  1109. this.m_DrawStart = caretPos;
  1110. }
  1111. this.m_DrawEnd = this.m_DrawStart;
  1112. }
  1113. while (this.m_DrawEnd < this.cachedInputTextGenerator.characterCountVisible)
  1114. {
  1115. width += characters[this.m_DrawEnd].charWidth;
  1116. bool flag14 = width > extents.x;
  1117. if (flag14)
  1118. {
  1119. break;
  1120. }
  1121. this.m_DrawEnd++;
  1122. }
  1123. }
  1124. }
  1125. }
  1126. #if UNITY_EDITOR
  1127. protected override void MarkGeometryAsDirty()
  1128. {
  1129. bool flag = !Application.isPlaying || PrefabUtility.IsPartOfPrefabAsset(base.gameObject);
  1130. if (!flag)
  1131. {
  1132. CanvasUpdateRegistry.RegisterCanvasElementForGraphicRebuild(this);
  1133. }
  1134. }
  1135. #else
  1136. protected override void MarkGeometryAsDirty()
  1137. {
  1138. bool flag = !Application.isPlaying;
  1139. if (!flag)
  1140. {
  1141. CanvasUpdateRegistry.RegisterCanvasElementForGraphicRebuild(this);
  1142. }
  1143. }
  1144. #endif
  1145. protected override void UpdateGeometry()
  1146. {
  1147. bool flag = !Application.isPlaying;
  1148. if (!flag)
  1149. {
  1150. bool flag2 = !this.shouldHideMobileInput;
  1151. if (!flag2)
  1152. {
  1153. bool flag3 = this.m_CachedInputRenderer == null && this.m_TextComponent != null;
  1154. if (flag3)
  1155. {
  1156. GameObject go = new GameObject(base.transform.name + " Input Caret", new Type[]
  1157. {
  1158. typeof(RectTransform),
  1159. typeof(CanvasRenderer)
  1160. });
  1161. go.hideFlags = HideFlags.DontSave;
  1162. go.transform.SetParent(this.m_TextComponent.transform.parent);
  1163. go.transform.SetAsFirstSibling();
  1164. go.layer = base.gameObject.layer;
  1165. this.caretRectTrans = go.GetComponent<RectTransform>();
  1166. this.m_CachedInputRenderer = go.GetComponent<CanvasRenderer>();
  1167. this.m_CachedInputRenderer.SetMaterial(this.m_TextComponent.GetModifiedMaterial(Graphic.defaultGraphicMaterial), Texture2D.whiteTexture);
  1168. go.AddComponent<LayoutElement>().ignoreLayout = true;
  1169. this.AssignPositioningIfNeeded();
  1170. }
  1171. bool flag4 = this.m_CachedInputRenderer == null;
  1172. if (!flag4)
  1173. {
  1174. this.OnFillVBO(this.mesh);
  1175. this.m_CachedInputRenderer.SetMesh(this.mesh);
  1176. }
  1177. }
  1178. }
  1179. }
  1180. private void GenerateHighlight(VertexHelper vbo, Vector2 roundingOffset)
  1181. {
  1182. int startChar = Mathf.Max(0, this.caretPositionInternal - this.m_DrawStart);
  1183. int endChar = Mathf.Max(0, this.caretSelectPositionInternal - this.m_DrawStart);
  1184. bool flag = startChar > endChar;
  1185. if (flag)
  1186. {
  1187. int temp = startChar;
  1188. startChar = endChar;
  1189. endChar = temp;
  1190. }
  1191. endChar--;
  1192. TextGenerator gen = this.m_TextComponent.cachedTextGenerator;
  1193. bool flag2 = gen.lineCount <= 0;
  1194. if (!flag2)
  1195. {
  1196. int currentLineIndex = this.DetermineCharacterLine(startChar, gen);
  1197. int lastCharInLineIndex = UGUI_SCInputField.GetLineEndPosition(gen, currentLineIndex);
  1198. UIVertex vert = UIVertex.simpleVert;
  1199. vert.uv0 = Vector2.zero;
  1200. vert.color = this.selectionColor;
  1201. int currentChar = startChar;
  1202. while (currentChar <= endChar && currentChar < gen.characterCount)
  1203. {
  1204. bool flag3 = currentChar == lastCharInLineIndex || currentChar == endChar;
  1205. if (flag3)
  1206. {
  1207. UICharInfo startCharInfo = gen.characters[startChar];
  1208. UICharInfo endCharInfo = gen.characters[currentChar];
  1209. Vector2 startPosition = new Vector2(startCharInfo.cursorPos.x / this.m_TextComponent.pixelsPerUnit, gen.lines[currentLineIndex].topY / this.m_TextComponent.pixelsPerUnit);
  1210. Vector2 endPosition = new Vector2((endCharInfo.cursorPos.x + endCharInfo.charWidth) / this.m_TextComponent.pixelsPerUnit, startPosition.y - (float)gen.lines[currentLineIndex].height / this.m_TextComponent.pixelsPerUnit);
  1211. bool flag4 = endPosition.x > this.m_TextComponent.rectTransform.rect.xMax || endPosition.x < this.m_TextComponent.rectTransform.rect.xMin;
  1212. if (flag4)
  1213. {
  1214. endPosition.x = this.m_TextComponent.rectTransform.rect.xMax;
  1215. }
  1216. int startIndex = vbo.currentVertCount;
  1217. vert.position = new Vector3(startPosition.x, endPosition.y, 0f) + new Vector3(roundingOffset.x, roundingOffset.y, 0);
  1218. vbo.AddVert(vert);
  1219. vert.position = new Vector3(endPosition.x, endPosition.y, 0f) + new Vector3(roundingOffset.x, roundingOffset.y, 0);
  1220. vbo.AddVert(vert);
  1221. vert.position = new Vector3(endPosition.x, startPosition.y, 0f) + new Vector3(roundingOffset.x, roundingOffset.y, 0);
  1222. vbo.AddVert(vert);
  1223. vert.position = new Vector3(startPosition.x, startPosition.y, 0f) + new Vector3(roundingOffset.x, roundingOffset.y, 0);
  1224. vbo.AddVert(vert);
  1225. vbo.AddTriangle(startIndex, startIndex + 1, startIndex + 2);
  1226. vbo.AddTriangle(startIndex + 2, startIndex + 3, startIndex);
  1227. startChar = currentChar + 1;
  1228. currentLineIndex++;
  1229. lastCharInLineIndex = UGUI_SCInputField.GetLineEndPosition(gen, currentLineIndex);
  1230. }
  1231. currentChar++;
  1232. }
  1233. }
  1234. }
  1235. protected override char Validate(string text, int pos, char ch)
  1236. {
  1237. bool flag = this.characterValidation == UGUI_SCInputField.CharacterValidation.None || !base.enabled;
  1238. char result;
  1239. if (flag)
  1240. {
  1241. result = ch;
  1242. }
  1243. else
  1244. {
  1245. bool flag2 = this.characterValidation == UGUI_SCInputField.CharacterValidation.Integer || this.characterValidation == UGUI_SCInputField.CharacterValidation.Decimal;
  1246. if (flag2)
  1247. {
  1248. bool cursorBeforeDash = pos == 0 && text.Length > 0 && text[0] == '-';
  1249. bool dashInSelection = text.Length > 0 && text[0] == '-' && ((this.caretPositionInternal == 0 && this.caretSelectPositionInternal > 0) || (this.caretSelectPositionInternal == 0 && this.caretPositionInternal > 0));
  1250. bool selectionAtStart = this.caretPositionInternal == 0 || this.caretSelectPositionInternal == 0;
  1251. bool flag3 = !cursorBeforeDash || dashInSelection;
  1252. if (flag3)
  1253. {
  1254. bool flag4 = ch >= '0' && ch <= '9';
  1255. if (flag4)
  1256. {
  1257. return ch;
  1258. }
  1259. bool flag5 = ch == '-' && (pos == 0 || selectionAtStart);
  1260. if (flag5)
  1261. {
  1262. return ch;
  1263. }
  1264. bool flag6 = (ch == '.' || ch == ',') && this.characterValidation == UGUI_SCInputField.CharacterValidation.Decimal && text.IndexOfAny(new char[]
  1265. {
  1266. '.',
  1267. ','
  1268. }) == -1;
  1269. if (flag6)
  1270. {
  1271. return ch;
  1272. }
  1273. }
  1274. }
  1275. else
  1276. {
  1277. bool flag7 = this.characterValidation == UGUI_SCInputField.CharacterValidation.Alphanumeric;
  1278. if (flag7)
  1279. {
  1280. bool flag8 = ch >= 'A' && ch <= 'Z';
  1281. if (flag8)
  1282. {
  1283. return ch;
  1284. }
  1285. bool flag9 = ch >= 'a' && ch <= 'z';
  1286. if (flag9)
  1287. {
  1288. return ch;
  1289. }
  1290. bool flag10 = ch >= '0' && ch <= '9';
  1291. if (flag10)
  1292. {
  1293. return ch;
  1294. }
  1295. }
  1296. else
  1297. {
  1298. bool flag11 = this.characterValidation == UGUI_SCInputField.CharacterValidation.Name;
  1299. if (flag11)
  1300. {
  1301. bool flag12 = char.IsLetter(ch);
  1302. if (flag12)
  1303. {
  1304. bool flag13 = char.IsLower(ch) && (pos == 0 || text[pos - 1] == ' ');
  1305. if (flag13)
  1306. {
  1307. return char.ToUpper(ch);
  1308. }
  1309. bool flag14 = char.IsUpper(ch) && pos > 0 && text[pos - 1] != ' ' && text[pos - 1] != '\'';
  1310. if (flag14)
  1311. {
  1312. return char.ToLower(ch);
  1313. }
  1314. return ch;
  1315. }
  1316. else
  1317. {
  1318. bool flag15 = ch == '\'';
  1319. if (flag15)
  1320. {
  1321. bool flag16 = !text.Contains("'");
  1322. if (flag16)
  1323. {
  1324. bool flag17 = (pos <= 0 || (text[pos - 1] != ' ' && text[pos - 1] != '\'')) && (pos >= text.Length || (text[pos] != ' ' && text[pos] != '\''));
  1325. if (flag17)
  1326. {
  1327. return ch;
  1328. }
  1329. }
  1330. }
  1331. bool flag18 = ch == ' ';
  1332. if (flag18)
  1333. {
  1334. bool flag19 = pos != 0;
  1335. if (flag19)
  1336. {
  1337. bool flag20 = (pos <= 0 || (text[pos - 1] != ' ' && text[pos - 1] != '\'')) && (pos >= text.Length || (text[pos] != ' ' && text[pos] != '\''));
  1338. if (flag20)
  1339. {
  1340. return ch;
  1341. }
  1342. }
  1343. }
  1344. }
  1345. }
  1346. else
  1347. {
  1348. bool flag21 = this.characterValidation == UGUI_SCInputField.CharacterValidation.EmailAddress;
  1349. if (flag21)
  1350. {
  1351. bool flag22 = ch >= 'A' && ch <= 'Z';
  1352. if (flag22)
  1353. {
  1354. return ch;
  1355. }
  1356. bool flag23 = ch >= 'a' && ch <= 'z';
  1357. if (flag23)
  1358. {
  1359. return ch;
  1360. }
  1361. bool flag24 = ch >= '0' && ch <= '9';
  1362. if (flag24)
  1363. {
  1364. return ch;
  1365. }
  1366. bool flag25 = ch == '@' && text.IndexOf('@') == -1;
  1367. if (flag25)
  1368. {
  1369. return ch;
  1370. }
  1371. bool flag26 = "!#$%&'*+-/=?^_`{|}~".IndexOf(ch) != -1;
  1372. if (flag26)
  1373. {
  1374. return ch;
  1375. }
  1376. bool flag27 = ch == '.';
  1377. if (flag27)
  1378. {
  1379. char lastChar = (text.Length > 0) ? text[Mathf.Clamp(pos, 0, text.Length - 1)] : ' ';
  1380. char nextChar = (text.Length > 0) ? text[Mathf.Clamp(pos + 1, 0, text.Length - 1)] : '\n';
  1381. bool flag28 = lastChar != '.' && nextChar != '.';
  1382. if (flag28)
  1383. {
  1384. return ch;
  1385. }
  1386. }
  1387. }
  1388. }
  1389. }
  1390. }
  1391. result = '\0';
  1392. }
  1393. return result;
  1394. }
  1395. public override void ActivateInputField()
  1396. {
  1397. bool flag = this.m_TextComponent == null || this.m_TextComponent.font == null || !this.IsActive() || !this.IsInteractable();
  1398. if (!flag)
  1399. {
  1400. bool isFocused = this.isFocused;
  1401. if (isFocused)
  1402. {
  1403. bool flag2 = this.m_Keyboard != null && !this.m_Keyboard.active;
  1404. if (flag2)
  1405. {
  1406. this.m_Keyboard.active = true;
  1407. this.m_Keyboard.text = this.m_Text;
  1408. }
  1409. }
  1410. this.m_ShouldActivateNextUpdate = true;
  1411. }
  1412. }
  1413. protected override void ActivateInputFieldInternal()
  1414. {
  1415. bool flag = EventSystem.current == null;
  1416. if (!flag)
  1417. {
  1418. bool flag2 = EventSystem.current.currentSelectedGameObject != base.gameObject;
  1419. if (flag2)
  1420. {
  1421. EventSystem.current.SetSelectedGameObject(base.gameObject);
  1422. }
  1423. #if SCKeyboard
  1424. bool isSupported = SCKeyboard.isSupported;
  1425. #elif TouchScreenKeyboard
  1426. bool isSupported = TouchScreenKeyboard.isSupported;
  1427. #endif
  1428. if (isSupported)
  1429. {
  1430. bool touchSupported = this.input.touchSupported;
  1431. if (touchSupported)
  1432. {
  1433. #if SCKeyboard
  1434. SCKeyboard.hideInput = this.shouldHideMobileInput;
  1435. #elif TouchScreenKeyboard
  1436. TouchScreenKeyboard.hideInput = this.shouldHideMobileInput;
  1437. #endif
  1438. }
  1439. #if SCKeyboard
  1440. // Set SCKeyboard Transform
  1441. m_Keyboard = SetKeyboardTransform();
  1442. // Set SCKeyboard Order In Layer
  1443. SetKeyboardOrderInLayer(m_OrderInLayer);
  1444. // Set Keyboard Regist Events
  1445. SetKeyboardRegistEvents(m_Keyboard);
  1446. //m_Keyboard.SetTextOnOpen(text);
  1447. this.m_TouchKeyboardAllowsInPlaceEditing = SCKeyboard.isInPlaceEditingAllowed;
  1448. #elif TouchScreenKeyboard
  1449. this.m_Keyboard = ((this.inputType == UGUI_SCInputField.InputType.Password) ? TouchScreenKeyboard.Open(this.m_Text, this.keyboardType, false, this.multiLine, true, false, "", this.characterLimit) : TouchScreenKeyboard.Open(this.m_Text, this.keyboardType, this.inputType == UGUI_SCInputField.InputType.AutoCorrect, this.multiLine, false, false, "", this.characterLimit));
  1450. this.m_TouchKeyboardAllowsInPlaceEditing = TouchScreenKeyboard.isInPlaceEditingAllowed;
  1451. #endif
  1452. this.MoveTextEnd(false);
  1453. }
  1454. else
  1455. {
  1456. this.input.imeCompositionMode = IMECompositionMode.On;
  1457. this.OnFocus();
  1458. }
  1459. this.m_AllowInput = true;
  1460. this.m_OriginalText = this.text;
  1461. this.m_WasCanceled = false;
  1462. this.SetCaretVisible();
  1463. this.UpdateLabel();
  1464. }
  1465. }
  1466. public override void OnPointerClick(PointerEventData eventData)
  1467. {
  1468. bool flag = eventData.button > PointerEventData.InputButton.Left;
  1469. if (!flag)
  1470. {
  1471. this.ActivateInputField();
  1472. }
  1473. }
  1474. public override void DeactivateInputField()
  1475. {
  1476. bool flag = !this.m_AllowInput;
  1477. if (!flag)
  1478. {
  1479. this.m_HasDoneFocusTransition = false;
  1480. this.m_AllowInput = false;
  1481. bool flag2 = this.m_Placeholder != null;
  1482. if (flag2)
  1483. {
  1484. this.m_Placeholder.enabled = string.IsNullOrEmpty(this.m_Text);
  1485. }
  1486. bool flag3 = this.m_TextComponent != null && this.IsInteractable();
  1487. if (flag3)
  1488. {
  1489. bool wasCanceled = this.m_WasCanceled;
  1490. if (wasCanceled)
  1491. {
  1492. this.text = this.m_OriginalText;
  1493. }
  1494. this.SendOnSubmit();
  1495. bool flag4 = this.m_Keyboard != null;
  1496. if (flag4)
  1497. {
  1498. this.m_Keyboard.active = false;
  1499. this.m_Keyboard = null;
  1500. }
  1501. this.m_CaretPosition = (this.m_CaretSelectPosition = 0);
  1502. if (this.input != null) this.input.imeCompositionMode = IMECompositionMode.Auto;
  1503. }
  1504. this.MarkGeometryAsDirty();
  1505. }
  1506. }
  1507. public override void OnDeselect(BaseEventData eventData)
  1508. {
  1509. if (shouldDeactivateOnDeselect)
  1510. {
  1511. //this.DeactivateInputField();
  1512. base.OnDeselect(eventData);
  1513. }
  1514. }
  1515. protected override void DoStateTransition(Selectable.SelectionState state, bool instant)
  1516. {
  1517. bool hasDoneFocusTransition = this.m_HasDoneFocusTransition;
  1518. if (hasDoneFocusTransition)
  1519. {
  1520. state = Selectable.SelectionState.Selected;
  1521. }
  1522. else
  1523. {
  1524. bool flag = state == Selectable.SelectionState.Pressed;
  1525. if (flag)
  1526. {
  1527. this.m_HasDoneFocusTransition = true;
  1528. }
  1529. }
  1530. base.DoStateTransition(state, instant);
  1531. }
  1532. //Transform ICanvasElement.get_transform()
  1533. //{
  1534. // return base.transform;
  1535. //}
  1536. #if SCKeyboard
  1537. protected new SCKeyboard m_Keyboard;
  1538. #elif TouchScreenKeyboard
  1539. protected TouchScreenKeyboard m_Keyboard;
  1540. #endif
  1541. private bool m_ShouldDeactivateNextUpdate = false;
  1542. private WaitForSecondsRealtime m_WaitForSecondsRealtime;
  1543. private bool m_TouchKeyboardAllowsInPlaceEditing = false;
  1544. private const int k_MaxTextLength = 16382;
  1545. #region SCKeyboard
  1546. [SerializeField]
  1547. public SCKeyboardType m_SCKeyboardType = SCKeyboardType.Default;
  1548. [SerializeField]
  1549. public SCKeyboardSpaceEnum m_SCKeyboardSpaceEnum = SCKeyboardSpaceEnum.WorldSpace;
  1550. [SerializeField]
  1551. protected float m_CustomDistance = 1.0f;
  1552. [SerializeField]
  1553. protected Vector2 m_CustomOffset = Vector2.down * 0.2f;
  1554. [SerializeField]
  1555. protected bool m_UseCustomOrderInLayer = false;
  1556. [SerializeField]
  1557. protected int m_OrderInLayer = 10;
  1558. #endregion
  1559. public void SetKeyboardLocalTransform(Vector3 position, Quaternion rotation, Vector3 localScale)
  1560. {
  1561. m_UseCustomTransform = true;
  1562. m_SCKeyboardSpaceEnum = SCKeyboardSpaceEnum.LocalSpace;
  1563. m_CustomPosition = position;
  1564. m_CustomRotation = rotation.eulerAngles;
  1565. m_CustomLocalScale = localScale;
  1566. ResetKeyboardTransform();
  1567. }
  1568. public void SetKeyboardWorldTransform(Vector3 position, Quaternion rotation, Vector3 localScale)
  1569. {
  1570. m_UseCustomTransform = true;
  1571. m_SCKeyboardSpaceEnum = SCKeyboardSpaceEnum.WorldSpace;
  1572. m_CustomPosition = position;
  1573. m_CustomRotation = rotation.eulerAngles;
  1574. m_CustomLocalScale = localScale;
  1575. ResetKeyboardTransform();
  1576. }
  1577. public void SetKeyboardOriginTransform(float distance, Vector2 offset, Quaternion rotation, Vector3 localScale)
  1578. {
  1579. m_UseCustomTransform = true;
  1580. m_SCKeyboardSpaceEnum = SCKeyboardSpaceEnum.OriginSpace;
  1581. m_CustomDistance = distance;
  1582. m_CustomOffset = offset;
  1583. m_CustomRotation = rotation.eulerAngles;
  1584. m_CustomLocalScale = localScale;
  1585. ResetKeyboardTransform();
  1586. }
  1587. public virtual void ResetKeyboardTransform()
  1588. {
  1589. if (m_Keyboard != null)
  1590. {
  1591. SetKeyboardTransform();
  1592. }
  1593. }
  1594. private SCKeyboard SetKeyboardTransform()
  1595. {
  1596. SCKeyboard scKeyboard;
  1597. Vector3 position = Vector3.zero;
  1598. Quaternion rotation = Quaternion.identity;
  1599. Vector3 localScale = Vector3.one;
  1600. GetKeyboardTransform(ref position, ref rotation, ref localScale);
  1601. scKeyboard = SCKeyboard.Open(this.scKeyboardEnum, m_Text, this.scKeyboardType, position, rotation, localScale);
  1602. scKeyboard.transform.SetParent(this.transform);
  1603. return scKeyboard;
  1604. }
  1605. private void SetKeyboardRegistEvents(SCKeyboard scKeyboard)
  1606. {
  1607. scKeyboard.Clear();
  1608. scKeyboard.RegisterOnKeyClickEvent((str) => { Append(str); this.UpdateLabel(); });
  1609. scKeyboard.RegisterOnSpecialKeyClickEvent(Module_Keyboard.SpecialKeyEnum.Delete, Backspace);
  1610. }
  1611. private void GetKeyboardTransform(ref Vector3 position, ref Quaternion rotation, ref Vector3 localScale)
  1612. {
  1613. Transform head = Camera.main.transform.transform;
  1614. if (m_UseCustomTransform)
  1615. {
  1616. switch (m_SCKeyboardSpaceEnum)
  1617. {
  1618. case SCKeyboardSpaceEnum.OriginSpace:
  1619. Vector3 direction = Vector3.ProjectOnPlane(head.forward, Vector3.up);
  1620. position = head.position + direction * m_CustomDistance + (Vector3)m_CustomOffset;
  1621. rotation = Quaternion.AngleAxis(head.rotation.eulerAngles.y, Vector3.up) * Quaternion.Euler(m_CustomRotation);
  1622. localScale = m_CustomLocalScale;
  1623. break;
  1624. case SCKeyboardSpaceEnum.WorldSpace:
  1625. case SCKeyboardSpaceEnum.LocalSpace:
  1626. position = m_CustomPosition;
  1627. rotation = Quaternion.Euler(m_CustomRotation);
  1628. localScale = m_CustomLocalScale;
  1629. break;
  1630. }
  1631. }
  1632. else
  1633. {
  1634. Vector3 direction = Vector3.ProjectOnPlane(head.forward, Vector3.up);
  1635. position = head.position + direction * 1 + Vector3.down * 0.2f;
  1636. rotation = Quaternion.AngleAxis(head.rotation.eulerAngles.y, Vector3.up) * Quaternion.Euler(Vector3.right * 30);
  1637. localScale = Vector3.one;
  1638. }
  1639. }
  1640. private void SetKeyboardOrderInLayer(int value)
  1641. {
  1642. switch (m_SCKeyboardEnum)
  1643. {
  1644. case SCKeyboardEnum.SCKeyboard2D:
  1645. Canvas canvas = m_Keyboard.transform.GetComponentInChildren<Canvas>();
  1646. canvas.overrideSorting = true;
  1647. canvas.sortingOrder = value;
  1648. break;
  1649. case SCKeyboardEnum.SCKeyboard3D:
  1650. break;
  1651. }
  1652. }
  1653. }
  1654. #region SCKeyboard
  1655. [Serializable]
  1656. public enum SCKeyboardSpaceEnum
  1657. {
  1658. OriginSpace = 0,
  1659. WorldSpace = 1,
  1660. LocalSpace = 2
  1661. }
  1662. #endregion
  1663. }