UILabel.cs 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using I2.Loc;
  5. using UnityEngine;
  6. [ExecuteInEditMode]
  7. [AddComponentMenu("NGUI/UI/NGUI Label")]
  8. public class UILabel : UIWidget
  9. {
  10. private bool shouldBeProcessed
  11. {
  12. get
  13. {
  14. return this.mShouldBeProcessed;
  15. }
  16. set
  17. {
  18. if (value)
  19. {
  20. this.mChanged = true;
  21. this.mShouldBeProcessed = true;
  22. }
  23. else
  24. {
  25. this.mShouldBeProcessed = false;
  26. }
  27. }
  28. }
  29. public override bool isAnchoredHorizontally
  30. {
  31. get
  32. {
  33. return base.isAnchoredHorizontally || this.mOverflow == UILabel.Overflow.ResizeFreely;
  34. }
  35. }
  36. public override bool isAnchoredVertically
  37. {
  38. get
  39. {
  40. return base.isAnchoredVertically || this.mOverflow == UILabel.Overflow.ResizeFreely || this.mOverflow == UILabel.Overflow.ResizeHeight;
  41. }
  42. }
  43. public override Material material
  44. {
  45. get
  46. {
  47. if (this.mMaterial != null)
  48. {
  49. return this.mMaterial;
  50. }
  51. if (this.mFont != null)
  52. {
  53. return this.mFont.material;
  54. }
  55. if (this.mTrueTypeFont != null)
  56. {
  57. return this.mTrueTypeFont.material;
  58. }
  59. return null;
  60. }
  61. set
  62. {
  63. if (this.mMaterial != value)
  64. {
  65. base.RemoveFromPanel();
  66. this.mMaterial = value;
  67. this.MarkAsChanged();
  68. }
  69. }
  70. }
  71. [Obsolete("Use UILabel.bitmapFont instead")]
  72. public UIFont font
  73. {
  74. get
  75. {
  76. return this.bitmapFont;
  77. }
  78. set
  79. {
  80. this.bitmapFont = value;
  81. }
  82. }
  83. public UIFont bitmapFont
  84. {
  85. get
  86. {
  87. return this.mFont;
  88. }
  89. set
  90. {
  91. if (this.mFont != value)
  92. {
  93. base.RemoveFromPanel();
  94. this.mFont = value;
  95. this.mTrueTypeFont = null;
  96. this.MarkAsChanged();
  97. }
  98. }
  99. }
  100. public Font trueTypeFont
  101. {
  102. get
  103. {
  104. if (this.mTrueTypeFont != null)
  105. {
  106. return this.mTrueTypeFont;
  107. }
  108. return (!(this.mFont != null)) ? null : this.mFont.dynamicFont;
  109. }
  110. set
  111. {
  112. if (this.mTrueTypeFont != value)
  113. {
  114. this.SetActiveFont(null);
  115. base.RemoveFromPanel();
  116. this.mTrueTypeFont = value;
  117. this.shouldBeProcessed = true;
  118. this.mFont = null;
  119. this.SetActiveFont(value);
  120. this.ProcessAndRequest();
  121. if (this.mActiveTTF != null)
  122. {
  123. base.MarkAsChanged();
  124. }
  125. }
  126. }
  127. }
  128. public UnityEngine.Object ambigiousFont
  129. {
  130. get
  131. {
  132. return (!(this.mFont != null)) ? this.mTrueTypeFont : this.mFont;
  133. }
  134. set
  135. {
  136. UIFont uifont = value as UIFont;
  137. if (uifont != null)
  138. {
  139. this.bitmapFont = uifont;
  140. }
  141. else
  142. {
  143. this.trueTypeFont = (value as Font);
  144. }
  145. }
  146. }
  147. public string text
  148. {
  149. get
  150. {
  151. return this.mText;
  152. }
  153. set
  154. {
  155. if (this.mText == value)
  156. {
  157. return;
  158. }
  159. if (string.IsNullOrEmpty(value))
  160. {
  161. if (!string.IsNullOrEmpty(this.mText))
  162. {
  163. this.mText = string.Empty;
  164. this.MarkAsChanged();
  165. this.ProcessAndRequest();
  166. }
  167. }
  168. else if (this.mText != value)
  169. {
  170. this.mText = value;
  171. this.MarkAsChanged();
  172. this.ProcessAndRequest();
  173. }
  174. if (this.autoResizeBoxCollider)
  175. {
  176. base.ResizeCollider();
  177. }
  178. }
  179. }
  180. public int defaultFontSize
  181. {
  182. get
  183. {
  184. return (!(this.trueTypeFont != null)) ? ((!(this.mFont != null)) ? 16 : this.mFont.defaultSize) : this.mFontSize;
  185. }
  186. }
  187. public int fontSize
  188. {
  189. get
  190. {
  191. return this.mFontSize;
  192. }
  193. set
  194. {
  195. value = Mathf.Clamp(value, 0, 256);
  196. if (this.mFontSize != value)
  197. {
  198. this.mFontSize = value;
  199. this.shouldBeProcessed = true;
  200. this.ProcessAndRequest();
  201. }
  202. }
  203. }
  204. public FontStyle fontStyle
  205. {
  206. get
  207. {
  208. return this.mFontStyle;
  209. }
  210. set
  211. {
  212. if (this.mFontStyle != value)
  213. {
  214. this.mFontStyle = value;
  215. this.shouldBeProcessed = true;
  216. this.ProcessAndRequest();
  217. }
  218. }
  219. }
  220. public NGUIText.Alignment alignment
  221. {
  222. get
  223. {
  224. return this.mAlignment;
  225. }
  226. set
  227. {
  228. if (this.mAlignment != value)
  229. {
  230. this.mAlignment = value;
  231. this.shouldBeProcessed = true;
  232. this.ProcessAndRequest();
  233. }
  234. }
  235. }
  236. public bool applyGradient
  237. {
  238. get
  239. {
  240. return this.mApplyGradient;
  241. }
  242. set
  243. {
  244. if (this.mApplyGradient != value)
  245. {
  246. this.mApplyGradient = value;
  247. this.MarkAsChanged();
  248. }
  249. }
  250. }
  251. public Color gradientTop
  252. {
  253. get
  254. {
  255. return this.mGradientTop;
  256. }
  257. set
  258. {
  259. if (this.mGradientTop != value)
  260. {
  261. this.mGradientTop = value;
  262. if (this.mApplyGradient)
  263. {
  264. this.MarkAsChanged();
  265. }
  266. }
  267. }
  268. }
  269. public Color gradientBottom
  270. {
  271. get
  272. {
  273. return this.mGradientBottom;
  274. }
  275. set
  276. {
  277. if (this.mGradientBottom != value)
  278. {
  279. this.mGradientBottom = value;
  280. if (this.mApplyGradient)
  281. {
  282. this.MarkAsChanged();
  283. }
  284. }
  285. }
  286. }
  287. public int spacingX
  288. {
  289. get
  290. {
  291. return this.mSpacingX;
  292. }
  293. set
  294. {
  295. if (this.mSpacingX != value)
  296. {
  297. this.mSpacingX = value;
  298. this.MarkAsChanged();
  299. }
  300. }
  301. }
  302. public int spacingY
  303. {
  304. get
  305. {
  306. return this.mSpacingY;
  307. }
  308. set
  309. {
  310. if (this.mSpacingY != value)
  311. {
  312. this.mSpacingY = value;
  313. this.MarkAsChanged();
  314. }
  315. }
  316. }
  317. public bool useFloatSpacing
  318. {
  319. get
  320. {
  321. return this.mUseFloatSpacing;
  322. }
  323. set
  324. {
  325. if (this.mUseFloatSpacing != value)
  326. {
  327. this.mUseFloatSpacing = value;
  328. this.shouldBeProcessed = true;
  329. }
  330. }
  331. }
  332. public float floatSpacingX
  333. {
  334. get
  335. {
  336. return this.mFloatSpacingX;
  337. }
  338. set
  339. {
  340. if (!Mathf.Approximately(this.mFloatSpacingX, value))
  341. {
  342. this.mFloatSpacingX = value;
  343. this.MarkAsChanged();
  344. }
  345. }
  346. }
  347. public float floatSpacingY
  348. {
  349. get
  350. {
  351. return this.mFloatSpacingY;
  352. }
  353. set
  354. {
  355. if (!Mathf.Approximately(this.mFloatSpacingY, value))
  356. {
  357. this.mFloatSpacingY = value;
  358. this.MarkAsChanged();
  359. }
  360. }
  361. }
  362. public float effectiveSpacingY
  363. {
  364. get
  365. {
  366. return (!this.mUseFloatSpacing) ? ((float)this.mSpacingY) : this.mFloatSpacingY;
  367. }
  368. }
  369. public float effectiveSpacingX
  370. {
  371. get
  372. {
  373. return (!this.mUseFloatSpacing) ? ((float)this.mSpacingX) : this.mFloatSpacingX;
  374. }
  375. }
  376. private bool keepCrisp
  377. {
  378. get
  379. {
  380. return this.trueTypeFont != null && this.keepCrispWhenShrunk != UILabel.Crispness.Never;
  381. }
  382. }
  383. public bool supportEncoding
  384. {
  385. get
  386. {
  387. return this.mEncoding;
  388. }
  389. set
  390. {
  391. if (this.mEncoding != value)
  392. {
  393. this.mEncoding = value;
  394. this.shouldBeProcessed = true;
  395. }
  396. }
  397. }
  398. public NGUIText.SymbolStyle symbolStyle
  399. {
  400. get
  401. {
  402. return this.mSymbols;
  403. }
  404. set
  405. {
  406. if (this.mSymbols != value)
  407. {
  408. this.mSymbols = value;
  409. this.shouldBeProcessed = true;
  410. }
  411. }
  412. }
  413. public UILabel.Overflow overflowMethod
  414. {
  415. get
  416. {
  417. return this.mOverflow;
  418. }
  419. set
  420. {
  421. if (this.mOverflow != value)
  422. {
  423. this.mOverflow = value;
  424. this.shouldBeProcessed = true;
  425. }
  426. }
  427. }
  428. [Obsolete("Use 'width' instead")]
  429. public int lineWidth
  430. {
  431. get
  432. {
  433. return base.width;
  434. }
  435. set
  436. {
  437. base.width = value;
  438. }
  439. }
  440. [Obsolete("Use 'height' instead")]
  441. public int lineHeight
  442. {
  443. get
  444. {
  445. return base.height;
  446. }
  447. set
  448. {
  449. base.height = value;
  450. }
  451. }
  452. public bool multiLine
  453. {
  454. get
  455. {
  456. return this.mMaxLineCount != 1;
  457. }
  458. set
  459. {
  460. if (this.mMaxLineCount != 1 != value)
  461. {
  462. this.mMaxLineCount = ((!value) ? 1 : 0);
  463. this.shouldBeProcessed = true;
  464. }
  465. }
  466. }
  467. public override Vector3[] localCorners
  468. {
  469. get
  470. {
  471. if (this.shouldBeProcessed)
  472. {
  473. this.ProcessText();
  474. }
  475. return base.localCorners;
  476. }
  477. }
  478. public override Vector3[] worldCorners
  479. {
  480. get
  481. {
  482. if (this.shouldBeProcessed)
  483. {
  484. this.ProcessText();
  485. }
  486. return base.worldCorners;
  487. }
  488. }
  489. public override Vector4 drawingDimensions
  490. {
  491. get
  492. {
  493. if (this.shouldBeProcessed)
  494. {
  495. this.ProcessText();
  496. }
  497. return base.drawingDimensions;
  498. }
  499. }
  500. public int maxLineCount
  501. {
  502. get
  503. {
  504. return this.mMaxLineCount;
  505. }
  506. set
  507. {
  508. if (this.mMaxLineCount != value)
  509. {
  510. this.mMaxLineCount = Mathf.Max(value, 0);
  511. this.shouldBeProcessed = true;
  512. if (this.overflowMethod == UILabel.Overflow.ShrinkContent)
  513. {
  514. this.MakePixelPerfect();
  515. }
  516. }
  517. }
  518. }
  519. public UILabel.Effect effectStyle
  520. {
  521. get
  522. {
  523. return this.mEffectStyle;
  524. }
  525. set
  526. {
  527. if (this.mEffectStyle != value)
  528. {
  529. this.mEffectStyle = value;
  530. this.shouldBeProcessed = true;
  531. }
  532. }
  533. }
  534. public Color effectColor
  535. {
  536. get
  537. {
  538. return this.mEffectColor;
  539. }
  540. set
  541. {
  542. if (this.mEffectColor != value)
  543. {
  544. this.mEffectColor = value;
  545. if (this.mEffectStyle != UILabel.Effect.None)
  546. {
  547. this.shouldBeProcessed = true;
  548. }
  549. }
  550. }
  551. }
  552. public Vector2 effectDistance
  553. {
  554. get
  555. {
  556. return this.mEffectDistance;
  557. }
  558. set
  559. {
  560. if (this.mEffectDistance != value)
  561. {
  562. this.mEffectDistance = value;
  563. this.shouldBeProcessed = true;
  564. }
  565. }
  566. }
  567. [Obsolete("Use 'overflowMethod == UILabel.Overflow.ShrinkContent' instead")]
  568. public bool shrinkToFit
  569. {
  570. get
  571. {
  572. return this.mOverflow == UILabel.Overflow.ShrinkContent;
  573. }
  574. set
  575. {
  576. if (value)
  577. {
  578. this.overflowMethod = UILabel.Overflow.ShrinkContent;
  579. }
  580. }
  581. }
  582. public string processedText
  583. {
  584. get
  585. {
  586. if (this.mLastWidth != this.mWidth || this.mLastHeight != this.mHeight)
  587. {
  588. this.mLastWidth = this.mWidth;
  589. this.mLastHeight = this.mHeight;
  590. this.mShouldBeProcessed = true;
  591. }
  592. if (this.shouldBeProcessed)
  593. {
  594. this.ProcessText();
  595. }
  596. return this.mProcessedText;
  597. }
  598. }
  599. public Vector2 printedSize
  600. {
  601. get
  602. {
  603. if (this.shouldBeProcessed)
  604. {
  605. this.ProcessText();
  606. }
  607. return this.mCalculatedSize;
  608. }
  609. }
  610. public override Vector2 localSize
  611. {
  612. get
  613. {
  614. if (this.shouldBeProcessed)
  615. {
  616. this.ProcessText();
  617. }
  618. return base.localSize;
  619. }
  620. }
  621. private bool isValid
  622. {
  623. get
  624. {
  625. return this.mFont != null || this.mTrueTypeFont != null;
  626. }
  627. }
  628. protected override void OnInit()
  629. {
  630. base.OnInit();
  631. UILabel.mList.Add(this);
  632. this.SetActiveFont(this.trueTypeFont);
  633. }
  634. protected override void OnDisable()
  635. {
  636. this.SetActiveFont(null);
  637. UILabel.mList.Remove(this);
  638. base.OnDisable();
  639. }
  640. protected void SetActiveFont(Font fnt)
  641. {
  642. if (this.mActiveTTF != fnt)
  643. {
  644. if (this.mActiveTTF != null)
  645. {
  646. int num;
  647. if (UILabel.mFontUsage.TryGetValue(this.mActiveTTF, out num))
  648. {
  649. num = Mathf.Max(0, --num);
  650. if (num == 0)
  651. {
  652. this.mActiveTTF.textureRebuildCallback = null;
  653. UILabel.mFontUsage.Remove(this.mActiveTTF);
  654. }
  655. else
  656. {
  657. UILabel.mFontUsage[this.mActiveTTF] = num;
  658. }
  659. }
  660. else
  661. {
  662. this.mActiveTTF.textureRebuildCallback = null;
  663. }
  664. }
  665. this.mActiveTTF = fnt;
  666. if (this.mActiveTTF != null)
  667. {
  668. int num2 = 0;
  669. if (!UILabel.mFontUsage.TryGetValue(this.mActiveTTF, out num2))
  670. {
  671. Font font = this.mActiveTTF;
  672. if (UILabel.<>f__mg$cache0 == null)
  673. {
  674. UILabel.<>f__mg$cache0 = new Font.FontTextureRebuildCallback(UILabel.OnFontTextureChanged);
  675. }
  676. font.textureRebuildCallback = UILabel.<>f__mg$cache0;
  677. }
  678. num2 = (UILabel.mFontUsage[this.mActiveTTF] = num2 + 1);
  679. }
  680. }
  681. }
  682. public static void OnFontTextureChanged()
  683. {
  684. for (int i = 0; i < UILabel.mList.size; i++)
  685. {
  686. UILabel uilabel = UILabel.mList[i];
  687. if (uilabel != null)
  688. {
  689. Font trueTypeFont = uilabel.trueTypeFont;
  690. if (trueTypeFont != null)
  691. {
  692. trueTypeFont.RequestCharactersInTexture(uilabel.mText, uilabel.mPrintedSize, uilabel.mFontStyle);
  693. }
  694. }
  695. }
  696. for (int j = 0; j < UILabel.mList.size; j++)
  697. {
  698. UILabel uilabel2 = UILabel.mList[j];
  699. if (uilabel2 != null)
  700. {
  701. Font trueTypeFont2 = uilabel2.trueTypeFont;
  702. if (trueTypeFont2 != null)
  703. {
  704. uilabel2.RemoveFromPanel();
  705. uilabel2.CreatePanel();
  706. }
  707. }
  708. }
  709. }
  710. public override Vector3[] GetSides(Transform relativeTo)
  711. {
  712. if (this.shouldBeProcessed)
  713. {
  714. this.ProcessText();
  715. }
  716. return base.GetSides(relativeTo);
  717. }
  718. protected override void UpgradeFrom265()
  719. {
  720. this.ProcessText(true, true);
  721. if (this.mShrinkToFit)
  722. {
  723. this.overflowMethod = UILabel.Overflow.ShrinkContent;
  724. this.mMaxLineCount = 0;
  725. }
  726. if (this.mMaxLineWidth != 0)
  727. {
  728. base.width = this.mMaxLineWidth;
  729. this.overflowMethod = ((this.mMaxLineCount <= 0) ? UILabel.Overflow.ShrinkContent : UILabel.Overflow.ResizeHeight);
  730. }
  731. else
  732. {
  733. this.overflowMethod = UILabel.Overflow.ResizeFreely;
  734. }
  735. if (this.mMaxLineHeight != 0)
  736. {
  737. base.height = this.mMaxLineHeight;
  738. }
  739. if (this.mFont != null)
  740. {
  741. int defaultSize = this.mFont.defaultSize;
  742. if (base.height < defaultSize)
  743. {
  744. base.height = defaultSize;
  745. }
  746. this.fontSize = defaultSize;
  747. }
  748. this.mMaxLineWidth = 0;
  749. this.mMaxLineHeight = 0;
  750. this.mShrinkToFit = false;
  751. NGUITools.UpdateWidgetCollider(base.gameObject, true);
  752. }
  753. protected override void OnAnchor()
  754. {
  755. if (this.mOverflow == UILabel.Overflow.ResizeFreely)
  756. {
  757. if (base.isFullyAnchored)
  758. {
  759. this.mOverflow = UILabel.Overflow.ShrinkContent;
  760. }
  761. }
  762. else if (this.mOverflow == UILabel.Overflow.ResizeHeight && this.topAnchor.target != null && this.bottomAnchor.target != null)
  763. {
  764. this.mOverflow = UILabel.Overflow.ShrinkContent;
  765. }
  766. base.OnAnchor();
  767. }
  768. private void ProcessAndRequest()
  769. {
  770. if (this.ambigiousFont != null)
  771. {
  772. this.ProcessText();
  773. }
  774. }
  775. protected override void OnStart()
  776. {
  777. base.OnStart();
  778. if (this.mLineWidth > 0f)
  779. {
  780. this.mMaxLineWidth = Mathf.RoundToInt(this.mLineWidth);
  781. this.mLineWidth = 0f;
  782. }
  783. if (!this.mMultiline)
  784. {
  785. this.mMaxLineCount = 1;
  786. this.mMultiline = true;
  787. }
  788. this.mPremultiply = (this.material != null && this.material.shader != null && this.material.shader.name.Contains("Premultiplied"));
  789. this.ProcessAndRequest();
  790. }
  791. public override void MarkAsChanged()
  792. {
  793. this.shouldBeProcessed = true;
  794. base.MarkAsChanged();
  795. }
  796. public void ProcessText()
  797. {
  798. this.ProcessText(false, true);
  799. }
  800. private void ProcessText(bool legacyMode, bool full)
  801. {
  802. if (!this.isValid)
  803. {
  804. return;
  805. }
  806. this.mChanged = true;
  807. this.shouldBeProcessed = false;
  808. float num = this.mDrawRegion.z - this.mDrawRegion.x;
  809. float num2 = this.mDrawRegion.w - this.mDrawRegion.y;
  810. NGUIText.rectWidth = ((!legacyMode) ? base.width : ((this.mMaxLineWidth == 0) ? 1000000 : this.mMaxLineWidth));
  811. NGUIText.rectHeight = ((!legacyMode) ? base.height : ((this.mMaxLineHeight == 0) ? 1000000 : this.mMaxLineHeight));
  812. NGUIText.regionWidth = ((num == 1f) ? NGUIText.rectWidth : Mathf.RoundToInt((float)NGUIText.rectWidth * num));
  813. NGUIText.regionHeight = ((num2 == 1f) ? NGUIText.rectHeight : Mathf.RoundToInt((float)NGUIText.rectHeight * num2));
  814. this.mPrintedSize = Mathf.Abs((!legacyMode) ? this.defaultFontSize : Mathf.RoundToInt(base.cachedTransform.localScale.x));
  815. this.mScale = 1f;
  816. if (NGUIText.regionWidth < 1 || NGUIText.regionHeight < 0)
  817. {
  818. this.mProcessedText = string.Empty;
  819. return;
  820. }
  821. bool flag = this.trueTypeFont != null;
  822. if (flag && this.keepCrisp)
  823. {
  824. UIRoot root = base.root;
  825. if (root != null)
  826. {
  827. this.mDensity = ((!(root != null)) ? 1f : root.pixelSizeAdjustment);
  828. }
  829. }
  830. else
  831. {
  832. this.mDensity = 1f;
  833. }
  834. if (full)
  835. {
  836. this.UpdateNGUIText();
  837. }
  838. if (this.mOverflow == UILabel.Overflow.ResizeFreely)
  839. {
  840. NGUIText.rectWidth = 1000000;
  841. NGUIText.regionWidth = 1000000;
  842. }
  843. if (this.mOverflow == UILabel.Overflow.ResizeFreely || this.mOverflow == UILabel.Overflow.ResizeHeight)
  844. {
  845. NGUIText.rectHeight = 1000000;
  846. NGUIText.regionHeight = 1000000;
  847. }
  848. if (this.mPrintedSize > 0)
  849. {
  850. bool keepCrisp = this.keepCrisp;
  851. for (int i = this.mPrintedSize; i > 0; i--)
  852. {
  853. if (keepCrisp)
  854. {
  855. this.mPrintedSize = i;
  856. NGUIText.fontSize = this.mPrintedSize;
  857. }
  858. else
  859. {
  860. this.mScale = (float)i / (float)this.mPrintedSize;
  861. NGUIText.fontScale = ((!flag) ? ((float)this.mFontSize / (float)this.mFont.defaultSize * this.mScale) : this.mScale);
  862. }
  863. NGUIText.Update(false);
  864. bool flag2 = NGUIText.WrapText(this.mText, out this.mProcessedText, true);
  865. if (this.mOverflow != UILabel.Overflow.ShrinkContent || flag2)
  866. {
  867. if (this.mOverflow == UILabel.Overflow.ResizeFreely)
  868. {
  869. this.mCalculatedSize = NGUIText.CalculatePrintedSize(this.mProcessedText);
  870. this.mWidth = Mathf.Max(this.minWidth, Mathf.RoundToInt(this.mCalculatedSize.x));
  871. if (num != 1f)
  872. {
  873. this.mWidth = Mathf.RoundToInt((float)this.mWidth / num);
  874. }
  875. this.mHeight = Mathf.Max(this.minHeight, Mathf.RoundToInt(this.mCalculatedSize.y));
  876. if (num2 != 1f)
  877. {
  878. this.mHeight = Mathf.RoundToInt((float)this.mHeight / num2);
  879. }
  880. if ((this.mWidth & 1) == 1)
  881. {
  882. this.mWidth++;
  883. }
  884. if ((this.mHeight & 1) == 1)
  885. {
  886. this.mHeight++;
  887. }
  888. }
  889. else if (this.mOverflow == UILabel.Overflow.ResizeHeight)
  890. {
  891. this.mCalculatedSize = NGUIText.CalculatePrintedSize(this.mProcessedText);
  892. this.mHeight = Mathf.Max(this.minHeight, Mathf.RoundToInt(this.mCalculatedSize.y));
  893. if (num2 != 1f)
  894. {
  895. this.mHeight = Mathf.RoundToInt((float)this.mHeight / num2);
  896. }
  897. if ((this.mHeight & 1) == 1)
  898. {
  899. this.mHeight++;
  900. }
  901. }
  902. else
  903. {
  904. this.mCalculatedSize = NGUIText.CalculatePrintedSize(this.mProcessedText);
  905. }
  906. if (legacyMode)
  907. {
  908. base.width = Mathf.RoundToInt(this.mCalculatedSize.x);
  909. base.height = Mathf.RoundToInt(this.mCalculatedSize.y);
  910. base.cachedTransform.localScale = Vector3.one;
  911. }
  912. break;
  913. }
  914. if (--i <= 1)
  915. {
  916. break;
  917. }
  918. }
  919. }
  920. else
  921. {
  922. base.cachedTransform.localScale = Vector3.one;
  923. this.mProcessedText = string.Empty;
  924. this.mScale = 1f;
  925. }
  926. if (full)
  927. {
  928. NGUIText.bitmapFont = null;
  929. NGUIText.dynamicFont = null;
  930. }
  931. }
  932. public override void MakePixelPerfect()
  933. {
  934. if (this.ambigiousFont != null)
  935. {
  936. Vector3 localPosition = base.cachedTransform.localPosition;
  937. localPosition.x = (float)Mathf.RoundToInt(localPosition.x);
  938. localPosition.y = (float)Mathf.RoundToInt(localPosition.y);
  939. localPosition.z = (float)Mathf.RoundToInt(localPosition.z);
  940. base.cachedTransform.localPosition = localPosition;
  941. base.cachedTransform.localScale = Vector3.one;
  942. if (this.mOverflow == UILabel.Overflow.ResizeFreely)
  943. {
  944. this.AssumeNaturalSize();
  945. }
  946. else
  947. {
  948. int width = base.width;
  949. int height = base.height;
  950. UILabel.Overflow overflow = this.mOverflow;
  951. if (overflow != UILabel.Overflow.ResizeHeight)
  952. {
  953. this.mWidth = 100000;
  954. }
  955. this.mHeight = 100000;
  956. this.mOverflow = UILabel.Overflow.ShrinkContent;
  957. this.ProcessText(false, true);
  958. this.mOverflow = overflow;
  959. int num = Mathf.RoundToInt(this.mCalculatedSize.x);
  960. int num2 = Mathf.RoundToInt(this.mCalculatedSize.y);
  961. num = Mathf.Max(num, base.minWidth);
  962. num2 = Mathf.Max(num2, base.minHeight);
  963. this.mWidth = Mathf.Max(width, num);
  964. this.mHeight = Mathf.Max(height, num2);
  965. this.MarkAsChanged();
  966. }
  967. }
  968. else
  969. {
  970. base.MakePixelPerfect();
  971. }
  972. }
  973. public void AssumeNaturalSize()
  974. {
  975. if (this.ambigiousFont != null)
  976. {
  977. this.mWidth = 100000;
  978. this.mHeight = 100000;
  979. this.ProcessText(false, true);
  980. this.mWidth = Mathf.RoundToInt(this.mCalculatedSize.x);
  981. this.mHeight = Mathf.RoundToInt(this.mCalculatedSize.y);
  982. if ((this.mWidth & 1) == 1)
  983. {
  984. this.mWidth++;
  985. }
  986. if ((this.mHeight & 1) == 1)
  987. {
  988. this.mHeight++;
  989. }
  990. this.MarkAsChanged();
  991. }
  992. }
  993. [Obsolete("Use UILabel.GetCharacterAtPosition instead")]
  994. public int GetCharacterIndex(Vector3 worldPos)
  995. {
  996. return this.GetCharacterIndexAtPosition(worldPos, false);
  997. }
  998. [Obsolete("Use UILabel.GetCharacterAtPosition instead")]
  999. public int GetCharacterIndex(Vector2 localPos)
  1000. {
  1001. return this.GetCharacterIndexAtPosition(localPos, false);
  1002. }
  1003. public int GetCharacterIndexAtPosition(Vector3 worldPos, bool precise)
  1004. {
  1005. Vector2 localPos = base.cachedTransform.InverseTransformPoint(worldPos);
  1006. return this.GetCharacterIndexAtPosition(localPos, precise);
  1007. }
  1008. public int GetCharacterIndexAtPosition(Vector2 localPos, bool precise)
  1009. {
  1010. if (this.isValid)
  1011. {
  1012. string processedText = this.processedText;
  1013. if (string.IsNullOrEmpty(processedText))
  1014. {
  1015. return 0;
  1016. }
  1017. this.UpdateNGUIText();
  1018. if (precise)
  1019. {
  1020. NGUIText.PrintExactCharacterPositions(processedText, UILabel.mTempVerts, UILabel.mTempIndices);
  1021. }
  1022. else
  1023. {
  1024. NGUIText.PrintApproximateCharacterPositions(processedText, UILabel.mTempVerts, UILabel.mTempIndices);
  1025. }
  1026. if (UILabel.mTempVerts.size > 0)
  1027. {
  1028. this.ApplyOffset(UILabel.mTempVerts, 0);
  1029. int result = (!precise) ? NGUIText.GetApproximateCharacterIndex(UILabel.mTempVerts, UILabel.mTempIndices, localPos) : NGUIText.GetExactCharacterIndex(UILabel.mTempVerts, UILabel.mTempIndices, localPos);
  1030. UILabel.mTempVerts.Clear();
  1031. UILabel.mTempIndices.Clear();
  1032. NGUIText.bitmapFont = null;
  1033. NGUIText.dynamicFont = null;
  1034. return result;
  1035. }
  1036. NGUIText.bitmapFont = null;
  1037. NGUIText.dynamicFont = null;
  1038. }
  1039. return 0;
  1040. }
  1041. public string GetWordAtPosition(Vector3 worldPos)
  1042. {
  1043. int characterIndexAtPosition = this.GetCharacterIndexAtPosition(worldPos, true);
  1044. return this.GetWordAtCharacterIndex(characterIndexAtPosition);
  1045. }
  1046. public string GetWordAtPosition(Vector2 localPos)
  1047. {
  1048. int characterIndexAtPosition = this.GetCharacterIndexAtPosition(localPos, true);
  1049. return this.GetWordAtCharacterIndex(characterIndexAtPosition);
  1050. }
  1051. public string GetWordAtCharacterIndex(int characterIndex)
  1052. {
  1053. if (characterIndex != -1 && characterIndex < this.mText.Length)
  1054. {
  1055. int num = this.mText.LastIndexOfAny(new char[]
  1056. {
  1057. ' ',
  1058. '\n'
  1059. }, characterIndex) + 1;
  1060. int num2 = this.mText.IndexOfAny(new char[]
  1061. {
  1062. ' ',
  1063. '\n',
  1064. ',',
  1065. '.'
  1066. }, characterIndex);
  1067. if (num2 == -1)
  1068. {
  1069. num2 = this.mText.Length;
  1070. }
  1071. if (num != num2)
  1072. {
  1073. int num3 = num2 - num;
  1074. if (num3 > 0)
  1075. {
  1076. string text = this.mText.Substring(num, num3);
  1077. return NGUIText.StripSymbols(text);
  1078. }
  1079. }
  1080. }
  1081. return null;
  1082. }
  1083. public string GetUrlAtPosition(Vector3 worldPos)
  1084. {
  1085. return this.GetUrlAtCharacterIndex(this.GetCharacterIndexAtPosition(worldPos, true));
  1086. }
  1087. public string GetUrlAtPosition(Vector2 localPos)
  1088. {
  1089. return this.GetUrlAtCharacterIndex(this.GetCharacterIndexAtPosition(localPos, true));
  1090. }
  1091. public string GetUrlAtCharacterIndex(int characterIndex)
  1092. {
  1093. if (characterIndex != -1 && characterIndex < this.mText.Length - 6)
  1094. {
  1095. int num;
  1096. if (this.mText[characterIndex] == '[' && this.mText[characterIndex + 1] == 'u' && this.mText[characterIndex + 2] == 'r' && this.mText[characterIndex + 3] == 'l' && this.mText[characterIndex + 4] == '=')
  1097. {
  1098. num = characterIndex;
  1099. }
  1100. else
  1101. {
  1102. num = this.mText.LastIndexOf("[url=", characterIndex);
  1103. }
  1104. if (num == -1)
  1105. {
  1106. return null;
  1107. }
  1108. num += 5;
  1109. int num2 = this.mText.IndexOf("]", num);
  1110. if (num2 == -1)
  1111. {
  1112. return null;
  1113. }
  1114. int num3 = this.mText.IndexOf("[/url]", num2);
  1115. if (num3 == -1 || characterIndex <= num3)
  1116. {
  1117. return this.mText.Substring(num, num2 - num);
  1118. }
  1119. }
  1120. return null;
  1121. }
  1122. public int GetCharacterIndex(int currentIndex, KeyCode key)
  1123. {
  1124. if (this.isValid)
  1125. {
  1126. string processedText = this.processedText;
  1127. if (string.IsNullOrEmpty(processedText))
  1128. {
  1129. return 0;
  1130. }
  1131. int defaultFontSize = this.defaultFontSize;
  1132. this.UpdateNGUIText();
  1133. NGUIText.PrintApproximateCharacterPositions(processedText, UILabel.mTempVerts, UILabel.mTempIndices);
  1134. if (UILabel.mTempVerts.size > 0)
  1135. {
  1136. this.ApplyOffset(UILabel.mTempVerts, 0);
  1137. int i = 0;
  1138. while (i < UILabel.mTempIndices.size)
  1139. {
  1140. if (UILabel.mTempIndices[i] == currentIndex)
  1141. {
  1142. Vector2 pos = UILabel.mTempVerts[i];
  1143. if (key == KeyCode.UpArrow)
  1144. {
  1145. pos.y += (float)defaultFontSize + this.effectiveSpacingY;
  1146. }
  1147. else if (key == KeyCode.DownArrow)
  1148. {
  1149. pos.y -= (float)defaultFontSize + this.effectiveSpacingY;
  1150. }
  1151. else if (key == KeyCode.Home)
  1152. {
  1153. pos.x -= 1000f;
  1154. }
  1155. else if (key == KeyCode.End)
  1156. {
  1157. pos.x += 1000f;
  1158. }
  1159. int approximateCharacterIndex = NGUIText.GetApproximateCharacterIndex(UILabel.mTempVerts, UILabel.mTempIndices, pos);
  1160. if (approximateCharacterIndex == currentIndex)
  1161. {
  1162. break;
  1163. }
  1164. UILabel.mTempVerts.Clear();
  1165. UILabel.mTempIndices.Clear();
  1166. return approximateCharacterIndex;
  1167. }
  1168. else
  1169. {
  1170. i++;
  1171. }
  1172. }
  1173. UILabel.mTempVerts.Clear();
  1174. UILabel.mTempIndices.Clear();
  1175. }
  1176. NGUIText.bitmapFont = null;
  1177. NGUIText.dynamicFont = null;
  1178. if (key == KeyCode.UpArrow || key == KeyCode.Home)
  1179. {
  1180. return 0;
  1181. }
  1182. if (key == KeyCode.DownArrow || key == KeyCode.End)
  1183. {
  1184. return processedText.Length;
  1185. }
  1186. }
  1187. return currentIndex;
  1188. }
  1189. public void PrintOverlay(int start, int end, UIGeometry caret, UIGeometry highlight, Color caretColor, Color highlightColor)
  1190. {
  1191. if (caret != null)
  1192. {
  1193. caret.Clear();
  1194. }
  1195. if (highlight != null)
  1196. {
  1197. highlight.Clear();
  1198. }
  1199. if (!this.isValid)
  1200. {
  1201. return;
  1202. }
  1203. string processedText = this.processedText;
  1204. this.UpdateNGUIText();
  1205. int size = caret.verts.size;
  1206. Vector2 item = new Vector2(0.5f, 0.5f);
  1207. float finalAlpha = this.finalAlpha;
  1208. if (highlight != null && start != end)
  1209. {
  1210. int size2 = highlight.verts.size;
  1211. NGUIText.PrintCaretAndSelection(processedText, start, end, caret.verts, highlight.verts);
  1212. if (highlight.verts.size > size2)
  1213. {
  1214. this.ApplyOffset(highlight.verts, size2);
  1215. Color32 item2 = new Color(highlightColor.r, highlightColor.g, highlightColor.b, highlightColor.a * finalAlpha);
  1216. for (int i = size2; i < highlight.verts.size; i++)
  1217. {
  1218. highlight.uvs.Add(item);
  1219. highlight.cols.Add(item2);
  1220. }
  1221. }
  1222. }
  1223. else
  1224. {
  1225. NGUIText.PrintCaretAndSelection(processedText, start, end, caret.verts, null);
  1226. }
  1227. this.ApplyOffset(caret.verts, size);
  1228. Color32 item3 = new Color(caretColor.r, caretColor.g, caretColor.b, caretColor.a * finalAlpha);
  1229. for (int j = size; j < caret.verts.size; j++)
  1230. {
  1231. caret.uvs.Add(item);
  1232. caret.cols.Add(item3);
  1233. }
  1234. NGUIText.bitmapFont = null;
  1235. NGUIText.dynamicFont = null;
  1236. }
  1237. public override void OnFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
  1238. {
  1239. if (!this.isValid)
  1240. {
  1241. return;
  1242. }
  1243. int num = verts.size;
  1244. Color color = base.color;
  1245. color.a = this.finalAlpha;
  1246. if (this.mFont != null && this.mFont.premultipliedAlphaShader)
  1247. {
  1248. color = NGUITools.ApplyPMA(color);
  1249. }
  1250. if (QualitySettings.activeColorSpace == ColorSpace.Linear)
  1251. {
  1252. color.r = Mathf.Pow(color.r, 2.2f);
  1253. color.g = Mathf.Pow(color.g, 2.2f);
  1254. color.b = Mathf.Pow(color.b, 2.2f);
  1255. }
  1256. string processedText = this.processedText;
  1257. int size = verts.size;
  1258. this.UpdateNGUIText();
  1259. NGUIText.tint = color;
  1260. NGUIText.Print(processedText, verts, uvs, cols);
  1261. NGUIText.bitmapFont = null;
  1262. NGUIText.dynamicFont = null;
  1263. Vector2 vector = this.ApplyOffset(verts, size);
  1264. if (this.mFont != null && this.mFont.packedFontShader)
  1265. {
  1266. return;
  1267. }
  1268. if (this.effectStyle != UILabel.Effect.None)
  1269. {
  1270. int size2 = verts.size;
  1271. vector.x = this.mEffectDistance.x;
  1272. vector.y = this.mEffectDistance.y;
  1273. this.ApplyShadow(verts, uvs, cols, num, size2, vector.x, -vector.y);
  1274. if (this.effectStyle == UILabel.Effect.Outline || this.effectStyle == UILabel.Effect.Outline8)
  1275. {
  1276. num = size2;
  1277. size2 = verts.size;
  1278. this.ApplyShadow(verts, uvs, cols, num, size2, -vector.x, vector.y);
  1279. num = size2;
  1280. size2 = verts.size;
  1281. this.ApplyShadow(verts, uvs, cols, num, size2, vector.x, vector.y);
  1282. num = size2;
  1283. size2 = verts.size;
  1284. this.ApplyShadow(verts, uvs, cols, num, size2, -vector.x, -vector.y);
  1285. if (this.effectStyle == UILabel.Effect.Outline8)
  1286. {
  1287. num = size2;
  1288. size2 = verts.size;
  1289. this.ApplyShadow(verts, uvs, cols, num, size2, -vector.x, 0f);
  1290. num = size2;
  1291. size2 = verts.size;
  1292. this.ApplyShadow(verts, uvs, cols, num, size2, vector.x, 0f);
  1293. num = size2;
  1294. size2 = verts.size;
  1295. this.ApplyShadow(verts, uvs, cols, num, size2, 0f, vector.y);
  1296. num = size2;
  1297. size2 = verts.size;
  1298. this.ApplyShadow(verts, uvs, cols, num, size2, 0f, -vector.y);
  1299. }
  1300. }
  1301. }
  1302. if (this.onPostFill != null)
  1303. {
  1304. this.onPostFill(this, num, verts, uvs, cols);
  1305. }
  1306. }
  1307. public Vector2 ApplyOffset(BetterList<Vector3> verts, int start)
  1308. {
  1309. Vector2 pivotOffset = base.pivotOffset;
  1310. float num = Mathf.Lerp(0f, (float)(-(float)this.mWidth), pivotOffset.x);
  1311. float num2 = Mathf.Lerp((float)this.mHeight, 0f, pivotOffset.y) + Mathf.Lerp(this.mCalculatedSize.y - (float)this.mHeight, 0f, pivotOffset.y);
  1312. num = Mathf.Round(num);
  1313. num2 = Mathf.Round(num2);
  1314. for (int i = start; i < verts.size; i++)
  1315. {
  1316. Vector3[] buffer = verts.buffer;
  1317. int num3 = i;
  1318. buffer[num3].x = buffer[num3].x + num;
  1319. Vector3[] buffer2 = verts.buffer;
  1320. int num4 = i;
  1321. buffer2[num4].y = buffer2[num4].y + num2;
  1322. }
  1323. return new Vector2(num, num2);
  1324. }
  1325. public void ApplyShadow(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols, int start, int end, float x, float y)
  1326. {
  1327. Color color = this.mEffectColor;
  1328. color.a *= this.finalAlpha;
  1329. Color32 color2 = (!(this.bitmapFont != null) || !this.bitmapFont.premultipliedAlphaShader) ? color : NGUITools.ApplyPMA(color);
  1330. for (int i = start; i < end; i++)
  1331. {
  1332. verts.Add(verts.buffer[i]);
  1333. uvs.Add(uvs.buffer[i]);
  1334. cols.Add(cols.buffer[i]);
  1335. Vector3 vector = verts.buffer[i];
  1336. vector.x += x;
  1337. vector.y += y;
  1338. verts.buffer[i] = vector;
  1339. Color32 color3 = cols.buffer[i];
  1340. if (color3.a == 255)
  1341. {
  1342. cols.buffer[i] = color2;
  1343. }
  1344. else
  1345. {
  1346. Color color4 = color;
  1347. color4.a = (float)color3.a / 255f * color.a;
  1348. cols.buffer[i] = ((!(this.bitmapFont != null) || !this.bitmapFont.premultipliedAlphaShader) ? color4 : NGUITools.ApplyPMA(color4));
  1349. }
  1350. }
  1351. }
  1352. public int CalculateOffsetToFit(string text)
  1353. {
  1354. this.UpdateNGUIText();
  1355. NGUIText.encoding = false;
  1356. NGUIText.symbolStyle = NGUIText.SymbolStyle.None;
  1357. int result = NGUIText.CalculateOffsetToFit(text);
  1358. NGUIText.bitmapFont = null;
  1359. NGUIText.dynamicFont = null;
  1360. return result;
  1361. }
  1362. public void SetCurrentProgress()
  1363. {
  1364. if (UIProgressBar.current != null)
  1365. {
  1366. this.text = UIProgressBar.current.value.ToString("F");
  1367. }
  1368. }
  1369. public void SetCurrentPercent()
  1370. {
  1371. if (UIProgressBar.current != null)
  1372. {
  1373. this.text = Mathf.RoundToInt(UIProgressBar.current.value * 100f) + "%";
  1374. }
  1375. }
  1376. public void SetCurrentSelection()
  1377. {
  1378. if (UIPopupList.current != null)
  1379. {
  1380. if (UIPopupList.current.isLocalized)
  1381. {
  1382. List<string> itemTerms = UIPopupList.current.itemTerms;
  1383. List<string> items = UIPopupList.current.items;
  1384. Localize localize = base.gameObject.GetComponent<Localize>();
  1385. if (localize == null)
  1386. {
  1387. localize = base.gameObject.AddComponent<Localize>();
  1388. }
  1389. string term = UIPopupList.current.value.Replace("\r", string.Empty);
  1390. if (itemTerms != null && itemTerms.Count == items.Count)
  1391. {
  1392. for (int i = 0; i < items.Count; i++)
  1393. {
  1394. if (items[i] == UIPopupList.current.value)
  1395. {
  1396. if (!string.IsNullOrEmpty(itemTerms[i]))
  1397. {
  1398. term = itemTerms[i];
  1399. }
  1400. break;
  1401. }
  1402. }
  1403. }
  1404. localize.SetTerm(term);
  1405. }
  1406. else
  1407. {
  1408. this.text = UIPopupList.current.value;
  1409. }
  1410. }
  1411. }
  1412. public bool Wrap(string text, out string final)
  1413. {
  1414. return this.Wrap(text, out final, 1000000);
  1415. }
  1416. public bool Wrap(string text, out string final, int height)
  1417. {
  1418. this.UpdateNGUIText();
  1419. NGUIText.rectHeight = height;
  1420. NGUIText.regionHeight = height;
  1421. bool result = NGUIText.WrapText(text, out final);
  1422. NGUIText.bitmapFont = null;
  1423. NGUIText.dynamicFont = null;
  1424. return result;
  1425. }
  1426. public void UpdateNGUIText()
  1427. {
  1428. Font trueTypeFont = this.trueTypeFont;
  1429. bool flag = trueTypeFont != null;
  1430. NGUIText.fontSize = this.mPrintedSize;
  1431. NGUIText.fontStyle = this.mFontStyle;
  1432. NGUIText.rectWidth = this.mWidth;
  1433. NGUIText.rectHeight = this.mHeight;
  1434. NGUIText.regionWidth = Mathf.RoundToInt((float)this.mWidth * (this.mDrawRegion.z - this.mDrawRegion.x));
  1435. NGUIText.regionHeight = Mathf.RoundToInt((float)this.mHeight * (this.mDrawRegion.w - this.mDrawRegion.y));
  1436. NGUIText.gradient = (this.mApplyGradient && (this.mFont == null || !this.mFont.packedFontShader));
  1437. NGUIText.gradientTop = this.mGradientTop;
  1438. NGUIText.gradientBottom = this.mGradientBottom;
  1439. NGUIText.encoding = this.mEncoding;
  1440. NGUIText.premultiply = this.mPremultiply;
  1441. NGUIText.symbolStyle = this.mSymbols;
  1442. NGUIText.maxLines = this.mMaxLineCount;
  1443. NGUIText.spacingX = this.effectiveSpacingX;
  1444. NGUIText.spacingY = this.effectiveSpacingY;
  1445. NGUIText.fontScale = ((!flag) ? ((float)this.mFontSize / (float)this.mFont.defaultSize * this.mScale) : this.mScale);
  1446. if (this.mFont != null)
  1447. {
  1448. NGUIText.bitmapFont = this.mFont;
  1449. for (;;)
  1450. {
  1451. UIFont replacement = NGUIText.bitmapFont.replacement;
  1452. if (replacement == null)
  1453. {
  1454. break;
  1455. }
  1456. NGUIText.bitmapFont = replacement;
  1457. }
  1458. if (NGUIText.bitmapFont.isDynamic)
  1459. {
  1460. NGUIText.dynamicFont = NGUIText.bitmapFont.dynamicFont;
  1461. NGUIText.bitmapFont = null;
  1462. }
  1463. else
  1464. {
  1465. NGUIText.dynamicFont = null;
  1466. }
  1467. }
  1468. else
  1469. {
  1470. NGUIText.dynamicFont = trueTypeFont;
  1471. NGUIText.bitmapFont = null;
  1472. }
  1473. if (flag && this.keepCrisp)
  1474. {
  1475. UIRoot root = base.root;
  1476. if (root != null)
  1477. {
  1478. NGUIText.pixelDensity = ((!(root != null)) ? 1f : root.pixelSizeAdjustment);
  1479. }
  1480. }
  1481. else
  1482. {
  1483. NGUIText.pixelDensity = 1f;
  1484. }
  1485. if (this.mDensity != NGUIText.pixelDensity)
  1486. {
  1487. this.ProcessText(false, false);
  1488. NGUIText.rectWidth = this.mWidth;
  1489. NGUIText.rectHeight = this.mHeight;
  1490. NGUIText.regionWidth = Mathf.RoundToInt((float)this.mWidth * (this.mDrawRegion.z - this.mDrawRegion.x));
  1491. NGUIText.regionHeight = Mathf.RoundToInt((float)this.mHeight * (this.mDrawRegion.w - this.mDrawRegion.y));
  1492. }
  1493. if (this.alignment == NGUIText.Alignment.Automatic)
  1494. {
  1495. UIWidget.Pivot pivot = base.pivot;
  1496. if (pivot == UIWidget.Pivot.Left || pivot == UIWidget.Pivot.TopLeft || pivot == UIWidget.Pivot.BottomLeft)
  1497. {
  1498. NGUIText.alignment = NGUIText.Alignment.Left;
  1499. }
  1500. else if (pivot == UIWidget.Pivot.Right || pivot == UIWidget.Pivot.TopRight || pivot == UIWidget.Pivot.BottomRight)
  1501. {
  1502. NGUIText.alignment = NGUIText.Alignment.Right;
  1503. }
  1504. else
  1505. {
  1506. NGUIText.alignment = NGUIText.Alignment.Center;
  1507. }
  1508. }
  1509. else
  1510. {
  1511. NGUIText.alignment = this.alignment;
  1512. }
  1513. NGUIText.Update();
  1514. }
  1515. public UILabel.Crispness keepCrispWhenShrunk = UILabel.Crispness.OnDesktop;
  1516. [HideInInspector]
  1517. [SerializeField]
  1518. private Font mTrueTypeFont;
  1519. [HideInInspector]
  1520. [SerializeField]
  1521. private UIFont mFont;
  1522. [Multiline(6)]
  1523. [HideInInspector]
  1524. [SerializeField]
  1525. private string mText = string.Empty;
  1526. [HideInInspector]
  1527. [SerializeField]
  1528. private int mFontSize = 16;
  1529. [HideInInspector]
  1530. [SerializeField]
  1531. private FontStyle mFontStyle;
  1532. [HideInInspector]
  1533. [SerializeField]
  1534. private NGUIText.Alignment mAlignment;
  1535. [HideInInspector]
  1536. [SerializeField]
  1537. private bool mEncoding = true;
  1538. [HideInInspector]
  1539. [SerializeField]
  1540. private int mMaxLineCount;
  1541. [HideInInspector]
  1542. [SerializeField]
  1543. private UILabel.Effect mEffectStyle;
  1544. [HideInInspector]
  1545. [SerializeField]
  1546. private Color mEffectColor = Color.black;
  1547. [HideInInspector]
  1548. [SerializeField]
  1549. private NGUIText.SymbolStyle mSymbols = NGUIText.SymbolStyle.Normal;
  1550. [HideInInspector]
  1551. [SerializeField]
  1552. private Vector2 mEffectDistance = Vector2.one;
  1553. [HideInInspector]
  1554. [SerializeField]
  1555. private UILabel.Overflow mOverflow;
  1556. [HideInInspector]
  1557. [SerializeField]
  1558. private Material mMaterial;
  1559. [HideInInspector]
  1560. [SerializeField]
  1561. private bool mApplyGradient;
  1562. [HideInInspector]
  1563. [SerializeField]
  1564. private Color mGradientTop = Color.white;
  1565. [HideInInspector]
  1566. [SerializeField]
  1567. private Color mGradientBottom = new Color(0.7f, 0.7f, 0.7f);
  1568. [HideInInspector]
  1569. [SerializeField]
  1570. private int mSpacingX;
  1571. [HideInInspector]
  1572. [SerializeField]
  1573. private int mSpacingY;
  1574. [HideInInspector]
  1575. [SerializeField]
  1576. private bool mUseFloatSpacing;
  1577. [HideInInspector]
  1578. [SerializeField]
  1579. private float mFloatSpacingX;
  1580. [HideInInspector]
  1581. [SerializeField]
  1582. private float mFloatSpacingY;
  1583. [HideInInspector]
  1584. [SerializeField]
  1585. private bool mShrinkToFit;
  1586. [HideInInspector]
  1587. [SerializeField]
  1588. private int mMaxLineWidth;
  1589. [HideInInspector]
  1590. [SerializeField]
  1591. private int mMaxLineHeight;
  1592. [HideInInspector]
  1593. [SerializeField]
  1594. private float mLineWidth;
  1595. [HideInInspector]
  1596. [SerializeField]
  1597. private bool mMultiline = true;
  1598. [NonSerialized]
  1599. private Font mActiveTTF;
  1600. private float mDensity = 1f;
  1601. private bool mShouldBeProcessed = true;
  1602. private string mProcessedText;
  1603. private bool mPremultiply;
  1604. private Vector2 mCalculatedSize = Vector2.zero;
  1605. private float mScale = 1f;
  1606. private int mPrintedSize;
  1607. private int mLastWidth;
  1608. private int mLastHeight;
  1609. private static BetterList<UILabel> mList = new BetterList<UILabel>();
  1610. private static Dictionary<Font, int> mFontUsage = new Dictionary<Font, int>();
  1611. private static BetterList<Vector3> mTempVerts = new BetterList<Vector3>();
  1612. private static BetterList<int> mTempIndices = new BetterList<int>();
  1613. [CompilerGenerated]
  1614. private static Font.FontTextureRebuildCallback <>f__mg$cache0;
  1615. public enum Effect
  1616. {
  1617. None,
  1618. Shadow,
  1619. Outline,
  1620. Outline8
  1621. }
  1622. public enum Overflow
  1623. {
  1624. ShrinkContent,
  1625. ClampContent,
  1626. ResizeFreely,
  1627. ResizeHeight
  1628. }
  1629. public enum Crispness
  1630. {
  1631. Never,
  1632. OnDesktop,
  1633. Always
  1634. }
  1635. }