void Start() { mList = GetComponent <NGUIPopupList>(); UpdateList(); mList.eventReceiver = gameObject; mList.functionName = "OnLanguageSelection"; }
/// <summary> /// Cache the components and register a listener callback. /// </summary> void Awake() { mList = GetComponent<NGUIPopupList>(); mCheck = GetComponent<NGUICheckbox>(); if (mList != null) mList.onSelectionChange += SaveSelection; if (mCheck != null) mCheck.onStateChange += SaveState; }
void Start() { mList = GetComponent<NGUIPopupList>(); UpdateList(); mList.eventReceiver = gameObject; mList.functionName = "OnLanguageSelection"; }
/// <summary> /// Cache the components and register a listener callback. /// </summary> void Awake() { mList = GetComponent <NGUIPopupList>(); mCheck = GetComponent <NGUICheckbox>(); if (mList != null) { mList.onSelectionChange += SaveSelection; } if (mCheck != null) { mCheck.onStateChange += SaveState; } }
/// <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; } }
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; } } }
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; } } }