private void CreateItemLabel(CharInfoNode node) { //var objres = ResourceManager.PrepareResourceSync<GameObject>("UI/ChatMain/ChatLableNode.prefab"); //var obj = Instantiate(objres) as GameObject; var obj = ComplexObjectPool.NewObjectSync("UI/ChatMain/ChatLableNode.prefab"); if (obj == null) { return; } var objTransform = obj.transform; //objTransform.parent = BackGround.transform; objTransform.SetParentEX(BackGround.transform); obj.gameObject.collider.enabled = true; obj.SetActive(true); var label = obj.GetComponent <UILabel>(); mColliderObjects.Add(obj.gameObject); var sbstr = ""; var text = ""; label.fontSize = FontSize; NGUIText.fontSize = label.fontSize; NGUIText.finalSize = label.fontSize; NGUIText.dynamicFont = label.trueTypeFont; NGUIText.regionWidth = MaxLineWidth - mPositionX; NGUIText.pixelDensity = 1.0f; NGUIText.maxLines = 10000; NGUIText.regionHeight = 10000; NGUIText.finalLineHeight = label.fontSize; NGUIText.fontScale = 1.0f; var chatLogic = obj.GetComponent <ChatLableLogic>(); chatLogic.InfoNode = node; var nodeNodeDataExDataCount0 = node.NodeData.ExData.Count; var tbTable = Table.GetItemBase(node.NodeData.Id); var value = tbTable.Name; var itemClor = GameUtils.GetTableColor(tbTable.Quality); //label.color = itemClor; NGUIText.WrapText(value, out sbstr, false, true); var index = sbstr.IndexOf("\n"); label.text = "[" + GameUtils.ColorToString(itemClor) + "]" + "[" + value + "]" + "[-]"; if (index > -1) { mPositionX = (int)(FontSize * 0.5f); var height = 0; if (mLineFace) { height = (int)(FontSize * FaceScale); mLineFace = false; } else { height = FontSize; } height += mLineOffset; mPositionY -= height; BackGround.height += height; } label.gameObject.transform.localPosition = new Vector3(mPositionX, mPositionY, 0); objTransform.localScale = Vector3.one; AddPositionX(label.width); }
private void CreateTextLabel(string value, bool isNewTeam = false, CharInfoNode node = null) { var obj = ComplexObjectPool.NewObjectSync("UI/ChatMain/ChatLableNode.prefab"); if (obj == null) { return; } var objTransform = obj.transform; //objTransform.parent = BackGround.transform; objTransform.SetParentEX(BackGround.transform); obj.gameObject.collider.enabled = false; obj.SetActive(false); NetManager.Instance.StartCoroutine(DelayShowTextLabel(obj)); var label = obj.GetComponent <UILabel>(); var sbstr = ""; var text = ""; label.fontSize = FontSize; NGUIText.fontSize = label.fontSize; NGUIText.finalSize = label.fontSize; NGUIText.dynamicFont = label.trueTypeFont; if (mPositionX > MaxLineWidth) { ChangeLine(); } NGUIText.regionWidth = MaxLineWidth - mPositionX; NGUIText.maxLines = 10000; NGUIText.pixelDensity = 1.0f; NGUIText.regionHeight = 10000; NGUIText.finalLineHeight = label.fontSize; NGUIText.fontScale = 1.0f; NGUIText.WrapText(value, out sbstr, false, true); var index = sbstr.IndexOf("\n"); if (index > -1) { text = sbstr.Substring(0, index); sbstr = sbstr.Remove(0, text.Length).Trim(); if (!string.IsNullOrEmpty(sbstr)) { int symbol = 0; var lastSymbol1 = text.LastIndexOf('['); var lastSymbol2 = text.LastIndexOf(']'); if (lastSymbol1 >= 0 && lastSymbol2 >= 0 && 7 == lastSymbol2 - lastSymbol1) { var lastEnd = text.LastIndexOf("[-]"); if ((lastEnd < 0 || lastEnd < lastSymbol1) && sbstr.IndexOf("[-]") >= 0) { text += "[-]"; var colstr = text.Substring(lastSymbol1, 8); sbstr = colstr + sbstr; } } } } else { text = sbstr; sbstr = sbstr.Remove(0, text.Length).Trim(); } SetLableStroke(label); SetLableColor(label, text); objTransform.localPosition = new Vector3(mPositionX, mPositionY, 0); objTransform.localScale = Vector3.one; //positionX += label.width; AddPositionX(label.width); //sbstr = sbstr.Remove(0, text.Length); if (isNewTeam || mChatMessageData.Ladder == -1) { obj.gameObject.collider.enabled = true; var chatLogic = obj.GetComponent <ChatLableLogic>(); chatLogic.InfoNode = node; chatLogic.param = mChatMessageData.Ladder; if (null != label) { NGUITools.UpdateWidgetCollider(label.gameObject); } } if (!string.IsNullOrEmpty(sbstr)) { ChangeLine(); sbstr = sbstr.Replace("\n", ""); CreateTextLabel(sbstr, isNewTeam, node); } }
private void ProcessText(bool legacyMode, bool full) { if (isValid) { mChanged = true; shouldBeProcessed = false; float num = mDrawRegion.z - mDrawRegion.x; float num2 = mDrawRegion.w - mDrawRegion.y; NGUIText.rectWidth = ((!legacyMode) ? base.width : ((mMaxLineWidth == 0) ? 1000000 : mMaxLineWidth)); NGUIText.rectHeight = ((!legacyMode) ? base.height : ((mMaxLineHeight == 0) ? 1000000 : 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)); int value; if (legacyMode) { Vector3 localScale = base.cachedTransform.localScale; value = Mathf.RoundToInt(localScale.x); } else { value = defaultFontSize; } mPrintedSize = Mathf.Abs(value); mScale = 1f; if (NGUIText.regionWidth < 1 || NGUIText.regionHeight < 0) { mProcessedText = string.Empty; } else { bool flag = trueTypeFont != null; if (flag && this.keepCrisp) { UIRoot root = base.root; if (root != null) { mDensity = ((!(root != null)) ? 1f : root.pixelSizeAdjustment); } } else { mDensity = 1f; } if (full) { UpdateNGUIText(); } if (mOverflow == Overflow.ResizeFreely) { NGUIText.rectWidth = 1000000; NGUIText.regionWidth = 1000000; } if (mOverflow == Overflow.ResizeFreely || mOverflow == Overflow.ResizeHeight) { NGUIText.rectHeight = 1000000; NGUIText.regionHeight = 1000000; } if (mPrintedSize > 0) { bool keepCrisp = this.keepCrisp; int num3; for (num3 = mPrintedSize; num3 > 0; num3--) { if (keepCrisp) { mPrintedSize = num3; NGUIText.fontSize = mPrintedSize; } else { mScale = (float)num3 / (float)mPrintedSize; NGUIText.fontScale = ((!flag) ? ((float)mFontSize / (float)mFont.defaultSize * mScale) : mScale); } NGUIText.Update(request: false); bool flag2 = NGUIText.WrapText(mText, out mProcessedText, keepCharCount: true); if (mOverflow != 0 || flag2) { if (mOverflow == Overflow.ResizeFreely) { mCalculatedSize = NGUIText.CalculatePrintedSize(mProcessedText); mWidth = Mathf.Max(minWidth, Mathf.RoundToInt(mCalculatedSize.x)); if (num != 1f) { mWidth = Mathf.RoundToInt((float)mWidth / num); } mHeight = Mathf.Max(minHeight, Mathf.RoundToInt(mCalculatedSize.y)); if (num2 != 1f) { mHeight = Mathf.RoundToInt((float)mHeight / num2); } if ((mWidth & 1) == 1) { mWidth++; } if ((mHeight & 1) == 1) { mHeight++; } } else if (mOverflow == Overflow.ResizeHeight) { mCalculatedSize = NGUIText.CalculatePrintedSize(mProcessedText); mHeight = Mathf.Max(minHeight, Mathf.RoundToInt(mCalculatedSize.y)); if (num2 != 1f) { mHeight = Mathf.RoundToInt((float)mHeight / num2); } if ((mHeight & 1) == 1) { mHeight++; } } else { mCalculatedSize = NGUIText.CalculatePrintedSize(mProcessedText); } if (legacyMode) { base.width = Mathf.RoundToInt(mCalculatedSize.x); base.height = Mathf.RoundToInt(mCalculatedSize.y); base.cachedTransform.localScale = Vector3.one; } break; } if (--num3 <= 1) { break; } } } else { base.cachedTransform.localScale = Vector3.one; mProcessedText = string.Empty; mScale = 1f; } if (full) { NGUIText.bitmapFont = null; NGUIText.dynamicFont = null; } } } }
/// <summary> /// Process the raw text, called when something changes. /// </summary> void ProcessText(bool legacyMode) { if (!isValid) { return; } mChanged = true; hasChanged = false; int fs = fontSize; float ps = pixelSize; float invSize = 1f / ps; mPrintedSize = Mathf.Abs(legacyMode ? Mathf.RoundToInt(cachedTransform.localScale.x) : fs); float lw = legacyMode ? (mMaxLineWidth != 0 ? mMaxLineWidth * invSize : 1000000) : width * invSize; float lh = legacyMode ? (mMaxLineHeight != 0 ? mMaxLineHeight * invSize : 1000000) : height * invSize; if (mPrintedSize > 0) { for (;;) { mScale = (float)mPrintedSize / fs; bool fits = true; int pw = (mOverflow == Overflow.ResizeFreely) ? 100000 : Mathf.RoundToInt(lw / mScale); int ph = (mOverflow == Overflow.ResizeFreely || mOverflow == Overflow.ResizeHeight) ? 100000 : Mathf.RoundToInt(lh / mScale); if (lw > 0f || lh > 0f) { if (mFont != null) { fits = mFont.WrapText(mText, fs, out mProcessedText, pw, ph, mMaxLineCount, mEncoding, mSymbols); } #if DYNAMIC_FONT else { fits = NGUIText.WrapText(mText, mTrueTypeFont, fs, mFontStyle, pw, ph, mMaxLineCount, mEncoding, out mProcessedText); } #endif } else { mProcessedText = mText; } // Remember the final printed size if (!string.IsNullOrEmpty(mProcessedText)) { if (mFont != null) { mCalculatedSize = mFont.CalculatePrintedSize(mProcessedText, fs, mEncoding, mSymbols); } #if DYNAMIC_FONT else { mCalculatedSize = NGUIText.CalculatePrintedSize(mProcessedText, mTrueTypeFont, fs, mFontStyle, mEncoding); } #endif } else { mCalculatedSize = Vector2.zero; } if (mOverflow == Overflow.ResizeFreely) { mWidth = Mathf.RoundToInt(mCalculatedSize.x * ps); mHeight = Mathf.RoundToInt(mCalculatedSize.y * ps); } else if (mOverflow == Overflow.ResizeHeight) { mHeight = Mathf.RoundToInt(mCalculatedSize.y * ps); } else if (mOverflow == Overflow.ShrinkContent && !fits) { if (--mPrintedSize > 1) { continue; } } // Upgrade to the new system if (legacyMode) { width = Mathf.RoundToInt(mCalculatedSize.x * ps); height = Mathf.RoundToInt(mCalculatedSize.y * ps); cachedTransform.localScale = Vector3.one; } break; } } else { cachedTransform.localScale = Vector3.one; mProcessedText = ""; mScale = 1f; } }
private void CreateTextLabel(string value) { UILabel label; if (labelCaches.Count > 0) { label = labelCaches[0]; labelCaches.Remove(label); label.gameObject.SetActive(true); } else { GameObject go = GameObject.Instantiate(Label) as GameObject; go.SetActive(true); go.transform.parent = chatPos.transform; label = go.GetComponent <UILabel>(); go.transform.localScale = Vector3.one; } string sbstr = ""; string text = ""; NGUIText.fontSize = 27; NGUIText.finalSize = 27; NGUIText.dynamicFont = label.trueTypeFont; NGUIText.rectWidth = MaxLineWidth - positionX; NGUIText.maxLines = 10000; NGUIText.rectHeight = 10000; NGUIText.WrapText(value, out sbstr); int index = sbstr.IndexOf("\n"); if (index > -1) { text = sbstr.Substring(0, index); } else { text = sbstr; } if (!string.IsNullOrEmpty(infoColor)) { label.text = co + text + "[-]"; } else { label.text = co + text + "[-]"; } label.gameObject.transform.localPosition = new Vector3(positionX, positionY, 0); positionX += (label.width); labelCur.Add(label); sbstr = sbstr.Remove(0, text.Length); if (labelNameWidth == 0) { labelNameWidth = label.width; } if (label.text.Contains("[url=") || label.text.StartsWith("[url=")) { if (label.GetComponent <BoxCollider>() == null) { label.gameObject.AddComponent <BoxCollider>(); NGUITools.UpdateWidgetCollider(label.gameObject); } } if (sbstr.Length > 0) { line++; positionX = labelNameWidth; positionY -= (cellHeight + 4); //back.height += (cellHeight+offset); sbstr = sbstr.Replace("\n", ""); CreateTextLabel(sbstr); } }
/// <summary> /// Process the raw text, called when something changes. /// </summary> void ProcessText(bool legacyMode) { if (!isValid) { return; } mChanged = true; shouldBeProcessed = false; NGUIText.rectWidth = legacyMode ? (mMaxLineWidth != 0 ? mMaxLineWidth : 1000000) : width; NGUIText.rectHeight = legacyMode ? (mMaxLineHeight != 0 ? mMaxLineHeight : 1000000) : height; mPrintedSize = Mathf.Abs(legacyMode ? Mathf.RoundToInt(cachedTransform.localScale.x) : defaultFontSize); mScale = 1f; if (NGUIText.rectWidth < 1 || NGUIText.rectHeight < 0) { mProcessedText = ""; return; } UpdateNGUIText(mPrintedSize, mWidth, mHeight); bool isDynamic = (trueTypeFont != null); if (mOverflow == Overflow.ResizeFreely) { NGUIText.rectWidth = 1000000; } if (mOverflow == Overflow.ResizeFreely || mOverflow == Overflow.ResizeHeight) { NGUIText.rectHeight = 1000000; } if (mPrintedSize > 0) { #if DYNAMIC_FONT bool adjustSize = keepCrisp; #endif for (int ps = mPrintedSize; ps > 0; --ps) { #if DYNAMIC_FONT // Adjust either the size, or the scale if (adjustSize) { mPrintedSize = ps; NGUIText.fontSize = mPrintedSize; } else #endif { mScale = (float)ps / mPrintedSize; NGUIText.fontScale = isDynamic ? mScale : ((float)mFontSize / mFont.defaultSize) * mScale * bitmapFont.pixelSize; } NGUIText.Update(false); // Wrap the text bool fits = NGUIText.WrapText(mText, out mProcessedText, true); if (mOverflow == Overflow.ShrinkContent && !fits) { if (--ps > 1) { continue; } else { break; } } else if (mOverflow == Overflow.ResizeFreely) { mCalculatedSize = NGUIText.CalculatePrintedSize(mProcessedText); mWidth = Mathf.Max(minWidth, Mathf.RoundToInt(mCalculatedSize.x)); mHeight = Mathf.Max(minHeight, Mathf.RoundToInt(mCalculatedSize.y)); if ((mWidth & 1) == 1) { ++mWidth; } if ((mHeight & 1) == 1) { ++mHeight; } } else if (mOverflow == Overflow.ResizeHeight) { mCalculatedSize = NGUIText.CalculatePrintedSize(mProcessedText); mHeight = Mathf.Max(minHeight, Mathf.RoundToInt(mCalculatedSize.y)); if ((mHeight & 1) == 1) { ++mHeight; } } else { mCalculatedSize = NGUIText.CalculatePrintedSize(mProcessedText); } // Upgrade to the new system if (legacyMode) { width = Mathf.RoundToInt(mCalculatedSize.x); height = Mathf.RoundToInt(mCalculatedSize.y); cachedTransform.localScale = Vector3.one; } break; } } else { cachedTransform.localScale = Vector3.one; mProcessedText = ""; mScale = 1f; } }
public bool Wrap(string text, out string final, int height) { UpdateNGUIText(); return(NGUIText.WrapText(text, out final)); }
private void CreateItemLabel(CharInfoNode node) { var obj = ComplexObjectPool.NewObjectSync("UI/ChatMain/ChatLableNode.prefab"); if (obj == null) { return; } var objTransform = obj.transform; objTransform.SetParentEX(Content.transform); obj.gameObject.collider.enabled = true; obj.SetActive(true); var label = obj.GetComponent <UILabel>(); ColliderList.Add(obj.gameObject); var sbstr = ""; var text = ""; label.fontSize = FontSize; NGUIText.fontSize = label.fontSize; NGUIText.finalSize = label.fontSize; NGUIText.dynamicFont = label.trueTypeFont; NGUIText.regionWidth = MaxWidth - xPos; NGUIText.pixelDensity = 1.0f; NGUIText.maxLines = 10000; NGUIText.regionHeight = 10000; NGUIText.finalLineHeight = label.fontSize; NGUIText.fontScale = 1.0f; var chatLogic = obj.GetComponent <ChatLableLogic>(); chatLogic.InfoNode = node; var tbTable = Table.GetItemBase(node.NodeData.Id); var value = tbTable.Name; var itemClor = GameUtils.GetTableColor(tbTable.Quality); //label.color = itemClor; NGUIText.WrapText(value, out sbstr, false, true); var index = sbstr.IndexOf("\n"); label.text = "[" + GameUtils.ColorToString(itemClor) + "]" + "[" + value + "]" + "[-]"; label.text = value; var y = yPos; if (index > -1) { xPos = (int)(FontSize * 0.5f); var height = 0; if (isFace) { height = (int)(FontSize * FaceScale); isFace = false; } else { height = FontSize; } height += LineOffset; y -= height; BackGround.height += height; Content.height += height; } else { if (isFace) { y -= FontSize; } } label.gameObject.transform.localPosition = new Vector3(xPos, y, 0); objTransform.localScale = Vector3.one; AddXPos(label.width); }
private void CreateTextLabel(string value) { var objres = ResourceManager.PrepareResourceSync <GameObject>("UI/ChatMain/ChatLableNode.prefab"); var obj = Instantiate(objres) as GameObject; if (obj == null) { return; } var objTransform = obj.transform; //objTransform.parent = Content.transform; objTransform.SetParentEX(Content.transform); obj.gameObject.collider.enabled = false; var label = obj.GetComponent <UILabel>(); var sbstr = ""; var text = ""; label.fontSize = FontSize; NGUIText.fontSize = label.fontSize; NGUIText.finalSize = label.fontSize; NGUIText.dynamicFont = label.trueTypeFont; if (xPos > MaxWidth) { WrapLine(); } NGUIText.regionWidth = MaxWidth - xPos; NGUIText.maxLines = 10000; NGUIText.pixelDensity = 1.0f; NGUIText.regionHeight = 10000; NGUIText.finalLineHeight = label.fontSize; NGUIText.fontScale = 1.0f; NGUIText.WrapText(value, out sbstr, false, true); var index = sbstr.IndexOf("\n"); if (index > -1) { text = sbstr.Substring(0, index); } else { text = sbstr; } label.text = text; var y = yPos; if (isFace) { y -= (int)(FontSize * (FaceScale - 1.0f) * 0.5f); } objTransform.localPosition = new Vector3(xPos, y, 0); objTransform.localScale = Vector3.one; AddXPos(label.width); sbstr = sbstr.Remove(0, text.Length); WidgetList.Add(label); if (sbstr.Length > 0) { //换行 WrapLine(); sbstr = sbstr.Replace("\n", ""); CreateTextLabel(sbstr); } }
private void ParseWrapHref(string value, RichContent content) { mLabel.gameObject.SetActive(true); value = value.Replace("\n", ""); NGUIText.fontSize = mLabel.fontSize; NGUIText.finalSize = mLabel.fontSize; NGUIText.dynamicFont = mLabel.trueTypeFont; NGUIText.rectWidth = (int)(maxWidth - mPositionX); NGUIText.maxLines = 10000; NGUIText.rectHeight = 10000; string sbstr = ""; NGUIText.WrapText(value, out sbstr); if (string.IsNullOrEmpty(sbstr)) { SetCurrWidth(mPositionX); mPositionX = mLabeltemp_x; mPositionY = mPositionY - cellHeight - m_dy - cellHeight + NGUIText.fontSize; m_dy = 0; //iswrap = true; ParseWrapHref(value, content); return; } GameObject labelgo = NGUITools.AddChild(mWidget.gameObject, mLabel.gameObject); labelgo.SetActive(true); UILabel label = labelgo.GetComponent <UILabel>(); labelgo.transform.localPosition = new Vector3(mPositionX, mPositionY, 0); UIDragScrollView dragScrollview = UtilTools.SafeAddComponent <UIDragScrollView>(labelgo); UIButtonColor btnColor = UtilTools.SafeAddComponent <UIButtonColor>(labelgo); btnColor.duration = 0.1f; btnColor.defaultColor = UtilTools.GetColorByLinkType(content); UILinkText linkText = UtilTools.SafeAddComponent <UILinkText>(labelgo); linkText.args = content.args; linkText.linktype = content.linktype; if (content.linktype == LinkType.AUDIO) { label.color = textColor; } else { label.color = UtilTools.GetColorByLinkType(content); } int index = sbstr.IndexOf("\n"); string str = ""; if (index > -1) { str = sbstr.Substring(0, index); label.text = str; BoxCollider boxcollider = UtilTools.SafeAddComponent <BoxCollider>(labelgo); boxcollider.size = new Vector3(label.width, label.height, 0); boxcollider.center = new Vector3(label.width * 0.5f, -label.height * 0.5f, 0); SetCurrWidth(mPositionX + label.width); mPositionX = mLabeltemp_x; mPositionY = mPositionY - cellHeight - m_dy - cellHeight + NGUIText.fontSize; m_dy = 0; //iswrap = true; sbstr = sbstr.Remove(0, str.Length); ParseWrapHref(sbstr, content); } else { str = sbstr; label.text = str; BoxCollider boxcollider = UtilTools.SafeAddComponent <BoxCollider>(labelgo); boxcollider.size = new Vector3(label.width, label.height, 0); boxcollider.center = new Vector3(label.width * 0.5f, -label.height * 0.5f, 0); int lastLabelwidth = label.width; mPositionX += lastLabelwidth; SetCurrWidth(mPositionX); } }
public string WrapText(string text, float maxWidth, bool multiline, bool encoding, int fontSize, FontStyle fontStyle, int SpaceingX, Font trueFont = null) { if (trueFont == null) { trueFont = TrueTypeFont; } string result; trueFont.RequestCharactersInTexture(text, fontSize, fontStyle); if (string.IsNullOrEmpty(text)) { NGUIText.WrapText(text, trueFont, fontSize, fontStyle, (int)maxWidth, 460, 3, encoding, out result); return(result); } // Width of the line in pixels int lineWidth = Mathf.RoundToInt(maxWidth * fontSize); if (lineWidth < 1) { return(text); } StringBuilder sb = new StringBuilder(); int textLength = text.Length; int remainingWidth = lineWidth; int start = 0; int offset = 0; bool lineIsEmpty = true; CharacterInfo tempCharInfo; // Run through all characters for (; offset < textLength; ++offset) { char ch = text[offset]; // New line character -- start a new line if (ch == '\n') { if (!multiline) { break; } remainingWidth = lineWidth; // Add the previous word to the final string if (start < offset) { sb.Append(text.Substring(start, offset - start + 1)); } else { sb.Append(ch); } lineIsEmpty = true; start = offset + 1; continue; } // When encoded symbols such as [RrGgBb] or [-] are encountered, skip past them if (encoding && ch == '[') { if (offset + 2 < textLength) { if (text[offset + 1] == '-' && text[offset + 2] == ']') { offset += 2; continue; } else if (offset + 7 < textLength && text[offset + 7] == ']') { offset += 7; continue; } } } if (encoding && ch == '\\') { if (offset + 1 < textLength) { if (text[offset + 1] == '<') { // sb.Append( '\\'); // sb.Append('<'); ch = '['; offset += 1; } else if (text[offset + 1] == '>') { // sb.Append('\\'); // sb.Append('>'); ch = ']'; offset += 1; } } } if (!trueFont.GetCharacterInfo(ch, out tempCharInfo, fontSize, fontStyle)) { continue; } int charSize = SpaceingX + (int)tempCharInfo.width; remainingWidth -= charSize; // Doesn't fit? if (remainingWidth < 0) { if (lineIsEmpty || !multiline) { // This is the first word on the line -- add it up to the character that fits sb.Append(text.Substring(start, Mathf.Max(0, offset - start))); if (!multiline) { start = offset; break; } EndLine(ref sb); // Start a brand-new line lineIsEmpty = true; if (ch == ' ') { start = offset + 1; remainingWidth = lineWidth; } else { start = offset; remainingWidth = lineWidth - charSize; } } else { // Skip all spaces before the word while (start < textLength && text[start] == ' ') { ++start; } // Revert the position to the beginning of the word and reset the line lineIsEmpty = true; remainingWidth = lineWidth; offset = start - 1; if (!multiline) { break; } EndLine(ref sb); continue; } } } if (start < offset) { sb.Append(text.Substring(start, offset - start)); } return(sb.ToString()); }
private void ParseWrapText(string value, RichContent richcontent) { mLabel.gameObject.SetActive(true); value = value.Replace("\n", ""); NGUIText.fontSize = mLabel.fontSize; NGUIText.finalSize = mLabel.fontSize; NGUIText.dynamicFont = mLabel.trueTypeFont; NGUIText.rectWidth = (int)(maxWidth - mPositionX); NGUIText.maxLines = 10000; NGUIText.rectHeight = 10000; string sbstr = ""; NGUIText.WrapText(value, out sbstr); if (string.IsNullOrEmpty(sbstr)) { SetCurrWidth(mPositionX); mPositionX = mLabeltemp_x; mPositionY = mPositionY - cellHeight - m_dy - cellHeight + NGUIText.fontSize; m_dy = 0; //iswrap = true; ParseWrapText(value, richcontent); return; } GameObject labelgo = NGUITools.AddChild(mWidget.gameObject, mLabel.gameObject); labelgo.SetActive(true); UILabel label = labelgo.GetComponent <UILabel>(); labelgo.transform.localPosition = new Vector3(mPositionX, mPositionY, 0); label.color = textColor; int index = sbstr.IndexOf("\n"); string str = ""; if (index > -1) { str = sbstr.Substring(0, index); if (!string.IsNullOrEmpty(richcontent.color)) { label.text = richcontent.color + str + "[-]"; } else { label.text = str; } //iswrap = true; mPositionY = mPositionY - cellHeight - m_dy - cellHeight + NGUIText.fontSize; SetCurrWidth(mPositionX + label.width); mPositionX = mLabeltemp_x; m_dy = 0; sbstr = sbstr.Remove(0, str.Length); ParseWrapText(sbstr, richcontent); } else { str = sbstr; if (!string.IsNullOrEmpty(richcontent.color)) { label.text = richcontent.color + str + "[-]"; } else { label.text = str; } int lastLabelwidth = label.width; mPositionX += lastLabelwidth; SetCurrWidth(mPositionX); } }
private void CreateTextLabel(string value) { UILabel label; List <UILabel> labelCaches = new List <UILabel> (); if (GamePlayer.Instance != null && GamePlayer.Instance.InstName.Equals(chatName)) { labelCaches = RlabelCaches; } else { labelCaches = LlabelCaches; } if (labelCaches.Count > 0) { label = labelCaches[0]; labelCaches.Remove(label); label.gameObject.SetActive(true); } else { GameObject go = null; // GameObject go = GameObject.Instantiate(LLabel) as GameObject; // go.SetActive(true); if (GamePlayer.Instance != null && GamePlayer.Instance.InstName.Equals(chatName)) { go = GameObject.Instantiate(LLabel) as GameObject; go.SetActive(true); go.transform.parent = _RChatBackground.transform; } else { go = GameObject.Instantiate(RLabel) as GameObject; go.SetActive(true); go.transform.parent = _LChatBackground.transform; } label = go.GetComponent <UILabel>(); go.transform.localScale = Vector3.one; } string sbstr = ""; string text = ""; NGUIText.fontSize = 27; NGUIText.finalSize = 27; NGUIText.dynamicFont = label.trueTypeFont; NGUIText.rectWidth = MaxLineWidth - positionX; NGUIText.maxLines = 10000; NGUIText.rectHeight = 10000; NGUIText.WrapText(value, out sbstr); //aaa (value, out sbstr); int index = sbstr.IndexOf("\n"); if (index > -1) { text = sbstr.Substring(0, index); } else { text = sbstr; } if (!string.IsNullOrEmpty(infoColor)) { label.text = infoColor + text + "[-]"; } else { label.text = text; } label.gameObject.transform.localPosition = new Vector3(positionX, positionY, 0); positionX += (label.width); if (GamePlayer.Instance != null && GamePlayer.Instance.InstName.Equals(chatName)) { RlabelCur.Add(label); } else { LlabelCur.Add(label); } sbstr = sbstr.Remove(0, text.Length); if (labelNameWidth == 0) { labelNameWidth = label.width; } if (label.text.Contains("[url=") || label.text.StartsWith("[url=")) { if (label.GetComponent <BoxCollider>() == null) { label.gameObject.AddComponent <BoxCollider>(); NGUITools.UpdateWidgetCollider(label.gameObject); } } if (GamePlayer.Instance != null && GamePlayer.Instance.InstName.Equals(chatName)) { if (rLine == 1) { _RChatBackground.width += label.width; } } else { if (lLine == 1) { if (label.text != " ") { _LChatBackground.width += label.width; } } } if (sbstr.Length > 0) { positionX = labelNameWidth; positionY -= (cellHeight + 4); if (GamePlayer.Instance != null && GamePlayer.Instance.InstName.Equals(chatName)) { rLine++; //_RChatBackground.height += (cellHeight+10); } else { lLine++; //_LChatBackground.height += (cellHeight+10); } sbstr = sbstr.Replace("\n", ""); CreateTextLabel(sbstr); } }
private void CreateTextLabel(NoticeData noticeNotice) { var value = noticeNotice.Content; var obj = ComplexObjectPool.NewObjectSync("UI/RechargeActivity/RechargeActivityText.prefab"); if (obj == null) { return; } _mObj.Add(obj); _mVarObjList.Add(new GameObjectType(obj, noticeNotice.Type)); var objTransform = obj.transform; objTransform.SetParentEX(BackGround.transform); obj.SetActive(true); var label = obj.GetComponent <UILabel>(); var sbstr = ""; var text = ""; label.fontSize = FontSize; NGUIText.fontSize = label.fontSize; NGUIText.finalSize = label.fontSize; if (mPositionX > MaxLineWidth) { ChangeLine(); } NGUIText.dynamicFont = label.trueTypeFont; NGUIText.regionWidth = MaxLineWidth - mPositionX; NGUIText.maxLines = 10000; NGUIText.pixelDensity = 1.0f; NGUIText.regionHeight = 10000; NGUIText.finalLineHeight = label.fontSize; NGUIText.fontScale = 1.0f; NGUIText.WrapText(value, out sbstr, false, true); var index = sbstr.IndexOf("\n"); if (index > -1) { text = sbstr.Substring(0, index); } else { text = sbstr; } objTransform.localScale = Vector3.one; objTransform.localPosition = new Vector3(mPositionX, mPositionY, 0); //Logger.Info("TextLabel:{0},{1},{2}", objTransform.localPosition.x, objTransform.localPosition.y,text); label.text = text; //positionX += label.width; AddPositionX(label.width); sbstr = sbstr.Remove(0, text.Length); if (sbstr.Length > 0) { ChangeLine(); index = sbstr.IndexOf("\n"); sbstr = sbstr.Substring(index + "\n".Length, sbstr.Length - "\n".Length); var notice = new NoticeData(eNoticeType.Text, -1, sbstr); CreateTextLabel(notice); } }
private void CreatePostionLabel(CharInfoNode node) { //var objres = ResourceManager.PrepareResourceSync<GameObject>("UI/ChatMain/ChatLableNode.prefab"); //var obj = Instantiate(objres) as GameObject; var obj = ComplexObjectPool.NewObjectSync("UI/ChatMain/ChatLableNode.prefab"); if (obj == null) { return; } var objTransform = obj.transform; //objTransform.parent = BackGround.transform; objTransform.SetParentEX(BackGround.transform); obj.gameObject.collider.enabled = true; obj.SetActive(true); var chatLogic = obj.GetComponent <ChatLableLogic>(); chatLogic.InfoNode = node; var label = obj.GetComponent <UILabel>(); mColliderObjects.Add(obj.gameObject); var sbstr = ""; var text = ""; //SetLableColor(label); label.fontSize = FontSize; NGUIText.fontSize = label.fontSize; NGUIText.finalSize = label.fontSize; NGUIText.dynamicFont = label.trueTypeFont; NGUIText.regionWidth = MaxLineWidth - mPositionX; NGUIText.pixelDensity = 1.0f; NGUIText.maxLines = 10000; NGUIText.regionHeight = 10000; NGUIText.finalLineHeight = label.fontSize; NGUIText.fontScale = 1.0f; var sceneId = node.NodeData.ExData[0]; var x = node.NodeData.ExData[1]; var y = node.NodeData.ExData[2]; var tbScene = Table.GetScene(sceneId); var strDic = GameUtils.GetDictionaryText(242011); var value = String.Format(strDic, tbScene.Name, x / 100, y / 100); NGUIText.WrapText(value, out sbstr, false, true); label.text = value; var index = sbstr.IndexOf("\n"); if (index > -1) { mPositionX = (int)(FontSize * 0.5f); var height = mLineOffset; if (mLineFace) { height = (int)(FontSize * FaceScale); mLineFace = false; } else { height = FontSize; } mPositionY -= height; BackGround.height += height; } label.gameObject.transform.localPosition = new Vector3(mPositionX, mPositionY, 0); objTransform.localScale = Vector3.one; AddPositionX(label.width); }
/// <summary> /// Process the raw text, called when something changes. /// </summary> void ProcessText(bool legacyMode) { if (!isValid) { return; } mChanged = true; hasChanged = false; int fs = fontSize; float invFS = 1f / fs; float ps = pixelSize; float invSize = 1f / ps; float lw = legacyMode ? (mMaxLineWidth != 0 ? mMaxLineWidth * invSize : 1000000) : width * invSize; float lh = legacyMode ? (mMaxLineHeight != 0 ? mMaxLineHeight * invSize : 1000000) : height * invSize; mScale = 1f; mPrintedSize = Mathf.Abs(legacyMode ? Mathf.RoundToInt(cachedTransform.localScale.x) : fs); UpdateNGUIText(fs, mWidth, mHeight); if (mPrintedSize > 0) { for (;;) { mScale = mPrintedSize * invFS; bool fits = true; NGUIText.lineWidth = (mOverflow == Overflow.ResizeFreely) ? 1000000 : Mathf.RoundToInt(lw / mScale); if (mOverflow == Overflow.ResizeFreely || mOverflow == Overflow.ResizeHeight) { NGUIText.lineHeight = 1000000; } else { NGUIText.lineHeight = Mathf.RoundToInt(lh / mScale); } NGUIText.Update(false); if (lw > 0f || lh > 0f) { fits = NGUIText.WrapText(mText, out mProcessedText); } else { mProcessedText = mText; } // Remember the final printed size if (!string.IsNullOrEmpty(mProcessedText)) { mCalculatedSize = NGUIText.CalculatePrintedSize(mProcessedText); } else { mCalculatedSize = Vector2.zero; } if (mOverflow == Overflow.ResizeFreely) { mWidth = Mathf.RoundToInt(mCalculatedSize.x * ps); mHeight = Mathf.RoundToInt(mCalculatedSize.y * ps); if ((mWidth & 1) == 1) { ++mWidth; } if ((mHeight & 1) == 1) { ++mHeight; } } else if (mOverflow == Overflow.ResizeHeight) { mHeight = Mathf.RoundToInt(mCalculatedSize.y * ps); } else if (mOverflow == Overflow.ShrinkContent && !fits) { if (--mPrintedSize > 1) { continue; } } // Upgrade to the new system if (legacyMode) { width = Mathf.RoundToInt(mCalculatedSize.x * ps); height = Mathf.RoundToInt(mCalculatedSize.y * ps); cachedTransform.localScale = Vector3.one; } break; } } else { cachedTransform.localScale = Vector3.one; mProcessedText = ""; mScale = 1f; } }
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.get_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.set_localScale(Vector3.get_one()); } break; } if (--i <= 1) { break; } } } else { base.cachedTransform.set_localScale(Vector3.get_one()); this.mProcessedText = string.Empty; this.mScale = 1f; } if (full) { NGUIText.bitmapFont = null; NGUIText.dynamicFont = null; } }
/// <summary> /// Text wrapping functionality. The 'width' and 'height' should be in pixels. /// Returns 'true' if the specified text was able to fit into the provided dimensions, 'false' otherwise. /// </summary> public bool WrapText(string text, int size, out string finalText, int width, int height, int maxLines, bool encoding, SymbolStyle symbolStyle) { if (mReplacement != null) { return(mReplacement.WrapText(text, size, out finalText, width, height, maxLines, encoding, symbolStyle)); } #if DYNAMIC_FONT if (isDynamic) { return(NGUIText.WrapText(text, mDynamicFont, size, mDynamicFontStyle, width, height, maxLines, encoding, out finalText)); } #endif if (width < 1 || height < 1) { finalText = ""; return(false); } if (maxLines > 0) { height = Mathf.Min(height, size * maxLines); } int maxLineCount = (maxLines > 0) ? maxLines : 1000000; maxLineCount = Mathf.Min(maxLineCount, height / size); if (maxLineCount == 0) { finalText = ""; return(false); } StringBuilder sb = new StringBuilder(); int textLength = text.Length; int remainingWidth = width; int previousChar = 0; int start = 0; int offset = 0; int lineCount = 1; bool lineIsEmpty = true; bool useSymbols = encoding && symbolStyle != SymbolStyle.None && hasSymbols; // Run through all characters for (; offset < textLength; ++offset) { char ch = text[offset]; // New line character -- start a new line if (ch == '\n') { if (lineCount == maxLineCount) { break; } remainingWidth = width; // Add the previous word to the final string if (start < offset) { sb.Append(text.Substring(start, offset - start + 1)); } else { sb.Append(ch); } lineIsEmpty = true; ++lineCount; start = offset + 1; previousChar = 0; continue; } // If this marks the end of a word, add it to the final string. if (ch == ' ' && previousChar != ' ' && start < offset) { sb.Append(text.Substring(start, offset - start + 1)); lineIsEmpty = false; start = offset + 1; previousChar = ch; } // When encoded symbols such as [RrGgBb] or [-] are encountered, skip past them if (NGUIText.ParseSymbol(text, ref offset)) { --offset; continue; } // See if there is a symbol matching this text BMSymbol symbol = useSymbols ? MatchSymbol(text, offset, textLength) : null; // Calculate how wide this symbol or character is going to be int glyphWidth = mSpacingX; if (symbol != null) { glyphWidth += symbol.advance; } else { // Find the glyph for this character BMGlyph glyph = (symbol == null) ? mFont.GetGlyph(ch) : null; if (glyph != null) { glyphWidth += (previousChar != 0) ? glyph.advance + glyph.GetKerning(previousChar) : glyph.advance; } else { continue; } } // Remaining width after this glyph gets printed remainingWidth -= glyphWidth; // Doesn't fit? if (remainingWidth < 0) { // Can't start a new line if (lineIsEmpty || lineCount == maxLineCount) { // This is the first word on the line -- add it up to the character that fits sb.Append(text.Substring(start, Mathf.Max(0, offset - start))); if (lineCount++ == maxLineCount) { start = offset; break; } NGUIText.EndLine(ref sb); // Start a brand-new line lineIsEmpty = true; if (ch == ' ') { start = offset + 1; remainingWidth = width; } else { start = offset; remainingWidth = width - glyphWidth; } previousChar = 0; } else { // Skip all spaces before the word while (start < textLength && text[start] == ' ') { ++start; } // Revert the position to the beginning of the word and reset the line lineIsEmpty = true; remainingWidth = width; offset = start - 1; previousChar = 0; if (lineCount++ == maxLineCount) { break; } NGUIText.EndLine(ref sb); continue; } } else { previousChar = ch; } // Advance the offset past the symbol if (symbol != null) { offset += symbol.length - 1; previousChar = 0; } } if (start < offset) { sb.Append(text.Substring(start, offset - start)); } finalText = sb.ToString(); return((offset == textLength) || (lineCount <= Mathf.Min(maxLines, maxLineCount))); }
/// <summary> /// Convenience function -- wrap the current text given the label's settings and the given height. /// </summary> public bool Wrap(string text, out string final, int height) { UpdateNGUIText(defaultFontSize, mWidth, height); return(NGUIText.WrapText(text, out final)); }
private void _Parse() { for (int i = 0; i < this.m_Symbols.Count; i++) { this.m_Symbols[i].Recycle(); } this.m_Symbols.Clear(); this.m_Label.text = string.Empty; this.m_Label.ProcessText(); this.m_Label.UpdateDefaultPrintedSize(); if (this._UniSpaceWidth < 0f) { this._UniSpaceWidth = NGUIText.CalculatePrintedSize(new string(XUILabelSymbol._UniSpace, 1), 1000).x; this._SpaceWidth = NGUIText.CalculatePrintedSize(" ", 1000).x; if (Mathf.Abs(this._SpaceWidth) < 0.01f) { XSingleton <XDebug> .singleton.AddErrorLog("_SpaceWidth = ", this._SpaceWidth.ToString(), " gameobject = ", base.gameObject.ToString(), null, null); } } this._CheckAttachments(); string text = string.Empty; int num = 0; int j = 0; int k = 0; int num2 = this.m_Label.width; if (this.m_Label.overflowMethod == UILabel.Overflow.ResizeFreely) { num2 = 10000; } string text2 = null; XUILabelSymbol.SymbolData symbolData = null; int l = 0; while (l < this.m_StringData.Count) { if (num != 0 && num >= text.Length) { break; } XUILabelSymbol.StringData stringData = this.m_StringData[l]; if (XUILabelSymbol.SymbolData.IsImage(stringData.type)) { XUILabelSymbol.ImageSymbolData data = XDataPool <XUILabelSymbol.ImageSymbolData> .GetData(); text2 = data.SetSprite(this, stringData.str, stringData.startIndex, stringData.length, ref j); if (text2 != null) { symbolData = data; goto IL_224; } data.Recycle(); } else if (XUILabelSymbol.SymbolData.IsAnimation(stringData.type)) { XUILabelSymbol.AnimationSymbolData data2 = XDataPool <XUILabelSymbol.AnimationSymbolData> .GetData(); text2 = data2.SetSprite(this, stringData.str, stringData.startIndex, stringData.length, ref k); if (text2 != null) { symbolData = data2; goto IL_224; } data2.Recycle(); } else { if (XUILabelSymbol.SymbolData.IsHyperLink(stringData.type)) { XUILabelSymbol.HyperLinkSymbolData.CreateHyperLinkSymbolData(stringData, out symbolData, out text2); goto IL_224; } goto IL_224; } IL_3B7: l++; continue; IL_224: if (text2 != null) { XUILabelSymbol.s_TempSB.Length = 0; XUILabelSymbol.s_TempSB.Append(text, num, text.Length - num); XUILabelSymbol.s_TempSB.Append(text2); int num3 = Mathf.CeilToInt(NGUIText.CalculatePrintedSize(XUILabelSymbol.s_TempSB.ToString(), num2 + 1000).x); if (num3 > num2) { symbolData.startIndex = text.Length + 1; num = text.Length + 1; XUILabelSymbol.s_TempSB.Length = 0; XUILabelSymbol.s_TempSB.Append(text); XUILabelSymbol.s_TempSB.Append('\n'); XUILabelSymbol.s_TempSB.Append(text2); text = XUILabelSymbol.s_TempSB.ToString(); } else { symbolData.startIndex = text.Length; XUILabelSymbol.s_TempSB.Length = 0; XUILabelSymbol.s_TempSB.Append(text); XUILabelSymbol.s_TempSB.Append(text2); text = XUILabelSymbol.s_TempSB.ToString(); } symbolData.endIndex = symbolData.startIndex + text2.Length; this.m_Symbols.Add(symbolData); NGUIText.WrapText(text, out text, false); text2 = null; goto IL_3B7; } XUILabelSymbol.s_TempSB.Length = 0; XUILabelSymbol.s_TempSB.Append(text); XUILabelSymbol.s_TempSB.Append(stringData.str, stringData.startIndex, stringData.length); NGUIText.WrapText(XUILabelSymbol.s_TempSB.ToString(), out text, false); num = text.LastIndexOf('\n'); if (num == -1) { num = 0; goto IL_3B7; } num++; goto IL_3B7; } while (j < this.m_SpriteList.Count) { this.m_SpriteList[j].gameObject.SetActive(false); j++; } while (k < this.m_AnimationList.Count) { this.m_AnimationList[k].gameObject.SetActive(false); k++; } this.m_Label.text = text; }
private void ProcessText(bool legacyMode, bool full) { if (!isValid) { return; } mChanged = true; shouldBeProcessed = false; NGUIText.rectWidth = ((!legacyMode) ? base.width : ((mMaxLineWidth != 0) ? mMaxLineWidth : 1000000)); NGUIText.rectHeight = ((!legacyMode) ? base.height : ((mMaxLineHeight != 0) ? mMaxLineHeight : 1000000)); mPrintedSize = Mathf.Abs(legacyMode ? Mathf.RoundToInt(base.cachedTransform.localScale.x) : defaultFontSize); mScale = 1f; if (NGUIText.rectWidth < 1 || NGUIText.rectHeight < 0) { mProcessedText = ""; return; } bool flag = trueTypeFont != null; if (flag && keepCrisp) { UIRoot uIRoot = base.root; if (uIRoot != null) { mDensity = ((uIRoot != null) ? uIRoot.pixelSizeAdjustment : 1f); } } else { mDensity = 1f; } if (full) { UpdateNGUIText(); } if (mOverflow == Overflow.ResizeFreely) { NGUIText.rectWidth = 1000000; } if (mOverflow == Overflow.ResizeFreely || mOverflow == Overflow.ResizeHeight) { NGUIText.rectHeight = 1000000; } if (mPrintedSize > 0) { bool flag2 = keepCrisp; int num = mPrintedSize; while (num > 0) { if (flag2) { mPrintedSize = num; NGUIText.fontSize = mPrintedSize; } else { mScale = (float)num / (float)mPrintedSize; NGUIText.fontScale = (flag ? mScale : ((float)mFontSize / (float)mFont.defaultSize * mScale)); } NGUIText.Update(request: false); bool flag3 = NGUIText.WrapText(mText, out mProcessedText, keepCharCount: true); if (mOverflow == Overflow.ShrinkContent && !flag3) { if (--num <= 1) { break; } num--; continue; } if (mOverflow == Overflow.ResizeFreely) { mCalculatedSize = NGUIText.CalculatePrintedSize(mProcessedText); mWidth = Mathf.Max(minWidth, Mathf.RoundToInt(mCalculatedSize.x)); mHeight = Mathf.Max(minHeight, Mathf.RoundToInt(mCalculatedSize.y)); if ((mWidth & 1) == 1) { mWidth++; } if ((mHeight & 1) == 1) { mHeight++; } } else if (mOverflow == Overflow.ResizeHeight) { mCalculatedSize = NGUIText.CalculatePrintedSize(mProcessedText); mHeight = Mathf.Max(minHeight, Mathf.RoundToInt(mCalculatedSize.y)); if ((mHeight & 1) == 1) { mHeight++; } } else { mCalculatedSize = NGUIText.CalculatePrintedSize(mProcessedText); } if (legacyMode) { base.width = Mathf.RoundToInt(mCalculatedSize.x); base.height = Mathf.RoundToInt(mCalculatedSize.y); base.cachedTransform.localScale = Vector3.one; } break; } } else { base.cachedTransform.localScale = Vector3.one; mProcessedText = ""; mScale = 1f; } }
public static GameObject Str2Obj(GameObject parent, string in_str, UIFont mFont, float width, string[] parms = null, int chatID = 0) { in_str = Str2Str(in_str, parms); GameObject content = new GameObject("content"); content.transform.parent = parent.transform; content.transform.localPosition = new Vector3(0, 0, 0); content.transform.localScale = new Vector3(1, 1, 1); content.layer = LayerMask.NameToLayer("NGUI"); string color = null; string has = in_str; float DrawWidth = 0; float now_y = 0; List <GameObject> thisLine = new List <GameObject>(); while (true) { if (has == null) { break; } if (has.Length == 0) { break; } int index_bef = has.IndexOf("["); int index_aft = has.IndexOf("]"); if (index_bef == -1) { string strs = string.Empty; NGUIText.WrapText(has, out strs); if (strs.Length <= 0) { if (DrawWidth == 0) { Debug.Log("can not set string"); return(null); } now_y = FormatLine(thisLine, now_y); DrawWidth = 0; thisLine = new List <GameObject>(); continue; } UILabel lb = CreateLabel(content, strs, mFont, color); lb.transform.localPosition = new Vector3(DrawWidth, 0, 0); thisLine.Add(lb.gameObject); now_y = FormatLine(thisLine, now_y); DrawWidth = 0; thisLine = new List <GameObject>(); if (has.Length > strs.Length) { has = has.Substring(strs.Length, has.Length - strs.Length); if (has[0] == '\n') { if (has.Length > 2) { has = has.Substring(1, has.Length - 1); } else { has = null; } } } else { has = null; } } else { if (index_aft < index_bef) { Debug.Log("error str = " + in_str); return(null); } if (index_aft == -1) { Debug.Log("error str = " + in_str); return(null); } else { string befor_has = has.Substring(0, index_bef); while (true) { if (befor_has == null) { break; } if (befor_has.Length == 0) { break; } string befor_strs = string.Empty; NGUIText.WrapText(befor_has, out befor_strs); if (befor_strs.Length <= 0) { if (DrawWidth == 0) { Debug.Log("can not set string"); return(null); } now_y = FormatLine(thisLine, now_y); DrawWidth = 0; thisLine = new List <GameObject>(); continue; } UILabel befor_lb = CreateLabel(content, befor_strs, mFont, color); befor_lb.transform.localPosition = new Vector3(DrawWidth, 0, 0); thisLine.Add(befor_lb.gameObject); Bounds b = NGUIMath.CalculateRelativeWidgetBounds(befor_lb.gameObject.transform); DrawWidth += b.size.x * mFont.defaultSize; if (befor_has.Length > befor_strs.Length) { now_y = FormatLine(thisLine, now_y); DrawWidth = 0; thisLine = new List <GameObject>(); befor_has = befor_has.Substring(befor_strs.Length, befor_has.Length - befor_strs.Length); if (befor_has[0] == '\n') { if (befor_has.Length > 2) { befor_has = befor_has.Substring(1, befor_has.Length - 1); } else { befor_has = null; } } } else { befor_has = null; } } if (index_aft - index_bef > 1) { string trun_str = has.Substring(index_bef + 1, index_aft - index_bef - 1); string[] trun_parms = trun_str.Split(','); switch (trun_parms[0]) { case "color": color = trun_parms[1]; break; case "-": color = null; break; default: //GameObject other = CreateOther(content, trun_parms, mFont,chatID); //if (other != null) //{ // Bounds b = NGUIMath.CalculateRelativeWidgetBounds(other.transform); // if ((DrawWidth + b.size.x * other.transform.localScale.x) > width) // { // now_y = FormatLine(thisLine, now_y); // thisLine = new List<GameObject>(); // other.transform.localPosition = new Vector3(0, 0, 0); // DrawWidth = b.size.x * other.transform.localScale.x; // thisLine.Add(other); // } // else // { // other.transform.localPosition = new Vector3(DrawWidth, 0, 0); // DrawWidth += b.size.x * other.transform.localScale.x; // thisLine.Add(other); // } //} break; } } if (has.Length > index_aft + 1) { has = has.Substring(index_aft + 1, has.Length - (index_aft + 1)); } else { has = null; } } } } if (thisLine.Count > 0) { FormatLine(thisLine, now_y); } return(content); }