UILabel.cs 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742
  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. Localize localize = base.gameObject.GetComponent<Localize>();
  1383. if (localize == null)
  1384. {
  1385. localize = base.gameObject.AddComponent<Localize>();
  1386. }
  1387. localize.SetTerm(UIPopupList.current.value.Replace("\r", string.Empty));
  1388. }
  1389. else
  1390. {
  1391. this.text = UIPopupList.current.value;
  1392. }
  1393. }
  1394. }
  1395. public bool Wrap(string text, out string final)
  1396. {
  1397. return this.Wrap(text, out final, 1000000);
  1398. }
  1399. public bool Wrap(string text, out string final, int height)
  1400. {
  1401. this.UpdateNGUIText();
  1402. NGUIText.rectHeight = height;
  1403. NGUIText.regionHeight = height;
  1404. bool result = NGUIText.WrapText(text, out final);
  1405. NGUIText.bitmapFont = null;
  1406. NGUIText.dynamicFont = null;
  1407. return result;
  1408. }
  1409. public void UpdateNGUIText()
  1410. {
  1411. Font trueTypeFont = this.trueTypeFont;
  1412. bool flag = trueTypeFont != null;
  1413. NGUIText.fontSize = this.mPrintedSize;
  1414. NGUIText.fontStyle = this.mFontStyle;
  1415. NGUIText.rectWidth = this.mWidth;
  1416. NGUIText.rectHeight = this.mHeight;
  1417. NGUIText.regionWidth = Mathf.RoundToInt((float)this.mWidth * (this.mDrawRegion.z - this.mDrawRegion.x));
  1418. NGUIText.regionHeight = Mathf.RoundToInt((float)this.mHeight * (this.mDrawRegion.w - this.mDrawRegion.y));
  1419. NGUIText.gradient = (this.mApplyGradient && (this.mFont == null || !this.mFont.packedFontShader));
  1420. NGUIText.gradientTop = this.mGradientTop;
  1421. NGUIText.gradientBottom = this.mGradientBottom;
  1422. NGUIText.encoding = this.mEncoding;
  1423. NGUIText.premultiply = this.mPremultiply;
  1424. NGUIText.symbolStyle = this.mSymbols;
  1425. NGUIText.maxLines = this.mMaxLineCount;
  1426. NGUIText.spacingX = this.effectiveSpacingX;
  1427. NGUIText.spacingY = this.effectiveSpacingY;
  1428. NGUIText.fontScale = ((!flag) ? ((float)this.mFontSize / (float)this.mFont.defaultSize * this.mScale) : this.mScale);
  1429. if (this.mFont != null)
  1430. {
  1431. NGUIText.bitmapFont = this.mFont;
  1432. for (;;)
  1433. {
  1434. UIFont replacement = NGUIText.bitmapFont.replacement;
  1435. if (replacement == null)
  1436. {
  1437. break;
  1438. }
  1439. NGUIText.bitmapFont = replacement;
  1440. }
  1441. if (NGUIText.bitmapFont.isDynamic)
  1442. {
  1443. NGUIText.dynamicFont = NGUIText.bitmapFont.dynamicFont;
  1444. NGUIText.bitmapFont = null;
  1445. }
  1446. else
  1447. {
  1448. NGUIText.dynamicFont = null;
  1449. }
  1450. }
  1451. else
  1452. {
  1453. NGUIText.dynamicFont = trueTypeFont;
  1454. NGUIText.bitmapFont = null;
  1455. }
  1456. if (flag && this.keepCrisp)
  1457. {
  1458. UIRoot root = base.root;
  1459. if (root != null)
  1460. {
  1461. NGUIText.pixelDensity = ((!(root != null)) ? 1f : root.pixelSizeAdjustment);
  1462. }
  1463. }
  1464. else
  1465. {
  1466. NGUIText.pixelDensity = 1f;
  1467. }
  1468. if (this.mDensity != NGUIText.pixelDensity)
  1469. {
  1470. this.ProcessText(false, false);
  1471. NGUIText.rectWidth = this.mWidth;
  1472. NGUIText.rectHeight = this.mHeight;
  1473. NGUIText.regionWidth = Mathf.RoundToInt((float)this.mWidth * (this.mDrawRegion.z - this.mDrawRegion.x));
  1474. NGUIText.regionHeight = Mathf.RoundToInt((float)this.mHeight * (this.mDrawRegion.w - this.mDrawRegion.y));
  1475. }
  1476. if (this.alignment == NGUIText.Alignment.Automatic)
  1477. {
  1478. UIWidget.Pivot pivot = base.pivot;
  1479. if (pivot == UIWidget.Pivot.Left || pivot == UIWidget.Pivot.TopLeft || pivot == UIWidget.Pivot.BottomLeft)
  1480. {
  1481. NGUIText.alignment = NGUIText.Alignment.Left;
  1482. }
  1483. else if (pivot == UIWidget.Pivot.Right || pivot == UIWidget.Pivot.TopRight || pivot == UIWidget.Pivot.BottomRight)
  1484. {
  1485. NGUIText.alignment = NGUIText.Alignment.Right;
  1486. }
  1487. else
  1488. {
  1489. NGUIText.alignment = NGUIText.Alignment.Center;
  1490. }
  1491. }
  1492. else
  1493. {
  1494. NGUIText.alignment = this.alignment;
  1495. }
  1496. NGUIText.Update();
  1497. }
  1498. public UILabel.Crispness keepCrispWhenShrunk = UILabel.Crispness.OnDesktop;
  1499. [HideInInspector]
  1500. [SerializeField]
  1501. private Font mTrueTypeFont;
  1502. [HideInInspector]
  1503. [SerializeField]
  1504. private UIFont mFont;
  1505. [Multiline(6)]
  1506. [HideInInspector]
  1507. [SerializeField]
  1508. private string mText = string.Empty;
  1509. [HideInInspector]
  1510. [SerializeField]
  1511. private int mFontSize = 16;
  1512. [HideInInspector]
  1513. [SerializeField]
  1514. private FontStyle mFontStyle;
  1515. [HideInInspector]
  1516. [SerializeField]
  1517. private NGUIText.Alignment mAlignment;
  1518. [HideInInspector]
  1519. [SerializeField]
  1520. private bool mEncoding = true;
  1521. [HideInInspector]
  1522. [SerializeField]
  1523. private int mMaxLineCount;
  1524. [HideInInspector]
  1525. [SerializeField]
  1526. private UILabel.Effect mEffectStyle;
  1527. [HideInInspector]
  1528. [SerializeField]
  1529. private Color mEffectColor = Color.black;
  1530. [HideInInspector]
  1531. [SerializeField]
  1532. private NGUIText.SymbolStyle mSymbols = NGUIText.SymbolStyle.Normal;
  1533. [HideInInspector]
  1534. [SerializeField]
  1535. private Vector2 mEffectDistance = Vector2.one;
  1536. [HideInInspector]
  1537. [SerializeField]
  1538. private UILabel.Overflow mOverflow;
  1539. [HideInInspector]
  1540. [SerializeField]
  1541. private Material mMaterial;
  1542. [HideInInspector]
  1543. [SerializeField]
  1544. private bool mApplyGradient;
  1545. [HideInInspector]
  1546. [SerializeField]
  1547. private Color mGradientTop = Color.white;
  1548. [HideInInspector]
  1549. [SerializeField]
  1550. private Color mGradientBottom = new Color(0.7f, 0.7f, 0.7f);
  1551. [HideInInspector]
  1552. [SerializeField]
  1553. private int mSpacingX;
  1554. [HideInInspector]
  1555. [SerializeField]
  1556. private int mSpacingY;
  1557. [HideInInspector]
  1558. [SerializeField]
  1559. private bool mUseFloatSpacing;
  1560. [HideInInspector]
  1561. [SerializeField]
  1562. private float mFloatSpacingX;
  1563. [HideInInspector]
  1564. [SerializeField]
  1565. private float mFloatSpacingY;
  1566. [HideInInspector]
  1567. [SerializeField]
  1568. private bool mShrinkToFit;
  1569. [HideInInspector]
  1570. [SerializeField]
  1571. private int mMaxLineWidth;
  1572. [HideInInspector]
  1573. [SerializeField]
  1574. private int mMaxLineHeight;
  1575. [HideInInspector]
  1576. [SerializeField]
  1577. private float mLineWidth;
  1578. [HideInInspector]
  1579. [SerializeField]
  1580. private bool mMultiline = true;
  1581. [NonSerialized]
  1582. private Font mActiveTTF;
  1583. private float mDensity = 1f;
  1584. private bool mShouldBeProcessed = true;
  1585. private string mProcessedText;
  1586. private bool mPremultiply;
  1587. private Vector2 mCalculatedSize = Vector2.zero;
  1588. private float mScale = 1f;
  1589. private int mPrintedSize;
  1590. private int mLastWidth;
  1591. private int mLastHeight;
  1592. private static BetterList<UILabel> mList = new BetterList<UILabel>();
  1593. private static Dictionary<Font, int> mFontUsage = new Dictionary<Font, int>();
  1594. private static BetterList<Vector3> mTempVerts = new BetterList<Vector3>();
  1595. private static BetterList<int> mTempIndices = new BetterList<int>();
  1596. [CompilerGenerated]
  1597. private static Font.FontTextureRebuildCallback <>f__mg$cache0;
  1598. public enum Effect
  1599. {
  1600. None,
  1601. Shadow,
  1602. Outline,
  1603. Outline8
  1604. }
  1605. public enum Overflow
  1606. {
  1607. ShrinkContent,
  1608. ClampContent,
  1609. ResizeFreely,
  1610. ResizeHeight
  1611. }
  1612. public enum Crispness
  1613. {
  1614. Never,
  1615. OnDesktop,
  1616. Always
  1617. }
  1618. }