/// <summary> /// Scroll bar template. /// </summary> void CreateScrollBar(GameObject go) { if (NGUISettings.atlas != null) { NGUIEditorTools.SpriteField("Background", "Sprite used for the background", NGUISettings.atlas, mScrollBG, OnScrollBG); NGUIEditorTools.SpriteField("Foreground", "Sprite used for the foreground (thumb)", NGUISettings.atlas, mScrollFG, OnScrollFG); GUILayout.BeginHorizontal(); NGUIScrollBar.Direction dir = (NGUIScrollBar.Direction)EditorGUILayout.EnumPopup("Direction", mScrollDir, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Add colliders?", GUILayout.Width(90f)); bool draggable = EditorGUILayout.Toggle(mScrollCL); GUILayout.EndHorizontal(); if (mScrollCL != draggable || mScrollDir != dir) { mScrollCL = draggable; mScrollDir = dir; Save(); } } if (ShouldCreate(go, NGUISettings.atlas != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Scroll Bar"; NGUISprite bg = NGUITools.AddWidget <NGUISprite>(go); bg.type = NGUISprite.Type.Sliced; bg.name = "Background"; bg.depth = depth; bg.atlas = NGUISettings.atlas; bg.spriteName = mScrollBG; bg.transform.localScale = new Vector3(400f + bg.border.x + bg.border.z, 14f + bg.border.y + bg.border.w, 1f); bg.MakePixelPerfect(); NGUISprite fg = NGUITools.AddWidget <NGUISprite>(go); fg.type = NGUISprite.Type.Sliced; fg.name = "Foreground"; fg.atlas = NGUISettings.atlas; fg.spriteName = mScrollFG; NGUIScrollBar sb = go.AddComponent <NGUIScrollBar>(); sb.background = bg; sb.foreground = fg; sb.direction = mScrollDir; sb.barSize = 0.3f; sb.scrollValue = 0.3f; sb.ForceUpdate(); if (mScrollCL) { NGUITools.AddWidgetCollider(bg.gameObject); NGUITools.AddWidgetCollider(fg.gameObject); } Selection.activeGameObject = go; } }
/// <summary> /// Triggered by the vertical scroll bar when it changes. /// </summary> void OnVerticalBar(NGUIScrollBar sb) { if (!mIgnoreCallbacks) { float x = (horizontalScrollBar != null) ? horizontalScrollBar.scrollValue : 0f; float y = (verticalScrollBar != null) ? verticalScrollBar.scrollValue : 0f; SetDragAmount(x, y, false); } }
public override void OnInspectorGUI() { EditorGUIUtility.LookLikeControls(80f); NGUIScrollBar sb = target as NGUIScrollBar; NGUIEditorTools.DrawSeparator(); float val = EditorGUILayout.Slider("Value", sb.scrollValue, 0f, 1f); float size = EditorGUILayout.Slider("Size", sb.barSize, 0f, 1f); float alpha = EditorGUILayout.Slider("Alpha", sb.alpha, 0f, 1f); NGUIEditorTools.DrawSeparator(); NGUISprite bg = (NGUISprite)EditorGUILayout.ObjectField("Background", sb.background, typeof(NGUISprite), true); NGUISprite fg = (NGUISprite)EditorGUILayout.ObjectField("Foreground", sb.foreground, typeof(NGUISprite), true); NGUIScrollBar.Direction dir = (NGUIScrollBar.Direction)EditorGUILayout.EnumPopup("Direction", sb.direction); bool inv = EditorGUILayout.Toggle("Inverted", sb.inverted); if (sb.scrollValue != val || sb.barSize != size || sb.background != bg || sb.foreground != fg || sb.direction != dir || sb.inverted != inv || sb.alpha != alpha) { NGUIEditorTools.RegisterUndo("Scroll Bar Change", sb); sb.scrollValue = val; sb.barSize = size; sb.inverted = inv; sb.background = bg; sb.foreground = fg; sb.direction = dir; sb.alpha = alpha; UnityEditor.EditorUtility.SetDirty(sb); } }