1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729 |
- using System;
- using System.Collections.Generic;
- using System.Runtime.CompilerServices;
- 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)
- {
- this.text = ((!UIPopupList.current.isLocalized) ? UIPopupList.current.value : Localization.Get(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
- }
- }
|