static public CalculatePrintedSize ( string text ) : Vector2 | ||
text | string | |
Résultat | Vector2 |
public static Vector2 CalcTextPrintSize(string text, Font ft, int fs, FontStyle style, bool b, int regionX, int regionY) { Font oldFt = NGUIText.dynamicFont; int oldFs = NGUIText.fontSize; FontStyle oldStyle = NGUIText.fontStyle; bool oldEncoding = NGUIText.encoding; int oldRegionX = NGUIText.regionWidth; int oldRegionY = NGUIText.regionHeight; NGUIText.dynamicFont = ft; NGUIText.fontSize = fs; NGUIText.fontStyle = style; NGUIText.encoding = b; NGUIText.rectWidth = regionX; NGUIText.rectHeight = regionY; NGUIText.regionWidth = regionX; NGUIText.regionHeight = regionY; NGUIText.Update(false); NGUIText.WrapText(text, out text, true); Vector2 ret = NGUIText.CalculatePrintedSize(text); NGUIText.dynamicFont = oldFt; NGUIText.fontSize = oldFs; NGUIText.fontStyle = oldStyle; NGUIText.encoding = oldEncoding; NGUIText.regionWidth = oldRegionX; NGUIText.regionHeight = oldRegionY; return(ret); }
public void SetBoard() { Vector2 vector = NGUIText.CalculatePrintedSize(this.m_Label.text, -1); vector.x += (float)this.BoardWidthOffset; if (this.BoardSprite != null) { if (this.MinBoardWidth != 0 && this.MaxBoardWidth != 0 && this.MaxBoardWidth >= this.MinBoardWidth) { if (vector.x <= (float)this.MinBoardWidth) { this.BoardSprite.spriteWidth = this.MinBoardWidth; } else if (vector.x > (float)this.MaxBoardWidth) { this.BoardSprite.spriteWidth = this.MaxBoardWidth; } else { this.BoardSprite.spriteWidth = (int)vector.x; } } else { this.BoardSprite.spriteWidth = (int)vector.x; } this.BoardSprite.spriteHeight = (int)vector.y + 20 + this.BoardHeightOffset; } }
private static int CalculatePrintedSize(IntPtr L) { int result; try { int num = LuaDLL.lua_gettop(L); if (num == 1 && TypeChecker.CheckTypes(L, 1, typeof(string))) { string text = ToLua.ToString(L, 1); Vector2 v = NGUIText.CalculatePrintedSize(text); ToLua.Push(L, v); result = 1; } else if (num == 2 && TypeChecker.CheckTypes(L, 1, typeof(string), typeof(int))) { string text2 = ToLua.ToString(L, 1); int maxW = (int)LuaDLL.lua_tonumber(L, 2); Vector2 v2 = NGUIText.CalculatePrintedSize(text2, maxW); ToLua.Push(L, v2); result = 1; } else { result = LuaDLL.luaL_throw(L, "invalid arguments to method: NGUIText.CalculatePrintedSize"); } } catch (Exception e) { result = LuaDLL.toluaL_exception(L, e, null); } return(result); }
/// <summary> /// Measuring text width and height /// </summary> /// <param name="text">text to measure</param> /// <returns>width and height of measured text</returns> public override HtSize Measure(string text) { this.content.text = text; Vector2 r; { if (m_font.isDynamic) { NGUIText.dynamicFont = m_font.dynamicFont; NGUIText.fontStyle = m_font.dynamicFontStyle; } else { NGUIText.bitmapFont = m_font; } NGUIText.fontSize = this.Size; //m_font.size; r = NGUIText.CalculatePrintedSize(text); NGUIText.fontSize = 16; NGUIText.bitmapFont = null; NGUIText.dynamicFont = null; } return(new HtSize((int)r.x, (int)r.y)); }
private string ReplaceFace(string text) { if (string.IsNullOrEmpty(text)) { return(string.Empty); } int num = 0; int num2 = 0; int length = text.Length; for (int i = 0; i < length; i++) { if (text[i] == '#' && i + 4 < length && text[i + 1] == 'e') { string s = text.Substring(i + 2, 3); int num3 = 0; Vector3 zero = Vector3.zero; if (int.TryParse(s, out num3)) { text = text.Remove(i, 5); text = text.Insert(i, this.space); length = text.Length; int num4 = Mathf.RoundToInt(NGUIText.CalculatePrintedSize(text.Substring(num2, i - num2), 330).x); if (num4 + 32 > 302) { float x = 0f; num++; num2 = i; zero.x = x; zero.y = (float)num; zero.z = (float)num3; } else { float x = (float)num4; zero.x = x; zero.y = (float)num; zero.z = (float)num3; } } if (num3 != 0) { this._eList.Add(zero); } } else if (i - num2 >= 0) { float num5 = (float)Mathf.RoundToInt(NGUIText.CalculatePrintedSize(text.Substring(num2, i - num2 + 1), 362).x); if (num5 > 330f) { num2 = i + 1; num++; } } } return(text); }
public void Resize() { var lbl = GetComponent <UILabel>(); //label.UpdateNGUIText() must be called before any NGUIText functions. lbl.UpdateNGUIText(); float width = NGUIText.CalculatePrintedSize(lbl.text).x;// *lbl.fontSize; lbl.width = (int)width; }
static int CalculatePrintedSize(IntPtr L) { LuaScriptMgr.CheckArgsCount(L, 1); string arg0 = LuaScriptMgr.GetLuaString(L, 1); Vector2 o = NGUIText.CalculatePrintedSize(arg0); LuaScriptMgr.Push(L, o); return(1); }
public void Resize() { var lbl = GetComponent <UILabel>(); lbl.UpdateNGUIText(); float width = NGUIText.CalculatePrintedSize(lbl.text).x;// *lbl.fontSize; lbl.width = (int)width; }
public float GetStringLen(string text) { float stringLen = 0f; if (!string.IsNullOrEmpty(text)) { label = gameObject.GetComponent <UILabel>(); label.UpdateNGUIText(); stringLen = NGUIText.CalculatePrintedSize(text).x; } return(stringLen); }
static public int CalculatePrintedSize_s(IntPtr l) { try { System.String a1; checkType(l, 1, out a1); var ret = NGUIText.CalculatePrintedSize(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
static int CalculatePrintedSize(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); string arg0 = ToLua.CheckString(L, 1); UnityEngine.Vector2 o = NGUIText.CalculatePrintedSize(arg0); ToLua.Push(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
private void UpdateEmptySlotLabelSize(UILabel emptySlotLabel) { emptySlotLabel.SetAnchor((Transform)null); emptySlotLabel.updateAnchors = UIRect.AnchorUpdate.OnStart; Int32 width = emptySlotLabel.width; Int32 height = emptySlotLabel.height; emptySlotLabel.width = (Int32)UIManager.UIContentSize.x; emptySlotLabel.height = (Int32)UIManager.UIContentSize.y; emptySlotLabel.ProcessText(); emptySlotLabel.UpdateNGUIText(); Int32 num = (Int32)NGUIText.CalculatePrintedSize(emptySlotLabel.text).x + 3; emptySlotLabel.width = (Int32)((width >= num) ? width : num); emptySlotLabel.height = height; }
private void UpdateNoticeRequest(string notice) { float screenHalfSize = 512f; float moveSpeed = 100f; labNotice.text = notice; Vector3 from = labNotice.transform.localPosition; from.x = screenHalfSize; Vector3 to = from; to.x = -NGUIText.CalculatePrintedSize(labNotice.text).x - screenHalfSize; noticeObj.SetActive(true); float moveTime = (from.x - to.x) / moveSpeed; ShowNoticeMoveEffect(labNotice, from, to, moveTime); vp_Timer.In(moveTime, FinishNoticeMove, 1, 0); }
public void ShowBubble(string msg) { this.bubbleTween.gameObject.SetActive(true); this.bubbleTween.Play(true); this.bubbleMsgLab.text = msg; this.bubbleMsgLab.UpdateNGUIText(); msg = this.ReplaceFace(msg); this.bubbleMsgLab.text = msg; int num = Mathf.RoundToInt(NGUIText.CalculatePrintedSize(msg, 330).x); if (num < 58) { num = 58; } this.bubbleMsgLab.width = Mathf.RoundToInt(NGUIText.CalculatePrintedSize(msg, 330).x); this.bubbleMsgLab.height = Mathf.RoundToInt(NGUIText.CalculatePrintedSize(msg, 330).y); this.bubbleBg.width = num + 68; this.bubbleBg.height = Mathf.RoundToInt(NGUIText.CalculatePrintedSize(msg, 330).y) + 64; this.DrawFace(); this.bubbleMsgLab.transform.localPosition = new Vector3(0f, 6.6f, 0f); base.Invoke("DelayHideBubble", 2f); }
//text format: purestring{2ItemName,100}purestring{1SpriteName,20}purestring //{1ItemName,100} represent: {(hyperType)(textWillShow),(ID)} public void SetText(string txt) { RecycleWidgets(); sourceTxt = txt; HyperStrs = new List <HyperString>(); mClickableDic = new Dictionary <GameObject, HyperString>(); DecodeText(txt); if (LenLimit > 0) { CalcuTextsLengthAndLine(); } else { for (int i = 0; i < HyperStrs.Count; i++) { Vector2 conLen = NGUIText.CalculatePrintedSize(HyperStrs[i].content, LblPrefab); conLen = new Vector2(conLen.x + ElementSpace, conLen.y); HyperStrs[i].length = conLen.x; } } DisplayText(); }
Vector2 GetHyperStrLength(HyperString hyperStr) { Vector2 conLen = Vector2.zero; if (hyperStr.type == HyperType.Sprite) { if (hyperStr.inputInfo != string.Empty) { conLen.x = int.Parse(hyperStr.inputInfo); } else { Vector3 sprSize = SprPrefab.Dimensions; conLen.x = sprSize.x; } hyperStr.length = conLen.x; } else if (hyperStr.type == HyperType.PureString || hyperStr.type == HyperType.Clickable) { conLen = NGUIText.CalculatePrintedSize(hyperStr.content, LblPrefab); conLen = new Vector2(conLen.x + ElementSpace, conLen.y); hyperStr.length = conLen.x; } else if (hyperStr.type == HyperType.Voice) { if (VoiPrefab == null) { Debug.Log(gameObject.name); } Vector3 sprSize = VoiPrefab.BackgroundSprite.Dimensions; conLen.x = sprSize.x; hyperStr.length = conLen.x; } return(conLen); }
public Vector2 CalculatePrintedSize(string text) { return(NGUIText.CalculatePrintedSize(text, -1)); }
/// <summary> /// Get the printed size of the specified string. The returned value is in pixels. /// </summary> public Vector2 CalculatePrintedSize(string text, int size, bool encoding, SymbolStyle symbolStyle) { if (mReplacement != null) { return(mReplacement.CalculatePrintedSize(text, size, encoding, symbolStyle)); } #if DYNAMIC_FONT if (isDynamic) { return(NGUIText.CalculatePrintedSize(text, mDynamicFont, size, mDynamicFontStyle, encoding)); } #endif Vector2 v = Vector2.zero; if (mFont != null && mFont.isValid && !string.IsNullOrEmpty(text)) { if (encoding) { text = NGUIText.StripSymbols(text); } int length = text.Length; int maxX = 0; int x = 0; int y = 0; int prev = 0; int fs = size; int lineHeight = (fs + mSpacingY); bool useSymbols = encoding && symbolStyle != SymbolStyle.None && hasSymbols; for (int i = 0; i < length; ++i) { char c = text[i]; // Start a new line if (c == '\n') { if (x > maxX) { maxX = x; } x = 0; y += lineHeight; prev = 0; continue; } // Skip invalid characters if (c < ' ') { prev = 0; continue; } // See if there is a symbol matching this text BMSymbol symbol = useSymbols ? MatchSymbol(text, i, length) : null; if (symbol == null) { // Get the glyph for this character BMGlyph glyph = mFont.GetGlyph(c); if (glyph != null) { x += mSpacingX + ((prev != 0) ? glyph.advance + glyph.GetKerning(prev) : glyph.advance); prev = c; } } else { // Symbol found -- use it x += mSpacingX + symbol.width; i += symbol.length - 1; prev = 0; } } // Convert from pixel coordinates to local coordinates v.x = ((x > maxX) ? x : maxX); v.y = (y + lineHeight); } return(v); }
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; } } } }
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; }
/// <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); NGUIText.current.size = fs; UpdateNGUIText(); if (mPrintedSize > 0) { for (;;) { mScale = mPrintedSize * invFS; bool fits = true; NGUIText.current.lineWidth = (mOverflow == Overflow.ResizeFreely) ? 1000000 : Mathf.RoundToInt(lw / mScale); NGUIText.current.lineHeight = (mOverflow == Overflow.ResizeFreely || mOverflow == Overflow.ResizeHeight) ? 1000000 : Mathf.RoundToInt(lh / mScale); if (lw > 0f || lh > 0f) { if (mFont != null) { fits = mFont.WrapText(mText, out mProcessedText); } #if DYNAMIC_FONT else { fits = NGUIText.WrapText(mTrueTypeFont, mText, out mProcessedText); } #endif } else { mProcessedText = mText; } // Remember the final printed size if (!string.IsNullOrEmpty(mProcessedText)) { if (mFont != null) { mCalculatedSize = mFont.CalculatePrintedSize(mProcessedText); } #if DYNAMIC_FONT else { mCalculatedSize = NGUIText.CalculatePrintedSize(mTrueTypeFont, mProcessedText); } #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; } }
public void Show(string text, float width = 0) { Transform child; for (int i = 0; i < transform.childCount; i++) { child = transform.GetChild(i); if (child.name == "Icon(Clone)") { Destroy(child.gameObject); } } if (label == null) { label = gameObject.GetComponent <UILabel>(); } if (spriteIcon == null) { spriteIcon = gameObject.transform.Find("Icon").gameObject.GetComponent <UISprite>(); } label.text = ""; label.UpdateNGUIText(); per_height = label.height; cur_height = per_height; cur_width = 0; if (e_list == null) { e_list = new List <IconData>(); } m_curIndex = 0; max_width = width; System.Text.StringBuilder _sb = LuaInterface.StringBuilderCache.Acquire(); float ch_width = 0.0f; int length = text.Length; int n = 0, m = 0; float space_width = NGUIText.CalculatePrintedSize(" ").x; int lengthIcon = 0; if (spriteIcon != null) { lengthIcon = (int)Math.Ceiling(spriteIcon.localSize.x / space_width); } for (int i = 0; i < length; i++) { if (m > i) { _sb.Append(text[i]); continue; } if (n > 0) { n--; continue; } if (text[i] == '[') { int index = i; bool is_symbol = NGUIText.ParseSymbol(text, ref index); if (is_symbol) { m = index; _sb.Append(text[i]); continue; } } if (text[i] == '\n' && i + 1 <= length) { cur_width = 0; cur_height += per_height; _sb.Append("\n"); continue; } if (text[i] == '[' && text.Substring(i, 5).Equals("[img]")) { if (cur_width + 2 * space_width > max_width) { cur_height += per_height; cur_width = 0; _sb.Append("\n"); } int indexEnd = text.IndexOf("[-]", i); string eName = text.Substring(i + 5, indexEnd - i - 5); IconData e = null; bool isExpression = false; if (eName != null || eName != "") { isExpression = true; e = GetEmoticonByIndex(m_curIndex); m_curIndex++; e.eName = eName; e.pos.x = cur_width + 2; e.pos.y = -1 * cur_height; cur_width += lengthIcon * space_width; for (int j = 0; j < lengthIcon; j++) { _sb.Append(" "); } } if (!isExpression) { _sb.Append(text[i]); } else { n = indexEnd - i + 2; } } else { ch_width = NGUIText.CalculatePrintedSize(text[i].ToString()).x; cur_width += ch_width; if (cur_width > max_width) { _sb.Append("\n"); cur_height += per_height; cur_width = ch_width; } _sb.Append(text[i]); } } label.text = LuaInterface.StringBuilderCache.GetStringAndRelease(_sb);//output_str; Show_emoticon(); }
/// <summary> /// Get the printed size of the specified string. The returned value is in pixels. /// </summary> public Vector2 CalculatePrintedSize(string text) { if (mReplacement != null) { return(mReplacement.CalculatePrintedSize(text)); } #if DYNAMIC_FONT if (isDynamic) { NGUIText.current.size = mDynamicFontSize; NGUIText.current.style = mDynamicFontStyle; return(NGUIText.CalculatePrintedSize(mDynamicFont, text)); } #endif Vector2 v = Vector2.zero; if (mFont != null && mFont.isValid && !string.IsNullOrEmpty(text)) { if (NGUIText.current.encoding) { text = NGUIText.StripSymbols(text); } int x = 0; int y = 0; int prev = 0; int maxX = 0; int length = text.Length; int lineHeight = NGUIText.current.size + NGUIText.current.spacingY; bool useSymbols = NGUIText.current.encoding && NGUIText.current.symbolStyle != NGUIText.SymbolStyle.None && hasSymbols; for (int i = 0; i < length; ++i) { char c = text[i]; // Start a new line if (c == '\n') { if (x > maxX) { maxX = x; } x = 0; y += lineHeight; prev = 0; continue; } // Skip invalid characters if (c < ' ') { prev = 0; continue; } // See if there is a symbol matching this text BMSymbol symbol = useSymbols ? MatchSymbol(text, i, length) : null; if (symbol == null) { // Get the glyph for this character BMGlyph glyph = mFont.GetGlyph(c); if (glyph != null) { x += NGUIText.current.spacingX + ((prev != 0) ? glyph.advance + glyph.GetKerning(prev) : glyph.advance); prev = c; } } else { // Symbol found -- use it x += NGUIText.current.spacingX + symbol.width; i += symbol.length - 1; prev = 0; } } // Padding is always between characters, so it's one less than the number of characters v.x = ((x > maxX) ? x : maxX); v.y = (y + NGUIText.current.size); } return(v); }
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.mFinalFontSize = 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.mFinalFontSize > 0) { bool keepCrisp = this.keepCrisp; for (int i = this.mFinalFontSize; i > 0; i--) { if (keepCrisp) { this.mFinalFontSize = i; NGUIText.fontSize = this.mFinalFontSize; } else { this.mScale = (float)i / (float)this.mFinalFontSize; 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, false); 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.CeilToInt(this.mCalculatedSize.x)); if (num != 1f) { this.mWidth = Mathf.CeilToInt((float)this.mWidth / num); } this.mHeight = Mathf.Max(this.minHeight, Mathf.CeilToInt(this.mCalculatedSize.y)); if (num2 != 1f) { this.mHeight = Mathf.CeilToInt((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.CeilToInt(this.mCalculatedSize.y)); if (num2 != 1f) { this.mHeight = Mathf.CeilToInt((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; } }
/// <summary> /// Process the raw text, called when something changes. /// </summary> void ProcessText(bool legacyMode) { if (!isValid) { return; } mChanged = true; hasChanged = false; float pxSize = pixelSize; int fontSize = this.fontSize; float invFontSize = 1f / fontSize; NGUIText.rectWidth = legacyMode ? (mMaxLineWidth != 0 ? mMaxLineWidth : 1000000) : width; NGUIText.rectHeight = legacyMode ? (mMaxLineHeight != 0 ? mMaxLineHeight : 1000000) : height; mScale = 1f; mPrintedSize = Mathf.Abs(legacyMode ? Mathf.RoundToInt(cachedTransform.localScale.x) : fontSize); if (NGUIText.rectWidth < 1 || NGUIText.rectHeight < 0) { mProcessedText = ""; return; } UpdateNGUIText(fontSize, mWidth, mHeight); if (mOverflow == Overflow.ResizeFreely) { NGUIText.rectWidth = 1000000; } if (mOverflow == Overflow.ResizeFreely || mOverflow == Overflow.ResizeHeight) { NGUIText.rectHeight = 1000000; } if (mPrintedSize > 0) { for (;;) { mScale = mPrintedSize * invFontSize; NGUIText.pixelSize = pxSize * mScale; NGUIText.Update(false); // Wrap the text bool fits = NGUIText.WrapText(mText, out mProcessedText); // 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); mHeight = Mathf.RoundToInt(mCalculatedSize.y); if ((mWidth & 1) == 1) { ++mWidth; } if ((mHeight & 1) == 1) { ++mHeight; } } else if (mOverflow == Overflow.ResizeHeight) { mHeight = Mathf.RoundToInt(mCalculatedSize.y); } else if (mOverflow == Overflow.ShrinkContent && !fits) { if (--mPrintedSize > 1) { continue; } } // 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; } }
//替换表情 private void ShowEmotion(UILabel content, string cont) { // Transform emo = content.transform.FindChild("emo").GetComponent<Transform>(); // emo.gameObject.SetActive (false); List <EmotionVo> emotionVoList = new List <EmotionVo>(); if (contentFont == null) { contentFont = content.trueTypeFont; } float emotionPosX = 0; float emotionPosY; string result = ""; string emotionId = ""; string newLine = ""; char[] contentChat = cont.ToCharArray(); for (int i = 0; i < contentChat.Length; ++i) { if (contentChat[i] == '\n') { newLine = "\n"; result += contentChat[i]; continue; } if (contentChat[i] == '/') { Log.info(this, "calX:" + NGUIText.CalculatePrintedSize(newLine).x); Log.info(this, "calY:" + NGUIText.CalculatePrintedSize(newLine).y); emotionId = ""; int len = (contentChat.Length - 1 - i) > 2?3:(contentChat.Length - 1 - i); int j = 1; for (j = 1; j <= len; ++j) { if (contentChat[i + j] == '\n') { ++len; result += '\n'; newLine = "\n"; continue; } emotionId += contentChat[i + j]; } i = i + j - 1; if (Singleton <ChatMode> .Instance.emoDic.ContainsKey(emotionId)) { result += ":"; newLine += ":"; // emo.gameObject.SetActive(true); emotionPosX = NGUIText.CalculatePrintedSize(newLine).x % content.width; emotionPosY = content.height - NGUIText.CalculatePrintedSize(newLine).y; // emo.localPosition = new Vector3(emotionPosX - ChatMode.FONT_SIZE, emotionPosY, 0); emotionVoList.Add(new EmotionVo(new Vector3(emotionPosX - ChatConfig.FONT_SIZE, emotionPosY, 0), "bq_" + emotionId)); } else { result += "/" + emotionId; newLine += "/" + emotionId; } } else { result += contentChat[i]; newLine += contentChat[i]; } } content.text = result; int emoNum = content.transform.childCount; Transform emo = content.transform.FindChild("emo").GetComponent <Transform>(); emo.GetComponent <UISprite>().atlas = Singleton <AtlasManager> .Instance.GetAtlas(AtlasManager.Chat); while (content.transform.childCount < emotionVoList.Count) { Transform emoClone = (GameObject.Instantiate(emo.gameObject, emo.position, emo.rotation) as GameObject).transform; emoClone.parent = emo.parent; } int sub = 0; foreach (Transform child in content.transform) { if (sub < emotionVoList.Count) { child.localPosition = emotionVoList[sub].loacalPos; child.localRotation = new Quaternion(0, 0, 0, 0); child.localScale = new Vector3(1, 1, 1); child.gameObject.SetActive(true); child.GetComponent <UISprite>().spriteName = emotionVoList[sub].emoName; sub++; } else { child.gameObject.SetActive(false); } } }
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; } }
/// <summary> /// Process the raw text, called when something changes. /// </summary> void ProcessText(bool legacyMode) { if (!isValid) { return; } mChanged = true; hasChanged = 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) : fontSize); mScale = 1f; if (NGUIText.rectWidth < 1 || NGUIText.rectHeight < 0) { mProcessedText = ""; return; } UpdateNGUIText(mPrintedSize, mWidth, mHeight); 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 = (bitmapFont != null) ? mScale * bitmapFont.pixelSize : mScale; } NGUIText.Update(false); // Wrap the text bool fits = NGUIText.WrapText(mText, out mProcessedText); 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; } }
/// <summary> /// Process the raw text, called when something changes. /// </summary> void ProcessText(bool legacyMode, bool full) { 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; } #if DYNAMIC_FONT bool isDynamic = (trueTypeFont != null); if (isDynamic && keepCrisp) { UIRoot rt = root; if (rt != null) { mDensity = (rt != null) ? rt.pixelSizeAdjustment : 1f; } } else { mDensity = 1f; } #endif if (full) { UpdateNGUIText(); } 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; #if DYNAMIC_FONT NGUIText.fontScale = isDynamic ? mScale : ((float)mFontSize / mFont.defaultSize) * mScale; #else NGUIText.fontScale = ((float)mFontSize / mFont.defaultSize) * mScale; #endif } 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; } }
private void OnReposition() { for (int i = 0; i < infoContent.transform.childCount; ++i) { Destroy(infoContent.transform.GetChild(i).gameObject); } string[,] array = null; if (!string.IsNullOrEmpty(product.details)) { JsonData jd = JsonMapper.ToObject(product.details); if (jd.IsArray) { array = new string[jd.Count + 1, 2]; for (int i = 0; i < jd.Count; ++i) { array[i + 1, 0] = (string)jd[i]["key"]; array[i + 1, 1] = (string)jd[i]["value"]; } } } if (array == null) { array = new string[1, 2]; } array[0, 0] = ""; array[0, 1] = product.name; UILabel label = labelPrefab.transform.Find("Content").gameObject.GetComponent <UILabel>(); NGUIText.fontSize = label.fontSize; NGUIText.fontStyle = label.fontStyle; NGUIText.rectWidth = label.width; NGUIText.Update(); int yOffset = 0; int lineSpace = 15; UIViewport vp = scrollCamera.GetComponent <UIViewport>(); int height = (int)(vp.topLeft.localPosition.y - vp.bottomRight.localPosition.y); for (int i = 0; i < array.Length / 2; ++i) { GameObject row = NGUITools.AddChild(infoContent, labelPrefab); UILabel nameLabel = row.transform.Find("Name").gameObject.GetComponent <UILabel>(); UILabel contentLabel = row.transform.Find("Content").gameObject.GetComponent <UILabel>(); nameLabel.text = array[i, 0]; contentLabel.text = array[i, 1]; BoxCollider bc = row.GetComponent <BoxCollider>(); UIDragCamera dc = row.GetComponent <UIDragCamera>(); dc.draggableCamera = scrollCamera.GetComponent <UIDraggableCamera>(); Vector2 rect = NGUIText.CalculatePrintedSize(array[i, 1]); if (i == array.Length / 2 - 1 && Math.Abs(yOffset - (int)rect.y - lineSpace) < height) { contentLabel.height = height - Math.Abs(yOffset); } else { contentLabel.height = (int)rect.y; } bc.center = new Vector3(0, -(contentLabel.height + lineSpace) / 2, 0); bc.size = new Vector3(bc.size.x, contentLabel.height + lineSpace, 0); row.transform.localPosition = new Vector3(0, yOffset, 0); yOffset -= (int)rect.y + lineSpace; } }