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 verts, BetterList uvs, BetterList 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 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 verts, BetterList uvs, BetterList 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) { List itemTerms = UIPopupList.current.itemTerms; List items = UIPopupList.current.items; Localize localize = base.gameObject.GetComponent(); if (localize == null) { localize = base.gameObject.AddComponent(); } string term = UIPopupList.current.value.Replace("\r", string.Empty); if (itemTerms != null && itemTerms.Count == items.Count) { string b = UIPopupList.current.value.Replace("\r", string.Empty); for (int i = 0; i < items.Count; i++) { if (items[i].Replace("\r", string.Empty) == b) { if (!string.IsNullOrEmpty(itemTerms[i])) { term = itemTerms[i]; } break; } } } localize.SetTerm(term); } 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 mList = new BetterList(); private static Dictionary mFontUsage = new Dictionary(); private static BetterList mTempVerts = new BetterList(); private static BetterList mTempIndices = new BetterList(); [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 } }