/// <summary> /// Automatically find the values if none were specified. /// </summary> void Awake() { if (textLabel == null) { textLabel = GetComponentInChildren <NGUILabel>(); } if (textLabel != null) { textLabel.lineWidth = 0; } Collider col = collider; if (col != null) { // Automatically set the width and height based on the collider if (maxHeight <= 0f) { maxHeight = col.bounds.size.y / transform.lossyScale.y; } if (maxWidth <= 0f) { maxWidth = col.bounds.size.x / transform.lossyScale.x; } } }
/// <summary> /// Labels used for input shouldn't support color encoding. /// </summary> protected void Init() { if (mDoInit) { mDoInit = false; if (label == null) { label = GetComponentInChildren <NGUILabel>(); } if (label != null) { if (useLabelTextAtStart) { mText = label.text; } mDefaultText = label.text; mDefaultColor = label.color; label.supportEncoding = false; label.password = isPassword; mPivot = label.pivot; mPosition = label.cachedTransform.localPosition.x; } else { enabled = false; } } }
/// <summary> /// Visibly highlight the specified transform by moving the highlight sprite to be over it. /// </summary> void Highlight(NGUILabel lbl, bool instant) { if (mHighlight != null) { // Don't allow highlighting while the label is animating to its intended position TweenPosition tp = lbl.GetComponent <TweenPosition>(); if (tp != null && tp.enabled) { return; } mHighlightedLabel = lbl; NGUIAtlas.Sprite sp = mHighlight.GetAtlasSprite(); if (sp == null) { return; } float offsetX = sp.inner.xMin - sp.outer.xMin; float offsetY = sp.inner.yMin - sp.outer.yMin; Vector3 pos = lbl.cachedTransform.localPosition + new Vector3(-offsetX, offsetY, 0f); if (instant || !isAnimated) { mHighlight.cachedTransform.localPosition = pos; } else { TweenPosition.Begin(mHighlight.gameObject, 0.1f, pos).method = NGUITweener.Method.EaseOut; } } }
/// <summary> /// Event function triggered when the mouse hovers over an item. /// </summary> void OnItemHover(GameObject go, bool isOver) { if (isOver) { NGUILabel lbl = go.GetComponent <NGUILabel>(); Highlight(lbl, false); } }
public static EmojiSpriteLabel create(NGUILabel pLabel) { EmojiSpriteLabel instance = new EmojiSpriteLabel(); instance.label = pLabel; instance.sprites = new List <GameObject>(); return(instance); }
/// <summary> /// Checkbox creation function. /// </summary> void CreateCheckbox(GameObject go) { if (NGUISettings.atlas != null) { NGUIEditorTools.SpriteField("Background", "Sprite used for the background", NGUISettings.atlas, mCheckBG, OnCheckBG); NGUIEditorTools.SpriteField("Checkmark", "Sprite used for the checkmark", NGUISettings.atlas, mCheck, OnCheck); } if (ShouldCreate(go, NGUISettings.atlas != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Checkbox"; NGUISprite bg = NGUITools.AddWidget <NGUISprite>(go); bg.type = NGUISprite.Type.Sliced; bg.name = "Background"; bg.depth = depth; bg.atlas = NGUISettings.atlas; bg.spriteName = mCheckBG; bg.transform.localScale = new Vector3(26f, 26f, 1f); bg.MakePixelPerfect(); NGUISprite fg = NGUITools.AddWidget <NGUISprite>(go); fg.name = "Checkmark"; fg.atlas = NGUISettings.atlas; fg.spriteName = mCheck; fg.MakePixelPerfect(); if (NGUISettings.font != null) { NGUILabel lbl = NGUITools.AddWidget <NGUILabel>(go); lbl.font = NGUISettings.font; lbl.text = go.name; lbl.pivot = NGUIWidget.Pivot.Left; lbl.transform.localPosition = new Vector3(16f, 0f, 0f); lbl.MakePixelPerfect(); } // Add a collider NGUITools.AddWidgetCollider(go); // Add the scripts go.AddComponent <NGUICheckbox>().checkSprite = fg; go.AddComponent <NGUIButton>().tweenTarget = bg.gameObject; go.AddComponent <NGUIButtonScale>().tweenTarget = bg.transform; go.AddComponent <NGUIButtonSound>(); Selection.activeGameObject = go; } }
/// <summary> /// Button creation function. /// </summary> void CreateImageButton(GameObject go) { if (NGUISettings.atlas != null) { NGUIEditorTools.SpriteField("Normal", "Normal state sprite", NGUISettings.atlas, mImage0, OnImage0); NGUIEditorTools.SpriteField("Hover", "Hover state sprite", NGUISettings.atlas, mImage1, OnImage1); NGUIEditorTools.SpriteField("Pressed", "Pressed state sprite", NGUISettings.atlas, mImage2, OnImage2); NGUIEditorTools.SpriteField("Disabled", "Disabled state sprite", NGUISettings.atlas, mImage3, OnImage3); } if (ShouldCreate(go, NGUISettings.atlas != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Image Button"; NGUIAtlas.Sprite sp = NGUISettings.atlas.GetSprite(mImage0); NGUISprite sprite = NGUITools.AddWidget <NGUISprite>(go); sprite.type = (sp.inner == sp.outer) ? NGUISprite.Type.Simple : NGUISprite.Type.Sliced; sprite.name = "Background"; sprite.depth = depth; sprite.atlas = NGUISettings.atlas; sprite.spriteName = mImage0; sprite.transform.localScale = new Vector3(150f, 40f, 1f); sprite.MakePixelPerfect(); if (NGUISettings.font != null) { NGUILabel lbl = NGUITools.AddWidget <NGUILabel>(go); lbl.font = NGUISettings.font; lbl.text = go.name; lbl.MakePixelPerfect(); } // Add a collider NGUITools.AddWidgetCollider(go); // Add the scripts NGUIImageButton ib = go.AddComponent <NGUIImageButton>(); ib.target = sprite; ib.normalSprite = mImage0; ib.hoverSprite = mImage1; ib.pressedSprite = mImage2; go.AddComponent <NGUIButtonSound>(); Selection.activeGameObject = go; } }
/// <summary> /// Input field creation function. /// </summary> void CreateInput(GameObject go) { if (NGUISettings.atlas != null) { NGUIEditorTools.SpriteField("Background", "Sliced Sprite for the background", NGUISettings.atlas, mInputBG, OnInputBG); } if (ShouldCreate(go, NGUISettings.atlas != null && NGUISettings.font != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Input"; float padding = 3f; NGUISprite bg = NGUITools.AddWidget <NGUISprite>(go); bg.type = NGUISprite.Type.Sliced; bg.name = "Background"; bg.depth = depth; bg.atlas = NGUISettings.atlas; bg.spriteName = mInputBG; bg.pivot = NGUIWidget.Pivot.Left; bg.transform.localScale = new Vector3(400f, NGUISettings.font.size + padding * 2f, 1f); bg.transform.localPosition = Vector3.zero; bg.MakePixelPerfect(); NGUILabel lbl = NGUITools.AddWidget <NGUILabel>(go); lbl.font = NGUISettings.font; lbl.pivot = NGUIWidget.Pivot.Left; lbl.transform.localPosition = new Vector3(padding, 0f, 0f); lbl.multiLine = false; lbl.supportEncoding = false; lbl.lineWidth = Mathf.RoundToInt(400f - padding * 2f); lbl.text = "You can type here"; lbl.MakePixelPerfect(); // Add a collider to the background NGUITools.AddWidgetCollider(go); // Add an input script to the background and have it point to the label NGUIInput input = go.AddComponent <NGUIInput>(); input.label = lbl; // Update the selection Selection.activeGameObject = go; } }
/// <summary> /// Button creation function. /// </summary> void CreateButton(GameObject go) { if (NGUISettings.atlas != null) { NGUIEditorTools.SpriteField("Background", "Sliced Sprite for the background", NGUISettings.atlas, mButton, OnButton); } if (ShouldCreate(go, NGUISettings.atlas != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Button"; NGUISprite bg = NGUITools.AddWidget <NGUISprite>(go); bg.type = NGUISprite.Type.Sliced; bg.name = "Background"; bg.depth = depth; bg.atlas = NGUISettings.atlas; bg.spriteName = mButton; bg.transform.localScale = new Vector3(150f, 40f, 1f); bg.MakePixelPerfect(); if (NGUISettings.font != null) { NGUILabel lbl = NGUITools.AddWidget <NGUILabel>(go); lbl.font = NGUISettings.font; lbl.text = go.name; lbl.MakePixelPerfect(); } // Add a collider NGUITools.AddWidgetCollider(go); // Add the scripts go.AddComponent <NGUIButton>().tweenTarget = bg.gameObject; go.AddComponent <NGUIButtonScale>(); go.AddComponent <NGUIButtonOffset>(); go.AddComponent <NGUIButtonSound>(); Selection.activeGameObject = go; } }
/// <summary> /// Select the specified label. /// </summary> void Select(NGUILabel lbl, bool instant) { Highlight(lbl, instant); NGUIEventListener listener = lbl.gameObject.GetComponent <NGUIEventListener>(); selection = listener.parameter as string; NGUIButtonSound[] sounds = GetComponents <NGUIButtonSound>(); for (int i = 0, imax = sounds.Length; i < imax; ++i) { NGUIButtonSound snd = sounds[i]; if (snd.trigger == NGUIButtonSound.Trigger.OnClick) { NGUITools.PlaySound(snd.audioClip, snd.volume, 1f); } } }
static public void AddLabel() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { Undo.RegisterSceneUndo("Add a Label"); NGUILabel lbl = NGUITools.AddWidget <NGUILabel>(go); lbl.name = "Label"; lbl.font = NGUISettings.font; lbl.text = "New Label"; lbl.pivot = NGUISettings.pivot; lbl.cachedTransform.localScale = new Vector3(100f, 100f, 1f); lbl.MakePixelPerfect(); Selection.activeGameObject = lbl.gameObject; } else { Debug.Log("You must select a game object first."); } }
/// <summary> /// Force-localize the widget. /// </summary> public void Localize() { Localization loc = Localization.instance; NGUIWidget w = GetComponent <NGUIWidget>(); NGUILabel lbl = w as NGUILabel; NGUISprite sp = w as NGUISprite; // If no localization key has been specified, use the label's text as the key if (string.IsNullOrEmpty(mLanguage) && string.IsNullOrEmpty(key) && lbl != null) { key = lbl.text; } // If we still don't have a key, leave the value as blank string val = string.IsNullOrEmpty(key) ? "" : loc.Get(key); if (lbl != null) { // If this is a label used by input, we should localize its default value instead NGUIInput input = NGUITools.FindInParents <NGUIInput>(lbl.gameObject); if (input != null && input.label == lbl) { input.defaultText = val; } else { lbl.text = val; } } else if (sp != null) { sp.spriteName = val; sp.MakePixelPerfect(); } mLanguage = loc.currentLanguage; }
/// <summary> /// Label creation function. /// </summary> void CreateLabel(GameObject go) { GUILayout.BeginHorizontal(); Color c = EditorGUILayout.ColorField("Color", mColor, GUILayout.Width(220f)); GUILayout.Label("Color tint the label will start with"); GUILayout.EndHorizontal(); if (mColor != c) { mColor = c; Save(); } if (ShouldCreate(go, NGUISettings.font != null)) { NGUILabel lbl = NGUITools.AddWidget <NGUILabel>(go); lbl.font = NGUISettings.font; lbl.text = "New Label"; lbl.color = mColor; lbl.MakePixelPerfect(); Selection.activeGameObject = lbl.gameObject; } }
// Use this for initialization void Awake() { tshScrKbStt = true; m_StatusText = this.gameObject.GetComponent<NGUILabel>(); }
public override void OnInspectorGUI() { EditorGUIUtility.LookLikeControls(80f); mList = target as NGUIPopupList; ComponentSelector.Draw <NGUIAtlas>(mList.atlas, OnSelectAtlas); ComponentSelector.Draw <NGUIFont>(mList.font, OnSelectFont); GUILayout.BeginHorizontal(); NGUILabel lbl = EditorGUILayout.ObjectField("Text Label", mList.textLabel, typeof(NGUILabel), true) as NGUILabel; if (mList.textLabel != lbl) { RegisterUndo(); mList.textLabel = lbl; if (lbl != null) { lbl.text = mList.selection; } } GUILayout.Space(44f); GUILayout.EndHorizontal(); if (mList.atlas != null) { NGUIEditorTools.SpriteField("Background", mList.atlas, mList.backgroundSprite, OnBackground); NGUIEditorTools.SpriteField("Highlight", mList.atlas, mList.highlightSprite, OnHighlight); GUILayout.BeginHorizontal(); GUILayout.Space(6f); GUILayout.Label("Options"); GUILayout.EndHorizontal(); string text = ""; foreach (string s in mList.items) { text += s + "\n"; } GUILayout.Space(-14f); GUILayout.BeginHorizontal(); GUILayout.Space(84f); string modified = EditorGUILayout.TextArea(text, GUILayout.Height(100f)); GUILayout.EndHorizontal(); if (modified != text) { RegisterUndo(); string[] split = modified.Split(new char[] { '\n' }, System.StringSplitOptions.RemoveEmptyEntries); mList.items.Clear(); foreach (string s in split) { mList.items.Add(s); } if (string.IsNullOrEmpty(mList.selection) || !mList.items.Contains(mList.selection)) { mList.selection = mList.items.Count > 0 ? mList.items[0] : ""; } } string sel = NGUIEditorTools.DrawList("Selection", mList.items.ToArray(), mList.selection); if (mList.selection != sel) { RegisterUndo(); mList.selection = sel; } NGUIPopupList.Position pos = (NGUIPopupList.Position)EditorGUILayout.EnumPopup("Position", mList.position); if (mList.position != pos) { RegisterUndo(); mList.position = pos; } float ts = EditorGUILayout.FloatField("Text Scale", mList.textScale); Color tc = EditorGUILayout.ColorField("Text Color", mList.textColor); Color bc = EditorGUILayout.ColorField("Background", mList.backgroundColor); Color hc = EditorGUILayout.ColorField("Highlight", mList.highlightColor); GUILayout.BeginHorizontal(); bool isLocalized = EditorGUILayout.Toggle("Localized", mList.isLocalized, GUILayout.Width(100f)); bool isAnimated = EditorGUILayout.Toggle("Animated", mList.isAnimated); GUILayout.EndHorizontal(); if (mList.textScale != ts || mList.textColor != tc || mList.highlightColor != hc || mList.backgroundColor != bc || mList.isLocalized != isLocalized || mList.isAnimated != isAnimated) { RegisterUndo(); mList.textScale = ts; mList.textColor = tc; mList.backgroundColor = bc; mList.highlightColor = hc; mList.isLocalized = isLocalized; mList.isAnimated = isAnimated; } NGUIEditorTools.DrawSeparator(); GUILayout.BeginHorizontal(); GUILayout.Space(6f); GUILayout.Label("Padding", GUILayout.Width(76f)); GUILayout.BeginVertical(); GUILayout.Space(-12f); Vector2 padding = EditorGUILayout.Vector2Field("", mList.padding); GUILayout.EndVertical(); GUILayout.EndHorizontal(); if (mList.padding != padding) { RegisterUndo(); mList.padding = padding; } EditorGUIUtility.LookLikeControls(100f); GameObject go = EditorGUILayout.ObjectField("Event Receiver", mList.eventReceiver, typeof(GameObject), true) as GameObject; string fn = EditorGUILayout.TextField("Function Name", mList.functionName); if (mList.eventReceiver != go || mList.functionName != fn) { RegisterUndo(); mList.eventReceiver = go; mList.functionName = fn; } } }
protected override bool DrawProperties() { mLabel = mWidget as NGUILabel; ComponentSelector.Draw<NGUIFont>(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; } // Added by YLL int size = EditorGUILayout.IntField("Font Size", mLabel.fontSize, GUILayout.Width(120f)); if (size != mLabel.fontSize) { RegisterUndo(); mLabel.fontSize = size; } GUILayout.BeginHorizontal(); int len = EditorGUILayout.IntField("Max Width", mLabel.lineWidth, GUILayout.Width(120f)); GUILayout.Label("pixels"); GUILayout.EndHorizontal(); if (len != mLabel.lineWidth) { RegisterUndo(); mLabel.lineWidth = len; } int count = EditorGUILayout.IntField("Max Lines", mLabel.maxLineCount, GUILayout.Width(100f)); if (count != mLabel.maxLineCount) { RegisterUndo(); mLabel.maxLineCount = count; } GUILayout.BeginHorizontal(); bool shrinkToFit = EditorGUILayout.Toggle("Shrink to Fit", mLabel.shrinkToFit, GUILayout.Width(100f)); GUILayout.Label("- adjust scale if doesn't fit"); GUILayout.EndHorizontal(); if (shrinkToFit != mLabel.shrinkToFit) { RegisterUndo(); mLabel.shrinkToFit = shrinkToFit; } 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; } if(mLabel.font.isDynamic) { GUILayout.BeginHorizontal(); bool isUsedEmojiSprite = EditorGUILayout.Toggle("isUsedEmojiSprite", mLabel.isUsedEmojiSprite, GUILayout.Width(100f)); GUILayout.Label("- use for dynamic symblo."); GUILayout.EndHorizontal(); if(mLabel.isUsedEmojiSprite != isUsedEmojiSprite) mLabel.isUsedEmojiSprite = isUsedEmojiSprite; } //GUILayout.EndHorizontal(); if (encoding && mLabel.font.hasSymbols) { NGUIFont.SymbolStyle sym = (NGUIFont.SymbolStyle)EditorGUILayout.EnumPopup("Symbols", mLabel.symbolStyle, GUILayout.Width(170f)); if (sym != mLabel.symbolStyle) { RegisterUndo(); mLabel.symbolStyle = sym; } } GUILayout.BeginHorizontal(); { NGUILabel.Effect effect = (NGUILabel.Effect)EditorGUILayout.EnumPopup("Effect", mLabel.effectStyle, GUILayout.Width(170f)); if (effect != mLabel.effectStyle) { RegisterUndo(); mLabel.effectStyle = effect; } if (effect != NGUILabel.Effect.None) { Color c = EditorGUILayout.ColorField(mLabel.effectColor); if (mLabel.effectColor != c) { RegisterUndo(); mLabel.effectColor = c; } } } GUILayout.EndHorizontal(); if (mLabel.effectStyle != NGUILabel.Effect.None) { GUILayout.Label("Distance", GUILayout.Width(70f)); GUILayout.Space(-34f); GUILayout.BeginHorizontal(); GUILayout.Space(70f); Vector2 offset = EditorGUILayout.Vector2Field("", mLabel.effectDistance); GUILayout.Space(20f); if (offset != mLabel.effectDistance) { RegisterUndo(); mLabel.effectDistance = offset; } GUILayout.EndHorizontal(); } return true; } EditorGUILayout.Space(); return false; }
/// <summary> /// Mark all widgets associated with this atlas as having changed. /// </summary> public void MarkAsDirty() { #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(gameObject); #endif if (mReplacement != null) { mReplacement.MarkAsDirty(); } NGUISprite[] list = NGUITools.FindActive <NGUISprite>(); for (int i = 0, imax = list.Length; i < imax; ++i) { NGUISprite sp = list[i]; if (CheckIfRelated(this, sp.atlas)) { NGUIAtlas atl = sp.atlas; sp.atlas = null; sp.atlas = atl; #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(sp); #endif } } NGUIFont[] fonts = Resources.FindObjectsOfTypeAll(typeof(NGUIFont)) as NGUIFont[]; for (int i = 0, imax = fonts.Length; i < imax; ++i) { NGUIFont font = fonts[i]; if (CheckIfRelated(this, font.atlas)) { NGUIAtlas atl = font.atlas; font.atlas = null; font.atlas = atl; #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(font); #endif } } NGUILabel[] labels = NGUITools.FindActive <NGUILabel>(); for (int i = 0, imax = labels.Length; i < imax; ++i) { NGUILabel lbl = labels[i]; if (lbl.font != null && CheckIfRelated(this, lbl.font.atlas)) { NGUIFont font = lbl.font; lbl.font = null; lbl.font = font; #if UNITY_EDITOR UnityEditor.EditorUtility.SetDirty(lbl); #endif } } }
// Use this for initialization void Awake() { tshScrKbStt = true; m_StatusText = this.gameObject.GetComponent <NGUILabel>(); }
/// <summary> /// Automatically find the values if none were specified. /// </summary> void Awake() { if (textLabel == null) textLabel = GetComponentInChildren<NGUILabel>(); if (textLabel != null) textLabel.lineWidth = 0; Collider col = collider; if (col != null) { // Automatically set the width and height based on the collider if (maxHeight <= 0f) maxHeight = col.bounds.size.y / transform.lossyScale.y; if (maxWidth <= 0f) maxWidth = col.bounds.size.x / transform.lossyScale.x; } }
/// <summary> /// Display the drop-down list when the game object gets clicked on. /// </summary> void OnClick() { if (mChild == null && atlas != null && font != null && items.Count > 0) { mLabelList.Clear(); // Disable the navigation script handleEvents = true; // Automatically locate the panel responsible for this object if (mPanel == null) { mPanel = NGUIPanel.Find(transform, true); } // Calculate the dimensions of the object triggering the popup list so we can position it below it Transform myTrans = transform; Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(myTrans.parent, myTrans); // Create the root object for the list mChild = new GameObject("Drop-down List"); mChild.layer = gameObject.layer; Transform t = mChild.transform; t.parent = myTrans.parent; t.localPosition = bounds.min; t.localRotation = Quaternion.identity; t.localScale = Vector3.one; // Add a sprite for the background mBackground = NGUITools.AddSprite(mChild, atlas, backgroundSprite); mBackground.pivot = NGUIWidget.Pivot.TopLeft; mBackground.depth = NGUITools.CalculateNextDepth(mPanel.gameObject); mBackground.color = backgroundColor; // We need to know the size of the background sprite for padding purposes Vector4 bgPadding = mBackground.border; mBgBorder = bgPadding.y; mBackground.cachedTransform.localPosition = new Vector3(0f, bgPadding.y, 0f); // Add a sprite used for the selection mHighlight = NGUITools.AddSprite(mChild, atlas, highlightSprite); mHighlight.pivot = NGUIWidget.Pivot.TopLeft; mHighlight.color = highlightColor; NGUIAtlas.Sprite hlsp = mHighlight.GetAtlasSprite(); if (hlsp == null) { return; } float hlspHeight = hlsp.inner.yMin - hlsp.outer.yMin; float fontScale = font.size * font.pixelSize * textScale; float x = 0f, y = -padding.y; List <NGUILabel> labels = new List <NGUILabel>(); // Run through all items and create labels for each one for (int i = 0, imax = items.Count; i < imax; ++i) { string s = items[i]; NGUILabel lbl = NGUITools.AddWidget <NGUILabel>(mChild); lbl.pivot = NGUIWidget.Pivot.TopLeft; lbl.font = font; lbl.text = (isLocalized && Localization.instance != null) ? Localization.instance.Get(s) : s; lbl.color = textColor; lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x, y, -0.01f); lbl.MakePixelPerfect(); if (textScale != 1f) { Vector3 scale = lbl.cachedTransform.localScale; lbl.cachedTransform.localScale = scale * textScale; } labels.Add(lbl); y -= fontScale; y -= padding.y; x = Mathf.Max(x, lbl.relativeSize.x * fontScale); // Add an event listener NGUIEventListener listener = NGUIEventListener.Get(lbl.gameObject); listener.onHover = OnItemHover; listener.onPress = OnItemPress; listener.parameter = s; // Move the selection here if this is the right label if (mSelectedItem == s) { Highlight(lbl, true); } // Add this label to the list mLabelList.Add(lbl); } // The triggering widget's width should be the minimum allowed width x = Mathf.Max(x, bounds.size.x - (bgPadding.x + padding.x) * 2f); Vector3 bcCenter = new Vector3((x * 0.5f) / fontScale, -0.5f, 0f); Vector3 bcSize = new Vector3(x / fontScale, (fontScale + padding.y) / fontScale, 1f); // Run through all labels and add colliders for (int i = 0, imax = labels.Count; i < imax; ++i) { NGUILabel lbl = labels[i]; BoxCollider bc = NGUITools.AddWidgetCollider(lbl.gameObject); bcCenter.z = bc.center.z; bc.center = bcCenter; bc.size = bcSize; } x += (bgPadding.x + padding.x) * 2f; y -= bgPadding.y; // Scale the background sprite to envelop the entire set of items mBackground.cachedTransform.localScale = new Vector3(x, -y + bgPadding.y, 1f); // Scale the highlight sprite to envelop a single item mHighlight.cachedTransform.localScale = new Vector3( x - (bgPadding.x + padding.x) * 2f + (hlsp.inner.xMin - hlsp.outer.xMin) * 2f, fontScale + hlspHeight * 2f, 1f); bool placeAbove = (position == Position.Above); if (position == Position.Auto) { NGUICamera cam = NGUICamera.FindCameraForLayer(gameObject.layer); if (cam != null) { Vector3 viewPos = cam.cachedCamera.WorldToViewportPoint(myTrans.position); placeAbove = (viewPos.y < 0.5f); } } // If the list should be animated, let's animate it by expanding it if (isAnimated) { float bottom = y + fontScale; Animate(mHighlight, placeAbove, bottom); for (int i = 0, imax = labels.Count; i < imax; ++i) { Animate(labels[i], placeAbove, bottom); } AnimateColor(mBackground); AnimateScale(mBackground, placeAbove, bottom); } // If we need to place the popup list above the item, we need to reposition everything by the size of the list if (placeAbove) { t.localPosition = new Vector3(bounds.min.x, bounds.max.y - y - bgPadding.y, bounds.min.z); } } else { OnSelect(false); } }
override protected bool DrawProperties() { mLabel = mWidget as NGUILabel; ComponentSelector.Draw <NGUIFont>(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; } // Added by YLL int size = EditorGUILayout.IntField("Font Size", mLabel.fontSize, GUILayout.Width(120f)); if (size != mLabel.fontSize) { RegisterUndo(); mLabel.fontSize = size; } GUILayout.BeginHorizontal(); int len = EditorGUILayout.IntField("Max Width", mLabel.lineWidth, GUILayout.Width(120f)); GUILayout.Label("pixels"); GUILayout.EndHorizontal(); if (len != mLabel.lineWidth) { RegisterUndo(); mLabel.lineWidth = len; } int count = EditorGUILayout.IntField("Max Lines", mLabel.maxLineCount, GUILayout.Width(100f)); if (count != mLabel.maxLineCount) { RegisterUndo(); mLabel.maxLineCount = count; } GUILayout.BeginHorizontal(); bool shrinkToFit = EditorGUILayout.Toggle("Shrink to Fit", mLabel.shrinkToFit, GUILayout.Width(100f)); GUILayout.Label("- adjust scale if doesn't fit"); GUILayout.EndHorizontal(); if (shrinkToFit != mLabel.shrinkToFit) { RegisterUndo(); mLabel.shrinkToFit = shrinkToFit; } 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; } if (mLabel.font.isDynamic) { GUILayout.BeginHorizontal(); bool isUsedEmojiSprite = EditorGUILayout.Toggle("isUsedEmojiSprite", mLabel.isUsedEmojiSprite, GUILayout.Width(100f)); GUILayout.Label("- use for dynamic symblo."); GUILayout.EndHorizontal(); if (mLabel.isUsedEmojiSprite != isUsedEmojiSprite) { mLabel.isUsedEmojiSprite = isUsedEmojiSprite; } } //GUILayout.EndHorizontal(); if (encoding && mLabel.font.hasSymbols) { NGUIFont.SymbolStyle sym = (NGUIFont.SymbolStyle)EditorGUILayout.EnumPopup("Symbols", mLabel.symbolStyle, GUILayout.Width(170f)); if (sym != mLabel.symbolStyle) { RegisterUndo(); mLabel.symbolStyle = sym; } } GUILayout.BeginHorizontal(); { NGUILabel.Effect effect = (NGUILabel.Effect)EditorGUILayout.EnumPopup("Effect", mLabel.effectStyle, GUILayout.Width(170f)); if (effect != mLabel.effectStyle) { RegisterUndo(); mLabel.effectStyle = effect; } if (effect != NGUILabel.Effect.None) { Color c = EditorGUILayout.ColorField(mLabel.effectColor); if (mLabel.effectColor != c) { RegisterUndo(); mLabel.effectColor = c; } } } GUILayout.EndHorizontal(); if (mLabel.effectStyle != NGUILabel.Effect.None) { GUILayout.Label("Distance", GUILayout.Width(70f)); GUILayout.Space(-34f); GUILayout.BeginHorizontal(); GUILayout.Space(70f); Vector2 offset = EditorGUILayout.Vector2Field("", mLabel.effectDistance); GUILayout.Space(20f); if (offset != mLabel.effectDistance) { RegisterUndo(); mLabel.effectDistance = offset; } GUILayout.EndHorizontal(); } return(true); } EditorGUILayout.Space(); return(false); }
void Awake() { mLabel = GetComponent <NGUILabel>(); }
/// <summary> /// Select the specified label. /// </summary> void Select(NGUILabel lbl, bool instant) { Highlight(lbl, instant); NGUIEventListener listener = lbl.gameObject.GetComponent<NGUIEventListener>(); selection = listener.parameter as string; NGUIButtonSound[] sounds = GetComponents<NGUIButtonSound>(); for (int i = 0, imax = sounds.Length; i < imax; ++i) { NGUIButtonSound snd = sounds[i]; if (snd.trigger == NGUIButtonSound.Trigger.OnClick) { NGUITools.PlaySound(snd.audioClip, snd.volume, 1f); } } }
void Awake() { mLabel = GetComponent<NGUILabel>(); }
/// <summary> /// Create a popup list or a menu. /// </summary> void CreatePopup(GameObject go, bool isDropDown) { if (NGUISettings.atlas != null) { NGUIEditorTools.SpriteField("Foreground", "Foreground sprite (shown on the button)", NGUISettings.atlas, mListFG, OnListFG); NGUIEditorTools.SpriteField("Background", "Background sprite (envelops the options)", NGUISettings.atlas, mListBG, OnListBG); NGUIEditorTools.SpriteField("Highlight", "Sprite used to highlight the selected option", NGUISettings.atlas, mListHL, OnListHL); } if (ShouldCreate(go, NGUISettings.atlas != null && NGUISettings.font != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = isDropDown ? "Popup List" : "Popup Menu"; NGUIAtlas.Sprite sphl = NGUISettings.atlas.GetSprite(mListHL); NGUIAtlas.Sprite spfg = NGUISettings.atlas.GetSprite(mListFG); Vector2 hlPadding = new Vector2( Mathf.Max(4f, sphl.inner.xMin - sphl.outer.xMin), Mathf.Max(4f, sphl.inner.yMin - sphl.outer.yMin)); Vector2 fgPadding = new Vector2( Mathf.Max(4f, spfg.inner.xMin - spfg.outer.xMin), Mathf.Max(4f, spfg.inner.yMin - spfg.outer.yMin)); // Background sprite NGUISprite sprite = NGUITools.AddSprite(go, NGUISettings.atlas, mListFG); sprite.depth = depth; sprite.atlas = NGUISettings.atlas; sprite.pivot = NGUIWidget.Pivot.Left; sprite.transform.localScale = new Vector3(150f + fgPadding.x * 2f, NGUISettings.font.size + fgPadding.y * 2f, 1f); sprite.transform.localPosition = Vector3.zero; sprite.MakePixelPerfect(); // Text label NGUILabel lbl = NGUITools.AddWidget <NGUILabel>(go); lbl.font = NGUISettings.font; lbl.text = go.name; lbl.pivot = NGUIWidget.Pivot.Left; lbl.cachedTransform.localPosition = new Vector3(fgPadding.x, 0f, 0f); lbl.MakePixelPerfect(); // Add a collider NGUITools.AddWidgetCollider(go); // Add the popup list NGUIPopupList list = go.AddComponent <NGUIPopupList>(); list.atlas = NGUISettings.atlas; list.font = NGUISettings.font; list.backgroundSprite = mListBG; list.highlightSprite = mListHL; list.padding = hlPadding; if (isDropDown) { list.textLabel = lbl; } for (int i = 0; i < 5; ++i) { list.items.Add(isDropDown ? ("List Option " + i) : ("Menu Option " + i)); } // Add the scripts go.AddComponent <NGUIButton>().tweenTarget = sprite.gameObject; go.AddComponent <NGUIButtonSound>(); Selection.activeGameObject = go; } }
/// <summary> /// Visibly highlight the specified transform by moving the highlight sprite to be over it. /// </summary> void Highlight(NGUILabel lbl, bool instant) { if (mHighlight != null) { // Don't allow highlighting while the label is animating to its intended position TweenPosition tp = lbl.GetComponent<TweenPosition>(); if (tp != null && tp.enabled) return; mHighlightedLabel = lbl; NGUIAtlas.Sprite sp = mHighlight.GetAtlasSprite(); if (sp == null) return; float offsetX = sp.inner.xMin - sp.outer.xMin; float offsetY = sp.inner.yMin - sp.outer.yMin; Vector3 pos = lbl.cachedTransform.localPosition + new Vector3(-offsetX, offsetY, 0f); if (instant || !isAnimated) { mHighlight.cachedTransform.localPosition = pos; } else { TweenPosition.Begin(mHighlight.gameObject, 0.1f, pos).method = NGUITweener.Method.EaseOut; } } }