public override void SubReset() { Name = "Label"; Font_Type = UILabelInspector.FontType.NGUI; UI_Font = null; //Dyn_Font = null; Font_Size = -1; Overflow_Width = -1; Max_Lines = -1; Font_Style = FontStyle.Normal; Overflow_Method = UILabel.Overflow.ResizeFreely; Crisp = UILabel.Crispness.Never; Modifier_Type = UILabel.Modifier.None; Alig_Type = NGUIText.Alignment.Automatic; Symbol_Style = NGUIText.SymbolStyle.Normal; Effect_Type = UILabel.Effect.None; UseEllipsis = false; Gradient = false; BBCode = true; Gradient_Top_Color = Color.white; Gradient_Bottom_Color = new Color(0.7f, 0.7f, 0.7f); Effect_Color = Color.black; Effect_Distance = new Vector2(-1, -1); }
static int IntToEnum(IntPtr L) { int arg0 = (int)LuaDLL.lua_tonumber(L, 1); UILabel.Overflow o = (UILabel.Overflow)arg0; ToLua.Push(L, o); return(1); }
private void SetLabel(UILabel label, int size, UILabel.Overflow overflowMethod = UILabel.Overflow.ClampContent) { if (label == null) { return; } label.overflowMethod = overflowMethod; label.alignment = NGUIText.Alignment.Left; label.fontSize = size; }
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); if ((num & 1) == 1) { num++; } if ((num2 & 1) == 1) { num2++; } this.mWidth = Mathf.Max(width, num); this.mHeight = Mathf.Max(height, num2); this.MarkAsChanged(); } } else { base.MakePixelPerfect(); } }
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(); }
static int set_overflowMethod(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); UILabel obj = (UILabel)o; UILabel.Overflow arg0 = (UILabel.Overflow)ToLua.CheckObject(L, 2, typeof(UILabel.Overflow)); obj.overflowMethod = arg0; return 0; } catch(Exception e) { return LuaDLL.toluaL_exception(L, e, o, "attempt to index overflowMethod on a nil value"); } }
static int get_overflowMethod(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); UILabel obj = (UILabel)o; UILabel.Overflow ret = obj.overflowMethod; ToLua.Push(L, ret); return 1; } catch(Exception e) { return LuaDLL.toluaL_exception(L, e, o, "attempt to index overflowMethod on a nil value"); } }
private void Awake() { this.m_realMatchs = new List <Match>(); this.m_TextLabel = NGUITools.AddChild <UILabel>(base.gameObject); this.m_TextLabel.name = "textLabel"; if (Config.SnailFont != null) { this.m_TextLabel.trueTypeFont = Config.SnailFont.dynamicFont; } this.m_TextLabel.spacingY = this.spacingY; this.m_TextLabel.fontSize = this.fontSize; this.m_TextLabel.overflowMethod = this.overflowMethod; this.m_TextLabel.alignment = this.alignment; this.m_TextLabel.pivot = this.pivot; this.m_TextLabel.width = this.width; this.m_TextLabel.depth = this.depth; this.m_TextLabel.transform.localPosition = Vector3.zero; this.m_TextLabel.SetSymbolOffset(new Action(this.SymbolOffset)); if (this.overflowMethod == UILabel.Overflow.ClampContent) { this.m_TextLabel.height = this.textHeight; this.m_TextLabel.maxLineCount = this.maxLine; } this.m_SymbolLabel = NGUITools.AddChild <UILabel>(base.gameObject); this.m_SymbolLabel.name = "symbolLabel"; this.m_SymbolLabel.bitmapFont = this.uifont; this.m_SymbolLabel.fontSize = this.symbolSize; this.m_SymbolLabel.overflowMethod = this.overflowMethod; this.m_SymbolLabel.alignment = this.alignment; this.m_SymbolLabel.pivot = this.pivot; this.m_SymbolLabel.depth = this.depth + 1; Vector3 zero = Vector3.zero; zero.x = 0f; zero.y = -3f; zero.z = 0f; this.m_SymbolLabel.transform.localPosition = zero; this.m_SymbolLabel.SetSymbolOffset(new Action(this.SymbolOffset)); UIWidget arg_213_0 = this.m_SymbolLabel; int height = 10; this.m_SymbolLabel.height = height; arg_213_0.width = height; }
UILabel.Overflow CalcTextSize(ref Vector2 showSize) { float size_w = mTransSizeWStack.Peek(); float size_h = mTransSizeHStack.Peek(); UILabel.Overflow overflow = UILabel.Overflow.ResizeFreely; if (size_w > showSize.x && size_h <= showSize.y) { showSize.x = size_w; overflow = UILabel.Overflow.ResizeHeight; } else if (size_h > showSize.y && size_w <= showSize.x) { showSize.y = size_h; overflow = UILabel.Overflow.ClampContent; } else if (size_w > showSize.x && size_h > showSize.y) { showSize.x = size_w; showSize.y = size_h; overflow = UILabel.Overflow.ShrinkContent; } return(overflow); }
private void OnGUI() { GUILayout.Space(20); GUILayout.BeginHorizontal(); GUILayout.Label("Overflow", GUILayout.Width(70)); ov = (UILabel.Overflow)EditorGUILayout.EnumPopup(ov); if (GUILayout.Button("修改")) { ChangeOverflow(); } GUILayout.EndHorizontal(); GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.Label("Effect", GUILayout.Width(70)); effect = (UILabel.Effect)EditorGUILayout.EnumPopup(effect); if (GUILayout.Button("修改")) { ChangeEffect(); //ChangeSize(); } GUILayout.EndHorizontal(); GUILayout.Space(10); GUILayout.Label("字体阴影颜色RGB值(在编辑器选中预设后批量修改)"); color = EditorGUILayout.ColorField(color); if (GUILayout.Button("修改字体颜色")) { ChangeColor(); } GUILayout.Space(10); GUILayout.Label("目标字体:"); toFont = (UIFont)EditorGUILayout.ObjectField(toFont, typeof(UIFont), true, GUILayout.MinWidth(100f)); toChangeFont = toFont; if (GUILayout.Button("修改字体大小(Unity4.6字体大小由动态字体决定)")) { ChangeSize(); } GUILayout.Space(10); effecfColor = EditorGUILayout.ColorField(effecfColor); if (GUILayout.Button("修改带特效字体边框颜色")) { ChangeEffectColor(); } GUILayout.Space(10); GUILayout.Label("Spriname"); SPName = EditorGUILayout.TextField(SPName); if (GUILayout.Button("修改图片")) { ChangeSP(); } if (NGUIEditorTools.DrawHeader("Widget")) { NGUIEditorTools.BeginContents(); #region Pivot //DrawPivot(); 采用新算法 [8/20/2017 BingLau] GUILayout.Space(10); int newPivotH = m_H_Select_Pivot, newPivotV = m_V_Select_Pivot; GUILayout.BeginHorizontal(); GUILayout.Label("Pivot", GUILayout.Width(66f)); if (GUILayout.Toggle(newPivotH == 0, "\u25C4", "ButtonLeft")) { newPivotH = 0; } if (GUILayout.Toggle(newPivotH == 1, "\u25AC", "ButtonMid")) { newPivotH = 1; } if (GUILayout.Toggle(newPivotH == 2, "\u25BA", "ButtonRight")) { newPivotH = 2; } if (GUILayout.Toggle(newPivotV == 0, "\u25B2", "ButtonLeft")) { newPivotV = 0; } if (GUILayout.Toggle(newPivotV == 1, "\u258C", "ButtonMid")) { newPivotV = 1; } if (GUILayout.Toggle(newPivotV == 2, "\u25BC", "ButtonRight")) { newPivotV = 2; } GUILayout.EndHorizontal(); if (m_H_Select_Pivot != newPivotH) { m_H_Select_Pivot = newPivotH; } if (m_V_Select_Pivot != newPivotV) { m_V_Select_Pivot = newPivotV; } if (GUILayout.Button("Change Pivot")) { UIWidget.Pivot pivot = (UIWidget.Pivot)(3 * m_V_Select_Pivot + m_H_Select_Pivot); Debug.Log(pivot.ToString()); WidgetContents.pivot = pivot; } #endregion #region DrawDepth //DrawDepth(); GUILayout.Space(10f); GUILayout.BeginHorizontal(); GUILayout.Label("Depth", GUILayout.Width(66f)); if (GUILayout.Button("Back", GUILayout.MinWidth(46f))) { depth -= 1; } GUILayout.Space(5); int newDepth = EditorGUILayout.IntField("", depth, GUILayout.MinWidth(50)); if (newDepth != depth) { depth = newDepth; } GUILayout.Space(5); if (GUILayout.Button("Forward", GUILayout.MinWidth(60f))) { depth += 1; } GUILayout.EndHorizontal(); if (GUILayout.Button("Change Depth")) { Debug.Log("Current Depth: " + depth); } #endregion #region DrawDimensions //DrawDimensions(); GUILayout.Space(10f); GUILayout.BeginHorizontal(); EditorGUIUtility.labelWidth = 70; int newBoundX = EditorGUILayout.IntField("Size", with, GUILayout.MinWidth(30f)); EditorGUIUtility.labelWidth = 12; int newBoundY = EditorGUILayout.IntField("x", height, GUILayout.MinWidth(30f)); EditorGUIUtility.labelWidth = 70; if (GUILayout.Button("Snap", GUILayout.Width(60f))) { Debug.LogError("UNDONE: Change this button to toggle"); } GUILayout.EndHorizontal(); if (GUILayout.Button("Change Dimensions")) { Debug.LogError("UNDONE: Change this button to toggle"); } #endregion NGUIEditorTools.EndContents(); } }
/// <summary> /// Draw widget's dimensions. /// </summary> static void DrawDimensions(SerializedObject so, UIWidget w, bool isPrefab) { GUILayout.BeginHorizontal(); { bool freezeSize = so.isEditingMultipleObjects; UILabel lbl = w as UILabel; if (!freezeSize && lbl) { freezeSize = (lbl.overflowMethod == UILabel.Overflow.ResizeFreely); } if (freezeSize) { EditorGUI.BeginDisabledGroup(true); NGUIEditorTools.DrawProperty("Size", so, "mWidth", GUILayout.MinWidth(100f)); EditorGUI.EndDisabledGroup(); } else { GUI.changed = false; int val = EditorGUILayout.IntField("Size", w.width, GUILayout.MinWidth(100f)); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Dimensions Change", w); w.width = val; } } if (!freezeSize && lbl) { UILabel.Overflow ov = lbl.overflowMethod; freezeSize = (ov == UILabel.Overflow.ResizeFreely || ov == UILabel.Overflow.ResizeHeight); } NGUIEditorTools.SetLabelWidth(12f); if (freezeSize) { EditorGUI.BeginDisabledGroup(true); NGUIEditorTools.DrawProperty("x", so, "mHeight", GUILayout.MinWidth(30f)); EditorGUI.EndDisabledGroup(); } else { GUI.changed = false; int val = EditorGUILayout.IntField("x", w.height, GUILayout.MinWidth(30f)); if (GUI.changed) { NGUIEditorTools.RegisterUndo("Dimensions Change", w); w.height = val; } } NGUIEditorTools.SetLabelWidth(80f); if (isPrefab) { GUILayout.Space(70f); } else { EditorGUI.BeginDisabledGroup(so.isEditingMultipleObjects); if (GUILayout.Button("Snap", GUILayout.Width(60f))) { foreach (GameObject go in Selection.gameObjects) { UIWidget pw = go.GetComponent <UIWidget>(); if (pw != null) { NGUIEditorTools.RegisterUndo("Snap Dimensions", pw); NGUIEditorTools.RegisterUndo("Snap Dimensions", pw.transform); pw.MakePixelPerfect(); } } } EditorGUI.EndDisabledGroup(); } } GUILayout.EndHorizontal(); }
public override void Show(UIDialogeOption option) { base.Show(option); if (Option != option) { // queued return; } if (option is UICustomeDialogueOption == false) { return; } mCustomOption = option as UICustomeDialogueOption; // set style if (mCustomOption.accept != null && acceptButton != null && acceptObject != null && acceptObject.activeSelf) { UILabel acceptLabel = acceptButton.GetComponentInChildren <UILabel>(); if (acceptLabel != null) { mOriginAccept = acceptLabel.text; acceptLabel.text = mCustomOption.accept; } } if (mCustomOption.decline != null && declineButton != null && declineObject != null && declineObject.activeSelf) { UILabel declineLabel = declineButton.GetComponentInChildren <UILabel>(); if (declineLabel != null) { mOriginDecline = declineLabel.text; declineLabel.text = mCustomOption.decline; } } if (mCustomOption.cancel != null && cancelButton != null && cancelObject != null && cancelObject.activeSelf) { UILabel cancelLabel = cancelButton.GetComponentInChildren <UILabel>(); if (cancelLabel != null) { mOriginCancel = cancelLabel.text; cancelLabel.text = mCustomOption.cancel; } } if (body != null && body.activeSelf) { UILabel bodyLabel = body.GetComponentInChildren <UILabel>(); mOriginAllianment = bodyLabel.alignment; mOriginOverflow = bodyLabel.overflowMethod; mOriginHeight = bodyLabel.height; mOriginSpace = bodyLabel.spacingY; //bodyLabel.alignment = mCustomOption.alignment; if (mCustomOption.lineSpace != 0) { bodyLabel.spacingY = mCustomOption.lineSpace; } if (mCustomOption.minHeight != 0) { bodyLabel.ProcessText(); if (bodyLabel.height < mCustomOption.minHeight) { bodyLabel.overflowMethod = UILabel.Overflow.ShrinkContent; bodyLabel.height = Mathf.Max(bodyLabel.height, mCustomOption.minHeight); } } UISprite bodyBackground = body.GetComponentInChildren <UISprite>(true); if (bodyBackground != null) { mOriginBodyBackgroundEnabled = bodyBackground.enabled; bodyBackground.enabled = !mCustomOption.hideBodyBackground; } } }
public override void DrawSubProperty() { state = UIModifierUtils.DrawContentHeader("UILabel", state); if (state) { #region Font EditorGUILayout.HelpBox("暂时只支持Dynamic Fonts替换", MessageType.Warning); GUILayout.BeginHorizontal(); EditorGUI.BeginDisabledGroup(true); Font_Type = (UILabelInspector.FontType)EditorGUILayout.EnumPopup(Font_Type, "DropDown", GUILayout.Width(74f)); EditorGUI.EndDisabledGroup(); if (GUILayout.Button("Font", "DropDown", GUILayout.Width(64f))) { ComponentSelector.Show <UIFont>(OnNGUIFont); } EditorGUILayout.ObjectField(UI_Font, typeof(UIFont), false); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label("Font Size", GUILayout.Width(66)); Font_Size = EditorGUILayout.IntField("", Font_Size, GUILayout.Width(142f)); Font_Style = (FontStyle)EditorGUILayout.EnumPopup(Font_Style); GUILayout.Space(18f); } GUILayout.EndHorizontal(); #endregion GUILayout.BeginHorizontal(); GUILayout.Label("Modifier", GUILayout.Width(66)); Modifier_Type = (UILabel.Modifier)EditorGUILayout.EnumPopup(Modifier_Type); GUILayout.Space(18f); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Alignment", GUILayout.Width(66)); Alig_Type = (NGUIText.Alignment)EditorGUILayout.EnumPopup(Alig_Type); GUILayout.Space(18f); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Effect", GUILayout.Width(66)); Effect_Type = (UILabel.Effect)EditorGUILayout.EnumPopup(Effect_Type); if (Effect_Type != UILabel.Effect.None) { Effect_Color = EditorGUILayout.ColorField(Effect_Color, GUILayout.MinWidth(10f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label(" ", GUILayout.Width(66)); EditorGUIUtility.labelWidth = 20f; Effect_Distance.x = EditorGUILayout.FloatField("X", Effect_Distance.x, GUILayout.MinWidth(40f)); Effect_Distance.y = EditorGUILayout.FloatField("Y", Effect_Distance.y, GUILayout.MinWidth(40f)); EditorGUIUtility.labelWidth = 70; } } GUILayout.Space(18f); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Overflow", GUILayout.Width(66)); Overflow_Method = (UILabel.Overflow)EditorGUILayout.EnumPopup(Overflow_Method); GUILayout.Space(18f); GUILayout.EndHorizontal(); //EditorGUI.indentLevel++; if (Overflow_Method == UILabel.Overflow.ClampContent) { GUILayout.BeginHorizontal(); GUILayout.Label(" ", GUILayout.Width(66)); UseEllipsis = EditorGUILayout.ToggleLeft("Use Ellipsis", UseEllipsis); GUILayout.EndHorizontal(); } else if (Overflow_Method == UILabel.Overflow.ResizeFreely) { GUILayout.BeginHorizontal(); GUILayout.Label(" ", GUILayout.Width(66)); Overflow_Width = EditorGUILayout.IntField("Max Width", Overflow_Width, GUILayout.MinWidth(100)); if (Overflow_Width < 1) { GUILayout.Label("unlimited"); } GUILayout.Space(18f); GUILayout.EndHorizontal(); } //EditorGUI.indentLevel--; GUILayout.BeginHorizontal(); Gradient = EditorGUILayout.Toggle("Gradient", Gradient, GUILayout.Width(80)); EditorGUI.BeginDisabledGroup(!Gradient); { EditorGUIUtility.labelWidth = 40; Gradient_Top_Color = EditorGUILayout.ColorField("Top", Gradient_Top_Color, GUILayout.MinWidth(60)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label(" ", GUILayout.Width(80)); Gradient_Bottom_Color = EditorGUILayout.ColorField("Bottom", Gradient_Bottom_Color, GUILayout.MinWidth(60)); EditorGUIUtility.labelWidth = 70; } EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); BBCode = EditorGUILayout.Toggle("BBCode", BBCode, GUILayout.Width(80)); EditorGUI.BeginDisabledGroup(!BBCode); Symbol_Style = (NGUIText.SymbolStyle)EditorGUILayout.EnumPopup("Symbols", Symbol_Style); EditorGUI.EndDisabledGroup(); GUILayout.Space(18); GUILayout.EndHorizontal(); Max_Lines = EditorGUILayout.IntField("Max Lines", Max_Lines, GUILayout.Width(120)); EditorGUILayout.HelpBox("依据官方文档,强制修改Keep Crisp为Never", MessageType.Warning); EditorGUI.BeginDisabledGroup(true); Crisp = UILabel.Crispness.Never; GUILayout.BeginHorizontal(); GUILayout.Label("Keep Crisp", GUILayout.Width(66)); Crisp = (UILabel.Crispness)EditorGUILayout.EnumPopup(Crisp); GUILayout.Space(18f); GUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); } }
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(); } }
protected override bool DrawProperties() { mLabel = mWidget as UILabel; ComponentSelector.Draw <UIFont>(mLabel.font, OnSelectFont); if (mLabel.font != null) { GUI.skin.textArea.wordWrap = true; string text = string.IsNullOrEmpty(mLabel.text) ? "" : mLabel.text; text = EditorGUILayout.TextArea(mLabel.text, GUI.skin.textArea, GUILayout.Height(100f)); if (!text.Equals(mLabel.text)) { RegisterUndo(); mLabel.text = text; } UILabel.Overflow ov = (UILabel.Overflow)EditorGUILayout.EnumPopup("Overflow", mLabel.overflowMethod); if (ov != mLabel.overflowMethod) { RegisterUndo(); mLabel.overflowMethod = ov; } // Only input fields need this setting exposed, and they have their own "is password" setting, so hiding it here. //GUILayout.BeginHorizontal(); //bool password = EditorGUILayout.Toggle("Password", mLabel.password, GUILayout.Width(100f)); //GUILayout.Label("- hide characters"); //GUILayout.EndHorizontal(); //if (password != mLabel.password) { RegisterUndo(); mLabel.password = password; } GUILayout.BeginHorizontal(); bool encoding = EditorGUILayout.Toggle("Encoding", mLabel.supportEncoding, GUILayout.Width(100f)); GUILayout.Label("use emoticons and colors"); GUILayout.EndHorizontal(); if (encoding != mLabel.supportEncoding) { RegisterUndo(); mLabel.supportEncoding = encoding; } //GUILayout.EndHorizontal(); if (encoding && mLabel.font.hasSymbols) { UIFont.SymbolStyle sym = (UIFont.SymbolStyle)EditorGUILayout.EnumPopup("Symbols", mLabel.symbolStyle, GUILayout.Width(170f)); if (sym != mLabel.symbolStyle) { RegisterUndo(); mLabel.symbolStyle = sym; } } GUILayout.BeginHorizontal(); { UILabel.Effect effect = (UILabel.Effect)EditorGUILayout.EnumPopup("Effect", mLabel.effectStyle, GUILayout.Width(170f)); if (effect != mLabel.effectStyle) { RegisterUndo(); mLabel.effectStyle = effect; } if (effect != UILabel.Effect.None) { Color c = EditorGUILayout.ColorField(mLabel.effectColor); if (mLabel.effectColor != c) { RegisterUndo(); mLabel.effectColor = c; } } } GUILayout.EndHorizontal(); if (mLabel.effectStyle != UILabel.Effect.None) { #if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 GUILayout.Label("Distance", GUILayout.Width(70f)); GUILayout.Space(-34f); GUILayout.BeginHorizontal(); GUILayout.Space(70f); Vector2 offset = EditorGUILayout.Vector2Field("", mLabel.effectDistance); GUILayout.Space(20f); GUILayout.EndHorizontal(); #else Vector2 offset = mLabel.effectDistance; GUILayout.BeginHorizontal(); GUILayout.Label("Distance", GUILayout.Width(76f)); offset.x = EditorGUILayout.FloatField(offset.x); offset.y = EditorGUILayout.FloatField(offset.y); GUILayout.Space(18f); GUILayout.EndHorizontal(); #endif if (offset != mLabel.effectDistance) { RegisterUndo(); mLabel.effectDistance = offset; } } int count = EditorGUILayout.IntField("Max Lines", mLabel.maxLineCount, GUILayout.Width(100f)); if (count != mLabel.maxLineCount) { RegisterUndo(); mLabel.maxLineCount = count; } return(true); } EditorGUILayout.Space(); return(false); }
protected void DoAddText(string text, string hrefb, string hrefColor, string hrefEnable, bool isTitle, bool limitReplace) { if (!limitReplace && 行数限制 > 0 && mNowLineCount >= 行数限制) { return; } UILabel lbl = null; UIFont font = UIResourceManager.LoadFont(FontType); int fontSize = mFontSizeTagStack.Peek(); Color color = mFontColorTagStack.Peek(); UILabelEffect effect = mFontEffectTagStack.Peek(); if (isTitle) { if (string.IsNullOrEmpty(hrefb)) { lbl = UIViewHelper.AddUILabel(底板.gameObject, FontType, fontSize, color); } else { UIHyperLinkLabel linkLbl = UIViewHelper.AddHyperLinkLabel(底板.gameObject, FontType, fontSize, color); linkLbl.OnHyperLinkClicked += OnLinkClicked; linkLbl.LinkDataSource = hrefb; linkLbl.UnderLineColor = hrefColor; linkLbl.LinkDataEnable = hrefEnable; lbl = linkLbl; } Vector2 showSize = new Vector2(lbl.width, lbl.height); lbl.overflowMethod = CalcTextSize(ref showSize); if (effect.type != UILabel.Effect.None) { lbl.effectStyle = effect.type; lbl.effectDistance = effect.dist; lbl.effectColor = effect.color; } lbl.depth = 层级 + 11; lbl.text = text; if (mNowWritePos.x > 0) { DoChangeLine(); } float x = 0; lbl.transform.localPosition = new Vector3(x, mNowWritePos.y - lbl.height * 0.5f); //OnUnitAdded(lbl); DoChangeLine(); } else { UILabel.Overflow overflow = UILabel.Overflow.ResizeFreely; Vector2 showSize = Vector2.zero; if (自动换行) { if (视图尺寸.x < fontSize) { Debug.LogError("富文本设置为自动换行后,视图尺寸至少大于等于一个字的宽度"); return; } string nextLineText = ""; string splitText = text; showSize = CalcTextPrintSize(splitText, font.dynamicFont, fontSize, FontStyle.Normal, true, 1000000, 1000000); overflow = CalcTextSize(ref showSize); float canUseSpace = CalcNowLineCanUsedSpace(); if (showSize.x > canUseSpace) { while (showSize.x > canUseSpace) { for (int i = text.Length - 1; i >= 0; --i) { splitText = splitText.Substring(0, i); showSize = CalcTextPrintSize(splitText, font.dynamicFont, fontSize, FontStyle.Normal, true, 1000000, 1000000); overflow = CalcTextSize(ref showSize); if (showSize.x <= canUseSpace) { break; } } if (string.IsNullOrEmpty(splitText)) { if (DoChangeLine()) { DoAddText(text, hrefb, hrefColor, hrefEnable, false); } return; } } nextLineText = text.Substring(splitText.Length); DoAddText(splitText, hrefb, hrefColor, hrefEnable, false); if (DoChangeLine()) { DoAddText(nextLineText, hrefb, hrefColor, hrefEnable, false); } return; } } if (string.IsNullOrEmpty(hrefb)) { lbl = UIViewHelper.AddUILabel(底板.gameObject, FontType, fontSize, color); } else { UIHyperLinkLabel linkLbl = UIViewHelper.AddHyperLinkLabel(底板.gameObject, FontType, fontSize, color); linkLbl.OnHyperLinkClicked += OnLinkClicked; linkLbl.LinkDataSource = hrefb; linkLbl.UnderLineColor = hrefColor; linkLbl.LinkDataEnable = hrefEnable; lbl = linkLbl; } lbl.width = (int)showSize.x; lbl.height = (int)showSize.y; lbl.overflowMethod = overflow; if (effect.type != UILabel.Effect.None) { lbl.effectStyle = effect.type; lbl.effectDistance = effect.dist; lbl.effectColor = effect.color; } lbl.depth = 层级 + 11; lbl.text = text; Vector3 pos = new Vector3(mNowWritePos.x - (视图尺寸.x - (float)lbl.width) * 0.5f, mNowWritePos.y - lbl.height * 0.5f); lbl.transform.localPosition = pos; OnUnitAdded(lbl); } }
void UpdateHTML() { if (html != null && Compiler_ != null) { currentRoot = NGUITools.FindInParents<UIRoot>(transform); currentDefaultFont = defaultFont; // we have new html text, so compile it Compiler_.Compile(html, maxLineWidth > 0 ? maxLineWidth : Screen.width); // destroy old widgets. Transform[] childs = new Transform[transform.childCount]; for (int i = 0; i < transform.childCount; ++i) childs[i] = transform.GetChild(i); foreach (Transform childTr in childs) { GameObject go; if (!gameobjs.TryGetValue(childTr.gameObject.name, out go)) { childTr.gameObject.transform.parent = null; Destroy(childTr.gameObject); } } // generate the widgets. currentDepth = depth; currentLabelOverflow = labelOverflow; currentLabelCrispness = labelCrispness; Compiler_.Draw(Time.deltaTime, transform); IDictionaryEnumerator e = gameobjs.GetEnumerator(); while (e.MoveNext()) { string id = (string)e.Key; if (!gameobjinuse.ContainsKey(id)) { Destroy((GameObject)e.Value); gameobjs.Remove(id); } } gameobjinuse.Clear(); height = Compiler_.Height(); width = Compiler_.Width(); //Debug.LogWarning("width:" + width + ",height:" + height); UpdateTarget(); if (autoScroll != AutoScrollType.MANUAL && (NGUITools.GetActive(this))) { StartCoroutine(updateAutoScroll()); } } }