UILabel.cs 36 KB

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