/// <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(); UIScrollBar.Direction dir = (UIScrollBar.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"; UISlicedSprite bg = NGUITools.AddWidget <UISlicedSprite>(go); 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(); UISlicedSprite fg = NGUITools.AddWidget <UISlicedSprite>(go); fg.name = "Foreground"; fg.atlas = NGUISettings.atlas; fg.spriteName = mScrollFG; UIScrollBar sb = go.AddComponent <UIScrollBar>(); 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> /// Input field creation function. /// </summary> void CreateInput(GameObject go) { if (UISettings.atlas != null) { GUILayout.BeginHorizontal(); string bg = UISpriteInspector.SpriteField(UISettings.atlas, "Background", mInputBG, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Sliced Sprite for the background"); GUILayout.EndHorizontal(); if (mInputBG != bg) { mInputBG = bg; Save(); } } if (ShouldCreate(go, UISettings.atlas != null && UISettings.font != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Input"; float padding = 3f; UISlicedSprite bg = NGUITools.AddWidget <UISlicedSprite>(go); bg.name = "Background"; bg.depth = depth; bg.atlas = UISettings.atlas; bg.spriteName = mInputBG; bg.pivot = UIWidget.Pivot.Left; bg.transform.localScale = new Vector3(400f, UISettings.font.size + padding * 2f, 1f); bg.MakePixelPerfect(); UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.font = UISettings.font; lbl.pivot = UIWidget.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 UIInput input = go.AddComponent <UIInput>(); input.label = lbl; // Update the selection Selection.activeGameObject = go; } }
void CreateInput(GameObject go) { if (UISettings.atlas != null) { //GUILayout.BeginHorizontal(); //string bg = UISpriteInspector.SpriteField(UISettings.atlas, "Background", mInputBG, GUILayout.Width(200f)); //GUILayout.Space(20f); //GUILayout.Label("Sliced Sprite for the background"); //GUILayout.EndHorizontal(); NGUIEditorTools.DrawSpriteField("Background", "Normal state sprite", NGUISettings.atlas, mInputBG, OnInputBG, GUILayout.Width(120f)); } if (ShouldCreate(go, UISettings.atlas != null && UISettings.font != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Input"; float padding = 3f; UISlicedSprite bg = NGUITools.AddWidget <UISlicedSprite>(go); bg.name = "Background"; bg.depth = depth; bg.atlas = UISettings.atlas; bg.spriteName = mInputBG; bg.pivot = UIWidget.Pivot.Left; //bg.transform.localScale = new Vector3(400f, UISettings.FontSize + padding * 2f, 1f); //bg.height = 52; bg.Dimensions = new Vector2(400f, 52f); bg.MakePixelPerfect(); UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.font = UISettings.font; lbl.pivot = UIWidget.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 = ""; lbl.Dimensions = new Vector2(24f, 24f); lbl.MakePixelPerfect(); // Add a collider to the background NGUITools.AddWidgetCollider(bg.gameObject); // Add an input script to the background and have it point to the label UIInput input = bg.gameObject.AddComponent <UIInput>(); input.label = lbl; // Update the selection Selection.activeGameObject = go; } }
/// <summary> /// Button creation function. /// </summary> void CreateButton(GameObject go) { if (UISettings.atlas != null) { //GUILayout.BeginHorizontal(); //string bg = UISpriteInspector.SpriteField(UISettings.atlas, "Background", mButton, GUILayout.Width(200f)); //GUILayout.Space(20f); //GUILayout.Label("Sliced Sprite for the background"); //GUILayout.EndHorizontal(); //if (mButton != bg) { mButton = bg; Save(); } NGUIEditorTools.DrawSpriteField("Background", "Sliced Sprite for the background", NGUISettings.atlas, mButton, OnButton, GUILayout.Width(120f)); } if (ShouldCreate(go, UISettings.atlas != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Button"; UISlicedSprite bg = NGUITools.AddWidget <UISlicedSprite>(go); bg.name = "Background"; bg.depth = depth; bg.atlas = UISettings.atlas; bg.spriteName = mButton; //Texture2D tex = bg.mainTexture as Texture2D; //bg.transform.localScale = new Vector3(Mathf.RoundToInt(Mathf.Abs(bg.outerUV.width * tex.width)), // Mathf.RoundToInt(Mathf.Abs(bg.outerUV.height * tex.height)), // 1f); bg.Dimensions = new Vector2(144f, 54f); bg.MakePixelPerfect(); if (UISettings.font != null) { UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.font = UISettings.font; lbl.text = go.name; lbl.Dimensions = new Vector2(24f, 24f); lbl.MakePixelPerfect(); } // Add a collider NGUITools.AddWidgetCollider(go); // Add the scripts go.AddComponent <UIButtonColor>().tweenTarget = bg.gameObject; go.AddComponent <UIButtonScale>(); go.AddComponent <UIButtonOffset>(); go.AddComponent <UIButtonSound>(); Selection.activeGameObject = go; } }
/// <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"; UISlicedSprite bg = NGUITools.AddWidget <UISlicedSprite>(go); bg.name = "Background"; bg.depth = depth; bg.atlas = NGUISettings.atlas; bg.spriteName = mCheckBG; bg.transform.localScale = new Vector3(26f, 26f, 1f); bg.MakePixelPerfect(); UISprite fg = NGUITools.AddWidget <UISprite>(go); fg.name = "Checkmark"; fg.atlas = NGUISettings.atlas; fg.spriteName = mCheck; fg.MakePixelPerfect(); if (NGUISettings.font != null) { UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.font = NGUISettings.font; lbl.text = go.name; lbl.pivot = UIWidget.Pivot.Left; lbl.transform.localPosition = new Vector3(16f, 0f, 0f); lbl.MakePixelPerfect(); } // Add a collider NGUITools.AddWidgetCollider(go); // Add the scripts go.AddComponent <UICheckbox>().checkSprite = fg; go.AddComponent <UIButton>().tweenTarget = bg.gameObject; go.AddComponent <UIButtonScale>().tweenTarget = bg.transform; go.AddComponent <UIButtonSound>(); Selection.activeGameObject = go; } }
/// <summary> /// Button creation function. /// </summary> void CreateButton(GameObject go) { if (UISettings.atlas != null) { GUILayout.BeginHorizontal(); string bg = UISpriteInspector.SpriteField(UISettings.atlas, "Background", mButton, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Sliced Sprite for the background"); GUILayout.EndHorizontal(); if (mButton != bg) { mButton = bg; Save(); } } if (ShouldCreate(go, UISettings.atlas != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Button"; UISlicedSprite bg = NGUITools.AddWidget <UISlicedSprite>(go); bg.name = "Background"; bg.depth = depth; bg.atlas = UISettings.atlas; bg.spriteName = mButton; bg.transform.localScale = new Vector3(150f, 40f, 1f); bg.MakePixelPerfect(); if (UISettings.font != null) { UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.font = UISettings.font; lbl.text = go.name; lbl.MakePixelPerfect(); } // Add a collider NGUITools.AddWidgetCollider(go); // Add the scripts go.AddComponent <UIButton>().tweenTarget = bg.gameObject; go.AddComponent <UIButtonScale>(); go.AddComponent <UIButtonOffset>(); go.AddComponent <UIButtonSound>(); Selection.activeGameObject = go; } }
public static UISlicedSprite CreateSlicedSprite(GameObject parent, UIAtlas atlas, string spriteName) { int depth = NGUITools.CalculateNextDepth(parent); UISlicedSprite bg = NGUITools.AddWidget <UISlicedSprite>(parent); bg.name = "Background"; bg.depth = depth; bg.atlas = atlas; bg.spriteName = spriteName; Texture2D tex = bg.mainTexture as Texture2D; bg.transform.localScale = new Vector3(Mathf.RoundToInt(Mathf.Abs(bg.outerUV.width * tex.width)), Mathf.RoundToInt(Mathf.Abs(bg.outerUV.height * tex.height)), 1f); bg.MakePixelPerfect(); return(bg); }
/// <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"; UISlicedSprite bg = NGUITools.AddWidget <UISlicedSprite>(go); 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) { UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.font = NGUISettings.font; lbl.text = go.name; lbl.MakePixelPerfect(); } // Add a collider NGUITools.AddWidgetCollider(go); // Add the scripts go.AddComponent <UIButton>().tweenTarget = bg.gameObject; go.AddComponent <UIButtonScale>(); go.AddComponent <UIButtonOffset>(); go.AddComponent <UIButtonSound>(); Selection.activeGameObject = go; } }
/// <summary> /// Checkbox creation function. /// </summary> void CreateCheckbox(GameObject go) { if (UISettings.atlas != null) { GUILayout.BeginHorizontal(); string bg = UISpriteInspector.SpriteField(UISettings.atlas, "Background", mCheckBG, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Sliced Sprite for the background"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); string ck = UISpriteInspector.SpriteField(UISettings.atlas, "Checkmark", mCheck, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Sprite visible when the state is 'checked'"); GUILayout.EndHorizontal(); if (mCheckBG != bg || mCheck != ck) { mCheckBG = bg; mCheck = ck; Save(); } } if (ShouldCreate(go, UISettings.atlas != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Checkbox"; UISlicedSprite bg = NGUITools.AddWidget <UISlicedSprite>(go); bg.name = "Background"; bg.depth = depth; bg.atlas = UISettings.atlas; bg.spriteName = mCheckBG; bg.transform.localScale = new Vector3(26f, 26f, 1f); bg.MakePixelPerfect(); UISprite fg = NGUITools.AddWidget <UISprite>(go); fg.name = "Checkmark"; fg.atlas = UISettings.atlas; fg.spriteName = mCheck; fg.MakePixelPerfect(); if (UISettings.font != null) { UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.font = UISettings.font; lbl.text = go.name; lbl.pivot = UIWidget.Pivot.Left; lbl.transform.localPosition = new Vector3(16f, 0f, 0f); lbl.MakePixelPerfect(); } // Add a collider NGUITools.AddWidgetCollider(go); // Add the scripts go.AddComponent <UICheckbox>().checkSprite = fg; go.AddComponent <UIButton>().tweenTarget = bg.gameObject; go.AddComponent <UIButtonScale>().tweenTarget = bg.transform; go.AddComponent <UIButtonSound>(); Selection.activeGameObject = go; } }
/// <summary> /// Checkbox creation function. /// </summary> void CreateCheckbox(GameObject go) { if (UISettings.atlas != null) { NGUIEditorTools.DrawSpriteField("Background", "Sliced Sprite for the background", UISettings.atlas, mCheckBG, (name) => { if (name != mCheckBG) { mCheckBG = name; Save(); Repaint(); } }, GUILayout.Width(120f)); NGUIEditorTools.DrawSpriteField("Checkmark", "Sprite visible when the state is 'checked'", UISettings.atlas, mCheck, (name) => { if (name != mCheck) { mCheck = name; Save(); Repaint(); } }, GUILayout.Width(120f)); } if (ShouldCreate(go, UISettings.atlas != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Checkbox"; UISlicedSprite bg = NGUITools.AddWidget <UISlicedSprite>(go); bg.name = "Background"; bg.depth = depth; bg.atlas = UISettings.atlas; bg.spriteName = mCheckBG; //bg.transform.localScale = new Vector3(26f, 26f, 1f); bg.Dimensions = new Vector2(26f, 26f); bg.MakePixelPerfect(); UISprite fg = NGUITools.AddWidget <UISprite>(go); fg.name = "Checkmark"; fg.atlas = UISettings.atlas; fg.spriteName = mCheck; fg.Dimensions = new Vector2(32f, 32f); fg.MakePixelPerfect(); if (UISettings.font != null) { UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.font = UISettings.font; lbl.text = go.name; lbl.pivot = UIWidget.Pivot.Left; lbl.transform.localPosition = new Vector3(16f, 0f, 0f); lbl.Dimensions = new Vector2(24f, 24f); lbl.MakePixelPerfect(); } // Add a collider NGUITools.AddWidgetCollider(go); // Add the scripts go.AddComponent <UICheckbox>().checkSprite = fg; go.AddComponent <UIButtonColor>().tweenTarget = bg.gameObject; go.AddComponent <UIButtonScale>().tweenTarget = bg.transform; go.AddComponent <UIButtonSound>(); Selection.activeGameObject = go; } }
void CreateMogoTwoStatusButton(GameObject go) { if (NGUISettings.atlas != null) { NGUIEditorTools.SpriteField("BGDown", "BGDown", NGUISettings.atlas, mMogoTwoStatusButtonBGDown, OnBGDown); NGUIEditorTools.SpriteField("BGUp", "BGUp", NGUISettings.atlas, mMogoTwoStatusButtonBGUp, OnBGUp); //GUILayout.Space(20f); //GUILayout.Label("MogoTwoStatusButton background down"); //GUILayout.EndHorizontal(); //GUILayout.BeginHorizontal(); //string bgUp = NGUIEditorTools.SpriteField(NGUISettings.atlas, "BGUp", // mMogoTwoStatusButtonBGUp,GUILayout.Width(200f)); //GUILayout.Space(20f); //GUILayout.Label("MogoTwoStatusButton background up"); //GUILayout.EndHorizontal(); //if (mMogoTwoStatusButtonBGDown != bgDown) //{ // mMogoTwoStatusButtonBGDown = bgDown; // Save(); //} //if (mMogoTwoStatusButtonBGUp != bgUp) //{ // mMogoTwoStatusButtonBGUp = bgUp; // Save(); //} } if (ShouldCreate(go, NGUISettings.atlas != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "MogoTwoStatusButton"; UISlicedSprite bgUp = NGUITools.AddWidget <UISlicedSprite>(go); bgUp.name = "MogoTwoStatusButtonBGUp"; bgUp.depth = depth; bgUp.atlas = NGUISettings.atlas; bgUp.spriteName = mMogoTwoStatusButtonBGUp; bgUp.MakePixelPerfect(); UISlicedSprite bgDown = NGUITools.AddWidget <UISlicedSprite>(go); bgDown.name = "MogoTwoStatusButtonBGDown"; bgDown.atlas = NGUISettings.atlas; bgDown.spriteName = mMogoTwoStatusButtonBGDown; bgDown.MakePixelPerfect(); if (NGUISettings.font != null) { depth = NGUITools.CalculateNextDepth(go); UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.name = "MogoTwoStatusButtonText"; lbl.font = NGUISettings.font; lbl.text = "Text"; lbl.MakePixelPerfect(); } NGUITools.AddWidgetCollider(go); go.AddComponent <MogoTwoStatusButton>(); bgDown.gameObject.SetActive(false); Selection.activeGameObject = go; } }