12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742 |
- using System;
- using System.Collections.Generic;
- using System.Runtime.CompilerServices;
- using I2.Loc;
- using UnityEngine;
- [ExecuteInEditMode]
- [AddComponentMenu("NGUI/UI/NGUI Label")]
- public class UILabel : UIWidget
- {
- private bool shouldBeProcessed
- {
- get
- {
- return this.mShouldBeProcessed;
- }
- set
- {
- if (value)
- {
- this.mChanged = true;
- this.mShouldBeProcessed = true;
- }
- else
- {
- this.mShouldBeProcessed = false;
- }
- }
- }
- public override bool isAnchoredHorizontally
- {
- get
- {
- return base.isAnchoredHorizontally || this.mOverflow == UILabel.Overflow.ResizeFreely;
- }
- }
- public override bool isAnchoredVertically
- {
- get
- {
- return base.isAnchoredVertically || this.mOverflow == UILabel.Overflow.ResizeFreely || this.mOverflow == UILabel.Overflow.ResizeHeight;
- }
- }
- public override Material material
- {
- get
- {
- if (this.mMaterial != null)
- {
- return this.mMaterial;
- }
- if (this.mFont != null)
- {
- return this.mFont.material;
- }
- if (this.mTrueTypeFont != null)
- {
- return this.mTrueTypeFont.material;
- }
- return null;
- }
- set
- {
- if (this.mMaterial != value)
- {
- base.RemoveFromPanel();
- this.mMaterial = value;
- this.MarkAsChanged();
- }
- }
- }
- [Obsolete("Use UILabel.bitmapFont instead")]
- public UIFont font
- {
- get
- {
- return this.bitmapFont;
- }
- set
- {
- this.bitmapFont = value;
- }
- }
- public UIFont bitmapFont
- {
- get
- {
- return this.mFont;
- }
- set
- {
- if (this.mFont != value)
- {
- base.RemoveFromPanel();
- this.mFont = value;
- this.mTrueTypeFont = null;
- this.MarkAsChanged();
- }
- }
- }
- public Font trueTypeFont
- {
- get
- {
- if (this.mTrueTypeFont != null)
- {
- return this.mTrueTypeFont;
- }
- return (!(this.mFont != null)) ? null : this.mFont.dynamicFont;
- }
- set
- {
- if (this.mTrueTypeFont != value)
- {
- this.SetActiveFont(null);
- base.RemoveFromPanel();
- this.mTrueTypeFont = value;
- this.shouldBeProcessed = true;
- this.mFont = null;
- this.SetActiveFont(value);
- this.ProcessAndRequest();
- if (this.mActiveTTF != null)
- {
- base.MarkAsChanged();
- }
- }
- }
- }
- public UnityEngine.Object ambigiousFont
- {
- get
- {
- return (!(this.mFont != null)) ? this.mTrueTypeFont : this.mFont;
- }
- set
- {
- UIFont uifont = value as UIFont;
- if (uifont != null)
- {
- this.bitmapFont = uifont;
- }
- else
- {
- this.trueTypeFont = (value as Font);
- }
- }
- }
- public string text
- {
- get
- {
- return this.mText;
- }
- set
- {
- if (this.mText == value)
- {
- return;
- }
- if (string.IsNullOrEmpty(value))
- {
- if (!string.IsNullOrEmpty(this.mText))
- {
- this.mText = string.Empty;
- this.MarkAsChanged();
- this.ProcessAndRequest();
- }
- }
- else if (this.mText != value)
- {
- this.mText = value;
- this.MarkAsChanged();
- this.ProcessAndRequest();
- }
- if (this.autoResizeBoxCollider)
- {
- base.ResizeCollider();
- }
- }
- }
- public int defaultFontSize
- {
- get
- {
- return (!(this.trueTypeFont != null)) ? ((!(this.mFont != null)) ? 16 : this.mFont.defaultSize) : this.mFontSize;
- }
- }
- public int fontSize
- {
- get
- {
- return this.mFontSize;
- }
- set
- {
- value = Mathf.Clamp(value, 0, 256);
- if (this.mFontSize != value)
- {
- this.mFontSize = value;
- this.shouldBeProcessed = true;
- this.ProcessAndRequest();
- }
- }
- }
- public FontStyle fontStyle
- {
- get
- {
- return this.mFontStyle;
- }
- set
- {
- if (this.mFontStyle != value)
- {
- this.mFontStyle = value;
- this.shouldBeProcessed = true;
- this.ProcessAndRequest();
- }
- }
- }
- public NGUIText.Alignment alignment
- {
- get
- {
- return this.mAlignment;
- }
- set
- {
- if (this.mAlignment != value)
- {
- this.mAlignment = value;
- this.shouldBeProcessed = true;
- this.ProcessAndRequest();
- }
- }
- }
- public bool applyGradient
- {
- get
- {
- return this.mApplyGradient;
- }
- set
- {
- if (this.mApplyGradient != value)
- {
- this.mApplyGradient = value;
- this.MarkAsChanged();
- }
- }
- }
- public Color gradientTop
- {
- get
- {
- return this.mGradientTop;
- }
- set
- {
- if (this.mGradientTop != value)
- {
- this.mGradientTop = value;
- if (this.mApplyGradient)
- {
- this.MarkAsChanged();
- }
- }
- }
- }
- public Color gradientBottom
- {
- get
- {
- return this.mGradientBottom;
- }
- set
- {
- if (this.mGradientBottom != value)
- {
- this.mGradientBottom = value;
- if (this.mApplyGradient)
- {
- this.MarkAsChanged();
- }
- }
- }
- }
- public int spacingX
- {
- get
- {
- return this.mSpacingX;
- }
- set
- {
- if (this.mSpacingX != value)
- {
- this.mSpacingX = value;
- this.MarkAsChanged();
- }
- }
- }
- public int spacingY
- {
- get
- {
- return this.mSpacingY;
- }
- set
- {
- if (this.mSpacingY != value)
- {
- this.mSpacingY = value;
- this.MarkAsChanged();
- }
- }
- }
- public bool useFloatSpacing
- {
- get
- {
- return this.mUseFloatSpacing;
- }
- set
- {
- if (this.mUseFloatSpacing != value)
- {
- this.mUseFloatSpacing = value;
- this.shouldBeProcessed = true;
- }
- }
- }
- public float floatSpacingX
- {
- get
- {
- return this.mFloatSpacingX;
- }
- set
- {
- if (!Mathf.Approximately(this.mFloatSpacingX, value))
- {
- this.mFloatSpacingX = value;
- this.MarkAsChanged();
- }
- }
- }
- public float floatSpacingY
- {
- get
- {
- return this.mFloatSpacingY;
- }
- set
- {
- if (!Mathf.Approximately(this.mFloatSpacingY, value))
- {
- this.mFloatSpacingY = value;
- this.MarkAsChanged();
- }
- }
- }
- public float effectiveSpacingY
- {
- get
- {
- return (!this.mUseFloatSpacing) ? ((float)this.mSpacingY) : this.mFloatSpacingY;
- }
- }
- public float effectiveSpacingX
- {
- get
- {
- return (!this.mUseFloatSpacing) ? ((float)this.mSpacingX) : this.mFloatSpacingX;
- }
- }
- private bool keepCrisp
- {
- get
- {
- return this.trueTypeFont != null && this.keepCrispWhenShrunk != UILabel.Crispness.Never;
- }
- }
- public bool supportEncoding
- {
- get
- {
- return this.mEncoding;
- }
- set
- {
- if (this.mEncoding != value)
- {
- this.mEncoding = value;
- this.shouldBeProcessed = true;
- }
- }
- }
- public NGUIText.SymbolStyle symbolStyle
- {
- get
- {
- return this.mSymbols;
- }
- set
- {
- if (this.mSymbols != value)
- {
- this.mSymbols = value;
- this.shouldBeProcessed = true;
- }
- }
- }
- public UILabel.Overflow overflowMethod
- {
- get
- {
- return this.mOverflow;
- }
- set
- {
- if (this.mOverflow != value)
- {
- this.mOverflow = value;
- this.shouldBeProcessed = true;
- }
- }
- }
- [Obsolete("Use 'width' instead")]
- public int lineWidth
- {
- get
- {
- return base.width;
- }
- set
- {
- base.width = value;
- }
- }
- [Obsolete("Use 'height' instead")]
- public int lineHeight
- {
- get
- {
- return base.height;
- }
- set
- {
- base.height = value;
- }
- }
- public bool multiLine
- {
- get
- {
- return this.mMaxLineCount != 1;
- }
- set
- {
- if (this.mMaxLineCount != 1 != value)
- {
- this.mMaxLineCount = ((!value) ? 1 : 0);
- this.shouldBeProcessed = true;
- }
- }
- }
- public override Vector3[] localCorners
- {
- get
- {
- if (this.shouldBeProcessed)
- {
- this.ProcessText();
- }
- return base.localCorners;
- }
- }
- public override Vector3[] worldCorners
- {
- get
- {
- if (this.shouldBeProcessed)
- {
- this.ProcessText();
- }
- return base.worldCorners;
- }
- }
- public override Vector4 drawingDimensions
- {
- get
- {
- if (this.shouldBeProcessed)
- {
- this.ProcessText();
- }
- return base.drawingDimensions;
- }
- }
- public int maxLineCount
- {
- get
- {
- return this.mMaxLineCount;
- }
- set
- {
- if (this.mMaxLineCount != value)
- {
- this.mMaxLineCount = Mathf.Max(value, 0);
- this.shouldBeProcessed = true;
- if (this.overflowMethod == UILabel.Overflow.ShrinkContent)
- {
- this.MakePixelPerfect();
- }
- }
- }
- }
- public UILabel.Effect effectStyle
- {
- get
- {
- return this.mEffectStyle;
- }
- set
- {
- if (this.mEffectStyle != value)
- {
- this.mEffectStyle = value;
- this.shouldBeProcessed = true;
- }
- }
- }
- public Color effectColor
- {
- get
- {
- return this.mEffectColor;
- }
- set
- {
- if (this.mEffectColor != value)
- {
- this.mEffectColor = value;
- if (this.mEffectStyle != UILabel.Effect.None)
- {
- this.shouldBeProcessed = true;
- }
- }
- }
- }
- public Vector2 effectDistance
- {
- get
- {
- return this.mEffectDistance;
- }
- set
- {
- if (this.mEffectDistance != value)
- {
- this.mEffectDistance = value;
- this.shouldBeProcessed = true;
- }
- }
- }
- [Obsolete("Use 'overflowMethod == UILabel.Overflow.ShrinkContent' instead")]
- public bool shrinkToFit
- {
- get
- {
- return this.mOverflow == UILabel.Overflow.ShrinkContent;
- }
- set
- {
- if (value)
- {
- this.overflowMethod = UILabel.Overflow.ShrinkContent;
- }
- }
- }
- public string processedText
- {
- get
- {
- if (this.mLastWidth != this.mWidth || this.mLastHeight != this.mHeight)
- {
- this.mLastWidth = this.mWidth;
- this.mLastHeight = this.mHeight;
- this.mShouldBeProcessed = true;
- }
- if (this.shouldBeProcessed)
- {
- this.ProcessText();
- }
- return this.mProcessedText;
- }
- }
- public Vector2 printedSize
- {
- get
- {
- if (this.shouldBeProcessed)
- {
- this.ProcessText();
- }
- return this.mCalculatedSize;
- }
- }
- public override Vector2 localSize
- {
- get
- {
- if (this.shouldBeProcessed)
- {
- this.ProcessText();
- }
- return base.localSize;
- }
- }
- private bool isValid
- {
- get
- {
- return this.mFont != null || this.mTrueTypeFont != null;
- }
- }
- protected override void OnInit()
- {
- base.OnInit();
- UILabel.mList.Add(this);
- this.SetActiveFont(this.trueTypeFont);
- }
- protected override void OnDisable()
- {
- this.SetActiveFont(null);
- UILabel.mList.Remove(this);
- base.OnDisable();
- }
- protected void SetActiveFont(Font fnt)
- {
- if (this.mActiveTTF != fnt)
- {
- if (this.mActiveTTF != null)
- {
- int num;
- if (UILabel.mFontUsage.TryGetValue(this.mActiveTTF, out num))
- {
- num = Mathf.Max(0, --num);
- if (num == 0)
- {
- this.mActiveTTF.textureRebuildCallback = null;
- UILabel.mFontUsage.Remove(this.mActiveTTF);
- }
- else
- {
- UILabel.mFontUsage[this.mActiveTTF] = num;
- }
- }
- else
- {
- this.mActiveTTF.textureRebuildCallback = null;
- }
- }
- this.mActiveTTF = fnt;
- if (this.mActiveTTF != null)
- {
- int num2 = 0;
- if (!UILabel.mFontUsage.TryGetValue(this.mActiveTTF, out num2))
- {
- Font font = this.mActiveTTF;
- if (UILabel.<>f__mg$cache0 == null)
- {
- UILabel.<>f__mg$cache0 = new Font.FontTextureRebuildCallback(UILabel.OnFontTextureChanged);
- }
- font.textureRebuildCallback = UILabel.<>f__mg$cache0;
- }
- num2 = (UILabel.mFontUsage[this.mActiveTTF] = num2 + 1);
- }
- }
- }
- public static void OnFontTextureChanged()
- {
- for (int i = 0; i < UILabel.mList.size; i++)
- {
- UILabel uilabel = UILabel.mList[i];
- if (uilabel != null)
- {
- Font trueTypeFont = uilabel.trueTypeFont;
- if (trueTypeFont != null)
- {
- trueTypeFont.RequestCharactersInTexture(uilabel.mText, uilabel.mPrintedSize, uilabel.mFontStyle);
- }
- }
- }
- for (int j = 0; j < UILabel.mList.size; j++)
- {
- UILabel uilabel2 = UILabel.mList[j];
- if (uilabel2 != null)
- {
- Font trueTypeFont2 = uilabel2.trueTypeFont;
- if (trueTypeFont2 != null)
- {
- uilabel2.RemoveFromPanel();
- uilabel2.CreatePanel();
- }
- }
- }
- }
- public override Vector3[] GetSides(Transform relativeTo)
- {
- if (this.shouldBeProcessed)
- {
- this.ProcessText();
- }
- return base.GetSides(relativeTo);
- }
- protected override void UpgradeFrom265()
- {
- this.ProcessText(true, true);
- if (this.mShrinkToFit)
- {
- this.overflowMethod = UILabel.Overflow.ShrinkContent;
- this.mMaxLineCount = 0;
- }
- if (this.mMaxLineWidth != 0)
- {
- base.width = this.mMaxLineWidth;
- this.overflowMethod = ((this.mMaxLineCount <= 0) ? UILabel.Overflow.ShrinkContent : UILabel.Overflow.ResizeHeight);
- }
- else
- {
- this.overflowMethod = UILabel.Overflow.ResizeFreely;
- }
- if (this.mMaxLineHeight != 0)
- {
- base.height = this.mMaxLineHeight;
- }
- if (this.mFont != null)
- {
- int defaultSize = this.mFont.defaultSize;
- if (base.height < defaultSize)
- {
- base.height = defaultSize;
- }
- this.fontSize = defaultSize;
- }
- this.mMaxLineWidth = 0;
- this.mMaxLineHeight = 0;
- this.mShrinkToFit = false;
- NGUITools.UpdateWidgetCollider(base.gameObject, true);
- }
- protected override void OnAnchor()
- {
- if (this.mOverflow == UILabel.Overflow.ResizeFreely)
- {
- if (base.isFullyAnchored)
- {
- this.mOverflow = UILabel.Overflow.ShrinkContent;
- }
- }
- else if (this.mOverflow == UILabel.Overflow.ResizeHeight && this.topAnchor.target != null && this.bottomAnchor.target != null)
- {
- this.mOverflow = UILabel.Overflow.ShrinkContent;
- }
- base.OnAnchor();
- }
- private void ProcessAndRequest()
- {
- if (this.ambigiousFont != null)
- {
- this.ProcessText();
- }
- }
- protected override void OnStart()
- {
- base.OnStart();
- if (this.mLineWidth > 0f)
- {
- this.mMaxLineWidth = Mathf.RoundToInt(this.mLineWidth);
- this.mLineWidth = 0f;
- }
- if (!this.mMultiline)
- {
- this.mMaxLineCount = 1;
- this.mMultiline = true;
- }
- this.mPremultiply = (this.material != null && this.material.shader != null && this.material.shader.name.Contains("Premultiplied"));
- this.ProcessAndRequest();
- }
- public override void MarkAsChanged()
- {
- this.shouldBeProcessed = true;
- base.MarkAsChanged();
- }
- public void ProcessText()
- {
- this.ProcessText(false, true);
- }
- private void ProcessText(bool legacyMode, bool full)
- {
- if (!this.isValid)
- {
- return;
- }
- this.mChanged = true;
- this.shouldBeProcessed = false;
- float num = this.mDrawRegion.z - this.mDrawRegion.x;
- float num2 = this.mDrawRegion.w - this.mDrawRegion.y;
- NGUIText.rectWidth = ((!legacyMode) ? base.width : ((this.mMaxLineWidth == 0) ? 1000000 : this.mMaxLineWidth));
- NGUIText.rectHeight = ((!legacyMode) ? base.height : ((this.mMaxLineHeight == 0) ? 1000000 : this.mMaxLineHeight));
- NGUIText.regionWidth = ((num == 1f) ? NGUIText.rectWidth : Mathf.RoundToInt((float)NGUIText.rectWidth * num));
- NGUIText.regionHeight = ((num2 == 1f) ? NGUIText.rectHeight : Mathf.RoundToInt((float)NGUIText.rectHeight * num2));
- this.mPrintedSize = Mathf.Abs((!legacyMode) ? this.defaultFontSize : Mathf.RoundToInt(base.cachedTransform.localScale.x));
- this.mScale = 1f;
- if (NGUIText.regionWidth < 1 || NGUIText.regionHeight < 0)
- {
- this.mProcessedText = string.Empty;
- return;
- }
- bool flag = this.trueTypeFont != null;
- if (flag && this.keepCrisp)
- {
- UIRoot root = base.root;
- if (root != null)
- {
- this.mDensity = ((!(root != null)) ? 1f : root.pixelSizeAdjustment);
- }
- }
- else
- {
- this.mDensity = 1f;
- }
- if (full)
- {
- this.UpdateNGUIText();
- }
- if (this.mOverflow == UILabel.Overflow.ResizeFreely)
- {
- NGUIText.rectWidth = 1000000;
- NGUIText.regionWidth = 1000000;
- }
- if (this.mOverflow == UILabel.Overflow.ResizeFreely || this.mOverflow == UILabel.Overflow.ResizeHeight)
- {
- NGUIText.rectHeight = 1000000;
- NGUIText.regionHeight = 1000000;
- }
- if (this.mPrintedSize > 0)
- {
- bool keepCrisp = this.keepCrisp;
- for (int i = this.mPrintedSize; i > 0; i--)
- {
- if (keepCrisp)
- {
- this.mPrintedSize = i;
- NGUIText.fontSize = this.mPrintedSize;
- }
- else
- {
- this.mScale = (float)i / (float)this.mPrintedSize;
- NGUIText.fontScale = ((!flag) ? ((float)this.mFontSize / (float)this.mFont.defaultSize * this.mScale) : this.mScale);
- }
- NGUIText.Update(false);
- bool flag2 = NGUIText.WrapText(this.mText, out this.mProcessedText, true);
- if (this.mOverflow != UILabel.Overflow.ShrinkContent || flag2)
- {
- if (this.mOverflow == UILabel.Overflow.ResizeFreely)
- {
- this.mCalculatedSize = NGUIText.CalculatePrintedSize(this.mProcessedText);
- this.mWidth = Mathf.Max(this.minWidth, Mathf.RoundToInt(this.mCalculatedSize.x));
- if (num != 1f)
- {
- this.mWidth = Mathf.RoundToInt((float)this.mWidth / num);
- }
- this.mHeight = Mathf.Max(this.minHeight, Mathf.RoundToInt(this.mCalculatedSize.y));
- if (num2 != 1f)
- {
- this.mHeight = Mathf.RoundToInt((float)this.mHeight / num2);
- }
- if ((this.mWidth & 1) == 1)
- {
- this.mWidth++;
- }
- if ((this.mHeight & 1) == 1)
- {
- this.mHeight++;
- }
- }
- else if (this.mOverflow == UILabel.Overflow.ResizeHeight)
- {
- this.mCalculatedSize = NGUIText.CalculatePrintedSize(this.mProcessedText);
- this.mHeight = Mathf.Max(this.minHeight, Mathf.RoundToInt(this.mCalculatedSize.y));
- if (num2 != 1f)
- {
- this.mHeight = Mathf.RoundToInt((float)this.mHeight / num2);
- }
- if ((this.mHeight & 1) == 1)
- {
- this.mHeight++;
- }
- }
- else
- {
- this.mCalculatedSize = NGUIText.CalculatePrintedSize(this.mProcessedText);
- }
- if (legacyMode)
- {
- base.width = Mathf.RoundToInt(this.mCalculatedSize.x);
- base.height = Mathf.RoundToInt(this.mCalculatedSize.y);
- base.cachedTransform.localScale = Vector3.one;
- }
- break;
- }
- if (--i <= 1)
- {
- break;
- }
- }
- }
- else
- {
- base.cachedTransform.localScale = Vector3.one;
- this.mProcessedText = string.Empty;
- this.mScale = 1f;
- }
- if (full)
- {
- NGUIText.bitmapFont = null;
- NGUIText.dynamicFont = null;
- }
- }
- public override void MakePixelPerfect()
- {
- if (this.ambigiousFont != null)
- {
- Vector3 localPosition = base.cachedTransform.localPosition;
- localPosition.x = (float)Mathf.RoundToInt(localPosition.x);
- localPosition.y = (float)Mathf.RoundToInt(localPosition.y);
- localPosition.z = (float)Mathf.RoundToInt(localPosition.z);
- base.cachedTransform.localPosition = localPosition;
- base.cachedTransform.localScale = Vector3.one;
- if (this.mOverflow == UILabel.Overflow.ResizeFreely)
- {
- this.AssumeNaturalSize();
- }
- else
- {
- int width = base.width;
- int height = base.height;
- UILabel.Overflow overflow = this.mOverflow;
- if (overflow != UILabel.Overflow.ResizeHeight)
- {
- this.mWidth = 100000;
- }
- this.mHeight = 100000;
- this.mOverflow = UILabel.Overflow.ShrinkContent;
- this.ProcessText(false, true);
- this.mOverflow = overflow;
- int num = Mathf.RoundToInt(this.mCalculatedSize.x);
- int num2 = Mathf.RoundToInt(this.mCalculatedSize.y);
- num = Mathf.Max(num, base.minWidth);
- num2 = Mathf.Max(num2, base.minHeight);
- this.mWidth = Mathf.Max(width, num);
- this.mHeight = Mathf.Max(height, num2);
- this.MarkAsChanged();
- }
- }
- else
- {
- base.MakePixelPerfect();
- }
- }
- public void AssumeNaturalSize()
- {
- if (this.ambigiousFont != null)
- {
- this.mWidth = 100000;
- this.mHeight = 100000;
- this.ProcessText(false, true);
- this.mWidth = Mathf.RoundToInt(this.mCalculatedSize.x);
- this.mHeight = Mathf.RoundToInt(this.mCalculatedSize.y);
- if ((this.mWidth & 1) == 1)
- {
- this.mWidth++;
- }
- if ((this.mHeight & 1) == 1)
- {
- this.mHeight++;
- }
- this.MarkAsChanged();
- }
- }
- [Obsolete("Use UILabel.GetCharacterAtPosition instead")]
- public int GetCharacterIndex(Vector3 worldPos)
- {
- return this.GetCharacterIndexAtPosition(worldPos, false);
- }
- [Obsolete("Use UILabel.GetCharacterAtPosition instead")]
- public int GetCharacterIndex(Vector2 localPos)
- {
- return this.GetCharacterIndexAtPosition(localPos, false);
- }
- public int GetCharacterIndexAtPosition(Vector3 worldPos, bool precise)
- {
- Vector2 localPos = base.cachedTransform.InverseTransformPoint(worldPos);
- return this.GetCharacterIndexAtPosition(localPos, precise);
- }
- public int GetCharacterIndexAtPosition(Vector2 localPos, bool precise)
- {
- if (this.isValid)
- {
- string processedText = this.processedText;
- if (string.IsNullOrEmpty(processedText))
- {
- return 0;
- }
- this.UpdateNGUIText();
- if (precise)
- {
- NGUIText.PrintExactCharacterPositions(processedText, UILabel.mTempVerts, UILabel.mTempIndices);
- }
- else
- {
- NGUIText.PrintApproximateCharacterPositions(processedText, UILabel.mTempVerts, UILabel.mTempIndices);
- }
- if (UILabel.mTempVerts.size > 0)
- {
- this.ApplyOffset(UILabel.mTempVerts, 0);
- int result = (!precise) ? NGUIText.GetApproximateCharacterIndex(UILabel.mTempVerts, UILabel.mTempIndices, localPos) : NGUIText.GetExactCharacterIndex(UILabel.mTempVerts, UILabel.mTempIndices, localPos);
- UILabel.mTempVerts.Clear();
- UILabel.mTempIndices.Clear();
- NGUIText.bitmapFont = null;
- NGUIText.dynamicFont = null;
- return result;
- }
- NGUIText.bitmapFont = null;
- NGUIText.dynamicFont = null;
- }
- return 0;
- }
- public string GetWordAtPosition(Vector3 worldPos)
- {
- int characterIndexAtPosition = this.GetCharacterIndexAtPosition(worldPos, true);
- return this.GetWordAtCharacterIndex(characterIndexAtPosition);
- }
- public string GetWordAtPosition(Vector2 localPos)
- {
- int characterIndexAtPosition = this.GetCharacterIndexAtPosition(localPos, true);
- return this.GetWordAtCharacterIndex(characterIndexAtPosition);
- }
- public string GetWordAtCharacterIndex(int characterIndex)
- {
- if (characterIndex != -1 && characterIndex < this.mText.Length)
- {
- int num = this.mText.LastIndexOfAny(new char[]
- {
- ' ',
- '\n'
- }, characterIndex) + 1;
- int num2 = this.mText.IndexOfAny(new char[]
- {
- ' ',
- '\n',
- ',',
- '.'
- }, characterIndex);
- if (num2 == -1)
- {
- num2 = this.mText.Length;
- }
- if (num != num2)
- {
- int num3 = num2 - num;
- if (num3 > 0)
- {
- string text = this.mText.Substring(num, num3);
- return NGUIText.StripSymbols(text);
- }
- }
- }
- return null;
- }
- public string GetUrlAtPosition(Vector3 worldPos)
- {
- return this.GetUrlAtCharacterIndex(this.GetCharacterIndexAtPosition(worldPos, true));
- }
- public string GetUrlAtPosition(Vector2 localPos)
- {
- return this.GetUrlAtCharacterIndex(this.GetCharacterIndexAtPosition(localPos, true));
- }
- public string GetUrlAtCharacterIndex(int characterIndex)
- {
- if (characterIndex != -1 && characterIndex < this.mText.Length - 6)
- {
- int num;
- if (this.mText[characterIndex] == '[' && this.mText[characterIndex + 1] == 'u' && this.mText[characterIndex + 2] == 'r' && this.mText[characterIndex + 3] == 'l' && this.mText[characterIndex + 4] == '=')
- {
- num = characterIndex;
- }
- else
- {
- num = this.mText.LastIndexOf("[url=", characterIndex);
- }
- if (num == -1)
- {
- return null;
- }
- num += 5;
- int num2 = this.mText.IndexOf("]", num);
- if (num2 == -1)
- {
- return null;
- }
- int num3 = this.mText.IndexOf("[/url]", num2);
- if (num3 == -1 || characterIndex <= num3)
- {
- return this.mText.Substring(num, num2 - num);
- }
- }
- return null;
- }
- public int GetCharacterIndex(int currentIndex, KeyCode key)
- {
- if (this.isValid)
- {
- string processedText = this.processedText;
- if (string.IsNullOrEmpty(processedText))
- {
- return 0;
- }
- int defaultFontSize = this.defaultFontSize;
- this.UpdateNGUIText();
- NGUIText.PrintApproximateCharacterPositions(processedText, UILabel.mTempVerts, UILabel.mTempIndices);
- if (UILabel.mTempVerts.size > 0)
- {
- this.ApplyOffset(UILabel.mTempVerts, 0);
- int i = 0;
- while (i < UILabel.mTempIndices.size)
- {
- if (UILabel.mTempIndices[i] == currentIndex)
- {
- Vector2 pos = UILabel.mTempVerts[i];
- if (key == KeyCode.UpArrow)
- {
- pos.y += (float)defaultFontSize + this.effectiveSpacingY;
- }
- else if (key == KeyCode.DownArrow)
- {
- pos.y -= (float)defaultFontSize + this.effectiveSpacingY;
- }
- else if (key == KeyCode.Home)
- {
- pos.x -= 1000f;
- }
- else if (key == KeyCode.End)
- {
- pos.x += 1000f;
- }
- int approximateCharacterIndex = NGUIText.GetApproximateCharacterIndex(UILabel.mTempVerts, UILabel.mTempIndices, pos);
- if (approximateCharacterIndex == currentIndex)
- {
- break;
- }
- UILabel.mTempVerts.Clear();
- UILabel.mTempIndices.Clear();
- return approximateCharacterIndex;
- }
- else
- {
- i++;
- }
- }
- UILabel.mTempVerts.Clear();
- UILabel.mTempIndices.Clear();
- }
- NGUIText.bitmapFont = null;
- NGUIText.dynamicFont = null;
- if (key == KeyCode.UpArrow || key == KeyCode.Home)
- {
- return 0;
- }
- if (key == KeyCode.DownArrow || key == KeyCode.End)
- {
- return processedText.Length;
- }
- }
- return currentIndex;
- }
- public void PrintOverlay(int start, int end, UIGeometry caret, UIGeometry highlight, Color caretColor, Color highlightColor)
- {
- if (caret != null)
- {
- caret.Clear();
- }
- if (highlight != null)
- {
- highlight.Clear();
- }
- if (!this.isValid)
- {
- return;
- }
- string processedText = this.processedText;
- this.UpdateNGUIText();
- int size = caret.verts.size;
- Vector2 item = new Vector2(0.5f, 0.5f);
- float finalAlpha = this.finalAlpha;
- if (highlight != null && start != end)
- {
- int size2 = highlight.verts.size;
- NGUIText.PrintCaretAndSelection(processedText, start, end, caret.verts, highlight.verts);
- if (highlight.verts.size > size2)
- {
- this.ApplyOffset(highlight.verts, size2);
- Color32 item2 = new Color(highlightColor.r, highlightColor.g, highlightColor.b, highlightColor.a * finalAlpha);
- for (int i = size2; i < highlight.verts.size; i++)
- {
- highlight.uvs.Add(item);
- highlight.cols.Add(item2);
- }
- }
- }
- else
- {
- NGUIText.PrintCaretAndSelection(processedText, start, end, caret.verts, null);
- }
- this.ApplyOffset(caret.verts, size);
- Color32 item3 = new Color(caretColor.r, caretColor.g, caretColor.b, caretColor.a * finalAlpha);
- for (int j = size; j < caret.verts.size; j++)
- {
- caret.uvs.Add(item);
- caret.cols.Add(item3);
- }
- NGUIText.bitmapFont = null;
- NGUIText.dynamicFont = null;
- }
- public override void OnFill(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols)
- {
- if (!this.isValid)
- {
- return;
- }
- int num = verts.size;
- Color color = base.color;
- color.a = this.finalAlpha;
- if (this.mFont != null && this.mFont.premultipliedAlphaShader)
- {
- color = NGUITools.ApplyPMA(color);
- }
- if (QualitySettings.activeColorSpace == ColorSpace.Linear)
- {
- color.r = Mathf.Pow(color.r, 2.2f);
- color.g = Mathf.Pow(color.g, 2.2f);
- color.b = Mathf.Pow(color.b, 2.2f);
- }
- string processedText = this.processedText;
- int size = verts.size;
- this.UpdateNGUIText();
- NGUIText.tint = color;
- NGUIText.Print(processedText, verts, uvs, cols);
- NGUIText.bitmapFont = null;
- NGUIText.dynamicFont = null;
- Vector2 vector = this.ApplyOffset(verts, size);
- if (this.mFont != null && this.mFont.packedFontShader)
- {
- return;
- }
- if (this.effectStyle != UILabel.Effect.None)
- {
- int size2 = verts.size;
- vector.x = this.mEffectDistance.x;
- vector.y = this.mEffectDistance.y;
- this.ApplyShadow(verts, uvs, cols, num, size2, vector.x, -vector.y);
- if (this.effectStyle == UILabel.Effect.Outline || this.effectStyle == UILabel.Effect.Outline8)
- {
- num = size2;
- size2 = verts.size;
- this.ApplyShadow(verts, uvs, cols, num, size2, -vector.x, vector.y);
- num = size2;
- size2 = verts.size;
- this.ApplyShadow(verts, uvs, cols, num, size2, vector.x, vector.y);
- num = size2;
- size2 = verts.size;
- this.ApplyShadow(verts, uvs, cols, num, size2, -vector.x, -vector.y);
- if (this.effectStyle == UILabel.Effect.Outline8)
- {
- num = size2;
- size2 = verts.size;
- this.ApplyShadow(verts, uvs, cols, num, size2, -vector.x, 0f);
- num = size2;
- size2 = verts.size;
- this.ApplyShadow(verts, uvs, cols, num, size2, vector.x, 0f);
- num = size2;
- size2 = verts.size;
- this.ApplyShadow(verts, uvs, cols, num, size2, 0f, vector.y);
- num = size2;
- size2 = verts.size;
- this.ApplyShadow(verts, uvs, cols, num, size2, 0f, -vector.y);
- }
- }
- }
- if (this.onPostFill != null)
- {
- this.onPostFill(this, num, verts, uvs, cols);
- }
- }
- public Vector2 ApplyOffset(BetterList<Vector3> verts, int start)
- {
- Vector2 pivotOffset = base.pivotOffset;
- float num = Mathf.Lerp(0f, (float)(-(float)this.mWidth), pivotOffset.x);
- float num2 = Mathf.Lerp((float)this.mHeight, 0f, pivotOffset.y) + Mathf.Lerp(this.mCalculatedSize.y - (float)this.mHeight, 0f, pivotOffset.y);
- num = Mathf.Round(num);
- num2 = Mathf.Round(num2);
- for (int i = start; i < verts.size; i++)
- {
- Vector3[] buffer = verts.buffer;
- int num3 = i;
- buffer[num3].x = buffer[num3].x + num;
- Vector3[] buffer2 = verts.buffer;
- int num4 = i;
- buffer2[num4].y = buffer2[num4].y + num2;
- }
- return new Vector2(num, num2);
- }
- public void ApplyShadow(BetterList<Vector3> verts, BetterList<Vector2> uvs, BetterList<Color32> cols, int start, int end, float x, float y)
- {
- Color color = this.mEffectColor;
- color.a *= this.finalAlpha;
- Color32 color2 = (!(this.bitmapFont != null) || !this.bitmapFont.premultipliedAlphaShader) ? color : NGUITools.ApplyPMA(color);
- for (int i = start; i < end; i++)
- {
- verts.Add(verts.buffer[i]);
- uvs.Add(uvs.buffer[i]);
- cols.Add(cols.buffer[i]);
- Vector3 vector = verts.buffer[i];
- vector.x += x;
- vector.y += y;
- verts.buffer[i] = vector;
- Color32 color3 = cols.buffer[i];
- if (color3.a == 255)
- {
- cols.buffer[i] = color2;
- }
- else
- {
- Color color4 = color;
- color4.a = (float)color3.a / 255f * color.a;
- cols.buffer[i] = ((!(this.bitmapFont != null) || !this.bitmapFont.premultipliedAlphaShader) ? color4 : NGUITools.ApplyPMA(color4));
- }
- }
- }
- public int CalculateOffsetToFit(string text)
- {
- this.UpdateNGUIText();
- NGUIText.encoding = false;
- NGUIText.symbolStyle = NGUIText.SymbolStyle.None;
- int result = NGUIText.CalculateOffsetToFit(text);
- NGUIText.bitmapFont = null;
- NGUIText.dynamicFont = null;
- return result;
- }
- public void SetCurrentProgress()
- {
- if (UIProgressBar.current != null)
- {
- this.text = UIProgressBar.current.value.ToString("F");
- }
- }
- public void SetCurrentPercent()
- {
- if (UIProgressBar.current != null)
- {
- this.text = Mathf.RoundToInt(UIProgressBar.current.value * 100f) + "%";
- }
- }
- public void SetCurrentSelection()
- {
- if (UIPopupList.current != null)
- {
- if (UIPopupList.current.isLocalized)
- {
- Localize localize = base.gameObject.GetComponent<Localize>();
- if (localize == null)
- {
- localize = base.gameObject.AddComponent<Localize>();
- }
- localize.SetTerm(UIPopupList.current.value.Replace("\r", string.Empty));
- }
- else
- {
- this.text = UIPopupList.current.value;
- }
- }
- }
- public bool Wrap(string text, out string final)
- {
- return this.Wrap(text, out final, 1000000);
- }
- public bool Wrap(string text, out string final, int height)
- {
- this.UpdateNGUIText();
- NGUIText.rectHeight = height;
- NGUIText.regionHeight = height;
- bool result = NGUIText.WrapText(text, out final);
- NGUIText.bitmapFont = null;
- NGUIText.dynamicFont = null;
- return result;
- }
- public void UpdateNGUIText()
- {
- Font trueTypeFont = this.trueTypeFont;
- bool flag = trueTypeFont != null;
- NGUIText.fontSize = this.mPrintedSize;
- NGUIText.fontStyle = this.mFontStyle;
- NGUIText.rectWidth = this.mWidth;
- NGUIText.rectHeight = this.mHeight;
- NGUIText.regionWidth = Mathf.RoundToInt((float)this.mWidth * (this.mDrawRegion.z - this.mDrawRegion.x));
- NGUIText.regionHeight = Mathf.RoundToInt((float)this.mHeight * (this.mDrawRegion.w - this.mDrawRegion.y));
- NGUIText.gradient = (this.mApplyGradient && (this.mFont == null || !this.mFont.packedFontShader));
- NGUIText.gradientTop = this.mGradientTop;
- NGUIText.gradientBottom = this.mGradientBottom;
- NGUIText.encoding = this.mEncoding;
- NGUIText.premultiply = this.mPremultiply;
- NGUIText.symbolStyle = this.mSymbols;
- NGUIText.maxLines = this.mMaxLineCount;
- NGUIText.spacingX = this.effectiveSpacingX;
- NGUIText.spacingY = this.effectiveSpacingY;
- NGUIText.fontScale = ((!flag) ? ((float)this.mFontSize / (float)this.mFont.defaultSize * this.mScale) : this.mScale);
- if (this.mFont != null)
- {
- NGUIText.bitmapFont = this.mFont;
- for (;;)
- {
- UIFont replacement = NGUIText.bitmapFont.replacement;
- if (replacement == null)
- {
- break;
- }
- NGUIText.bitmapFont = replacement;
- }
- if (NGUIText.bitmapFont.isDynamic)
- {
- NGUIText.dynamicFont = NGUIText.bitmapFont.dynamicFont;
- NGUIText.bitmapFont = null;
- }
- else
- {
- NGUIText.dynamicFont = null;
- }
- }
- else
- {
- NGUIText.dynamicFont = trueTypeFont;
- NGUIText.bitmapFont = null;
- }
- if (flag && this.keepCrisp)
- {
- UIRoot root = base.root;
- if (root != null)
- {
- NGUIText.pixelDensity = ((!(root != null)) ? 1f : root.pixelSizeAdjustment);
- }
- }
- else
- {
- NGUIText.pixelDensity = 1f;
- }
- if (this.mDensity != NGUIText.pixelDensity)
- {
- this.ProcessText(false, false);
- NGUIText.rectWidth = this.mWidth;
- NGUIText.rectHeight = this.mHeight;
- NGUIText.regionWidth = Mathf.RoundToInt((float)this.mWidth * (this.mDrawRegion.z - this.mDrawRegion.x));
- NGUIText.regionHeight = Mathf.RoundToInt((float)this.mHeight * (this.mDrawRegion.w - this.mDrawRegion.y));
- }
- if (this.alignment == NGUIText.Alignment.Automatic)
- {
- UIWidget.Pivot pivot = base.pivot;
- if (pivot == UIWidget.Pivot.Left || pivot == UIWidget.Pivot.TopLeft || pivot == UIWidget.Pivot.BottomLeft)
- {
- NGUIText.alignment = NGUIText.Alignment.Left;
- }
- else if (pivot == UIWidget.Pivot.Right || pivot == UIWidget.Pivot.TopRight || pivot == UIWidget.Pivot.BottomRight)
- {
- NGUIText.alignment = NGUIText.Alignment.Right;
- }
- else
- {
- NGUIText.alignment = NGUIText.Alignment.Center;
- }
- }
- else
- {
- NGUIText.alignment = this.alignment;
- }
- NGUIText.Update();
- }
- public UILabel.Crispness keepCrispWhenShrunk = UILabel.Crispness.OnDesktop;
- [HideInInspector]
- [SerializeField]
- private Font mTrueTypeFont;
- [HideInInspector]
- [SerializeField]
- private UIFont mFont;
- [Multiline(6)]
- [HideInInspector]
- [SerializeField]
- private string mText = string.Empty;
- [HideInInspector]
- [SerializeField]
- private int mFontSize = 16;
- [HideInInspector]
- [SerializeField]
- private FontStyle mFontStyle;
- [HideInInspector]
- [SerializeField]
- private NGUIText.Alignment mAlignment;
- [HideInInspector]
- [SerializeField]
- private bool mEncoding = true;
- [HideInInspector]
- [SerializeField]
- private int mMaxLineCount;
- [HideInInspector]
- [SerializeField]
- private UILabel.Effect mEffectStyle;
- [HideInInspector]
- [SerializeField]
- private Color mEffectColor = Color.black;
- [HideInInspector]
- [SerializeField]
- private NGUIText.SymbolStyle mSymbols = NGUIText.SymbolStyle.Normal;
- [HideInInspector]
- [SerializeField]
- private Vector2 mEffectDistance = Vector2.one;
- [HideInInspector]
- [SerializeField]
- private UILabel.Overflow mOverflow;
- [HideInInspector]
- [SerializeField]
- private Material mMaterial;
- [HideInInspector]
- [SerializeField]
- private bool mApplyGradient;
- [HideInInspector]
- [SerializeField]
- private Color mGradientTop = Color.white;
- [HideInInspector]
- [SerializeField]
- private Color mGradientBottom = new Color(0.7f, 0.7f, 0.7f);
- [HideInInspector]
- [SerializeField]
- private int mSpacingX;
- [HideInInspector]
- [SerializeField]
- private int mSpacingY;
- [HideInInspector]
- [SerializeField]
- private bool mUseFloatSpacing;
- [HideInInspector]
- [SerializeField]
- private float mFloatSpacingX;
- [HideInInspector]
- [SerializeField]
- private float mFloatSpacingY;
- [HideInInspector]
- [SerializeField]
- private bool mShrinkToFit;
- [HideInInspector]
- [SerializeField]
- private int mMaxLineWidth;
- [HideInInspector]
- [SerializeField]
- private int mMaxLineHeight;
- [HideInInspector]
- [SerializeField]
- private float mLineWidth;
- [HideInInspector]
- [SerializeField]
- private bool mMultiline = true;
- [NonSerialized]
- private Font mActiveTTF;
- private float mDensity = 1f;
- private bool mShouldBeProcessed = true;
- private string mProcessedText;
- private bool mPremultiply;
- private Vector2 mCalculatedSize = Vector2.zero;
- private float mScale = 1f;
- private int mPrintedSize;
- private int mLastWidth;
- private int mLastHeight;
- private static BetterList<UILabel> mList = new BetterList<UILabel>();
- private static Dictionary<Font, int> mFontUsage = new Dictionary<Font, int>();
- private static BetterList<Vector3> mTempVerts = new BetterList<Vector3>();
- private static BetterList<int> mTempIndices = new BetterList<int>();
- [CompilerGenerated]
- private static Font.FontTextureRebuildCallback <>f__mg$cache0;
- public enum Effect
- {
- None,
- Shadow,
- Outline,
- Outline8
- }
- public enum Overflow
- {
- ShrinkContent,
- ClampContent,
- ResizeFreely,
- ResizeHeight
- }
- public enum Crispness
- {
- Never,
- OnDesktop,
- Always
- }
- }
|