/// <summary> /// Button creation function. /// </summary> void CreateButton(GameObject go) { if (NGUISettings.atlas != null) { NGUIEditorTools.DrawSpriteField("Background", "Sliced Sprite for the background", NGUISettings.atlas, mButton, OnButton, GUILayout.Width(120f)); } if (ShouldCreate(go, NGUISettings.atlas != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Button"; UISprite bg = NGUITools.AddWidget <UISprite>(go); bg.type = UISprite.Type.Sliced; bg.name = "Background"; bg.depth = depth; bg.atlas = NGUISettings.atlas; bg.spriteName = mButton; bg.width = 200; bg.height = 50; bg.MakePixelPerfect(); if (NGUISettings.ambigiousFont != null) { UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.ambigiousFont = NGUISettings.ambigiousFont; lbl.text = go.name; lbl.AssumeNaturalSize(); } // Add a collider NGUITools.AddWidgetCollider(go); // Add the scripts go.AddComponent <UIButton>().tweenTarget = bg.gameObject; go.AddComponent <UIButtonScale>(); go.AddComponent <Coolape.CLUIPlaySound>(); // modify by chenbin Selection.activeGameObject = go; } }
/// <summary> /// Scroll bar template. /// </summary> public static void CreateScrollBar(GameObject go) { if (ShouldCreate(go, NGUISettings.atlas != null)) { int depth = 0; //NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Scroll Bar"; UISprite bg = NGUITools.AddWidget <UISprite>(go); bg.type = UISprite.Type.Sliced; bg.name = "Background"; bg.depth = depth; bg.atlas = NGUISettings.atlas; bg.spriteName = mScrollBG; Vector4 border = bg.border; bg.width = Mathf.RoundToInt(400f + border.x + border.z); bg.height = Mathf.RoundToInt(14f + border.y + border.w); bg.MakePixelPerfect(); UISprite fg = NGUITools.AddWidget <UISprite>(go); fg.type = UISprite.Type.Sliced; fg.name = "Foreground"; fg.atlas = NGUISettings.atlas; fg.spriteName = mScrollFG; UIScrollBar sb = go.AddComponent <UIScrollBar>(); sb.foregroundWidget = fg; sb.backgroundWidget = bg; sb.fillDirection = mFillDir; sb.barSize = 0.3f; sb.value = 0.3f; sb.ForceUpdate(); if (mScrollCL) { NGUITools.AddWidgetCollider(bg.gameObject); NGUITools.AddWidgetCollider(fg.gameObject); } 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"; UISprite bg = NGUITools.AddWidget <UISprite>(go); bg.type = UISprite.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) { 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; } }
static public void AddTexture() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { UITexture tex = NGUITools.AddWidget <UITexture>(go); tex.name = "Texture"; tex.pivot = NGUISettings.pivot; tex.cachedTransform.localScale = new Vector3(100f, 100f, 1f); Selection.activeGameObject = tex.gameObject; // Fixing deprecated Undo.RegisterSceneUndo("Add a Texture"); RebasedUndo.RegisterUndo(tex.gameObject, "Add a Texture"); } else { Debug.Log("You must select a game object first."); } }
public static GameObject CreateUITextureButton_NULL( GameObject panel, string text = null, UIFont font = null, float fontSize = 16 ) { // refer to CreateButton at UICreateWidgetWizard int depth = NGUITools.CalculateNextDepth(panel); var go = NGUITools.AddChild(panel); go.name = "Button"; var bg = NGUITools.AddWidget <UITexture>(go); bg.name = "Background"; bg.depth = depth; if (text != null) { UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.font = 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>(); var ubm = go.AddComponent <UIButtonMessage>(); ubm.target = panel.GetComponentInChildren <xmlTags_html>().gameObject; ubm.functionName = "OnButtonClick"; return(go); }
/// <summary> /// Button creation function. /// </summary> public static void CreateImageButton(GameObject go) { if (ShouldCreate(go, NGUISettings.atlas != null)) { int depth = 0; //NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Image Button"; UISpriteData sp = NGUISettings.atlas.GetSprite(mImage0); UISprite sprite = NGUITools.AddWidget <UISprite>(go); sprite.type = sp.hasBorder ? UISprite.Type.Sliced : UISprite.Type.Simple; 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.ambigiousFont != null) { UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.ambigiousFont = NGUISettings.ambigiousFont; lbl.text = go.name; lbl.AssumeNaturalSize(); } // Add a collider NGUITools.AddWidgetCollider(go); // Add the scripts UIImageButton ib = go.AddComponent <UIImageButton>(); ib.target = sprite; ib.normalSprite = mImage0; ib.hoverSprite = mImage1; ib.pressedSprite = mImage2; ib.disabledSprite = mImage3; go.AddComponent <UIPlaySound>(); Selection.activeGameObject = go; } }
private void CreateSequence(GameObject go) { if (NGUISettings.atlas != null) { if (ShouldCreate(go, true)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "SequenceBar"; var bar = go.AddComponent <UISequenceProgressBar>(); var sprite = NGUITools.AddWidget <UISprite>(go); sprite.type = UISprite.Type.Simple; sprite.name = "sprite"; sprite.depth = depth; sprite.atlas = NGUISettings.atlas; bar.sprite = sprite; } } }
static public void AddTexture() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { //Undo.RegisterSceneUndo("Add a Texture"); Undo.DestroyObjectImmediate(go); Undo.RegisterCreatedObjectUndo(go, "Add a Texture"); UITexture tex = NGUITools.AddWidget <UITexture>(go); tex.name = "Texture"; tex.pivot = NGUISettings.pivot; tex.cachedTransform.localScale = new Vector3(100f, 100f, 1f); Selection.activeGameObject = tex.gameObject; } else { Debug.Log("You must select a game object first."); } }
static public void AddTexture() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { #if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 Undo.RegisterSceneUndo("Add a Texture"); #endif UITexture tex = NGUITools.AddWidget <UITexture>(go); tex.name = "Texture"; tex.pivot = NGUISettings.pivot; tex.width = 100; tex.height = 100; Selection.activeGameObject = tex.gameObject; } else { Debug.Log("You must select a game object first."); } }
static public void AddWidget() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { #if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 Undo.RegisterSceneUndo("Add a Widget"); #endif UIWidget w = NGUITools.AddWidget <UIWidget>(go); w.name = "Widget"; w.pivot = NGUISettings.pivot; w.width = 100; w.height = 100; Selection.activeGameObject = w.gameObject; } else { Debug.Log("You must select a game object first."); } }
/// <summary> /// Convenience method -- add a sprite. /// </summary> static public UISprite AddSprite(GameObject go) { UISprite w = NGUITools.AddWidget <UISprite>(go); w.name = "Sprite"; w.atlas = atlas; w.spriteName = selectedSprite; var sp = w.GetAtlasSprite(); if (sp != null && sp.hasBorder) { w.type = UISprite.Type.Sliced; } w.pivot = pivot; w.width = 100; w.height = 100; w.MakePixelPerfect(); return(w); }
private static UILabel CreateLabel(GameObject parent, string str, UIFont mFont, string color) { int nextDepth = NGUITools.CalculateNextDepth(parent); UILabel lbl = NGUITools.AddWidget <UILabel>(parent); lbl.name = "Label_text"; lbl.depth = nextDepth; lbl.bitmapFont = mFont; lbl.pivot = UILabel.Pivot.TopLeft; lbl.transform.localScale = new Vector3(mFont.defaultSize, mFont.defaultSize, 1f); lbl.MakePixelPerfect(); lbl.supportEncoding = true; lbl.symbolStyle = NGUIText.SymbolStyle.Normal; if (color != null) { lbl.color = ColorManage.GetColor(color); } lbl.text = str; return(lbl); }
/// <summary> /// Create a new entry, reusing an old entry if necessary. /// </summary> Entry Create() { // See if an unused entry can be reused if (mUnused.Count > 0) { Entry ent = mUnused[mUnused.Count - 1]; mUnused.RemoveAt(mUnused.Count - 1); ent.time = Time.realtimeSinceStartup; ent.label.depth = NGUITools.CalculateNextDepth(gameObject); NGUITools.SetActive(ent.label.gameObject, true); ent.offset = 0f; mList.Add(ent); ent.label.ambigiousFont = ambigiousFont; ent.label.fontSize = fontSize; return(ent); } // New entry Entry ne = new Entry(); ne.time = Time.realtimeSinceStartup; ne.label = NGUITools.AddWidget <UILabel>(gameObject); ne.label.name = counter.ToString(); ne.label.ambigiousFont = ambigiousFont; ne.label.fontSize = fontSize; ne.label.fontStyle = fontStyle; ne.label.applyGradient = applyGradient; ne.label.gradientTop = gradientTop; ne.label.gradientBottom = gradienBottom; ne.label.effectStyle = effect; ne.label.effectColor = effectColor; ne.label.overflowMethod = UILabel.Overflow.ResizeFreely; // Make it small so that it's invisible to start with ne.label.cachedTransform.localScale = new Vector3(0.001f, 0.001f, 0.001f); mList.Add(ne); ++counter; return(ne); }
static public void AddLabel() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { Undo.RegisterSceneUndo("Add a Label"); UILabel lbl = NGUITools.AddWidget <UILabel>(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."); } }
static public void AddSprite() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { #if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 Undo.RegisterSceneUndo("Add a Sprite"); #endif UISprite sprite = NGUITools.AddWidget <UISprite>(go); sprite.name = "Sprite"; sprite.atlas = NGUISettings.atlas; if (sprite.atlas != null) { string sn = EditorPrefs.GetString("NGUI Sprite", ""); UISpriteData sp = sprite.atlas.GetSprite(sn); if (sp != null) { sprite.spriteName = sn; if (sp.hasBorder) { sprite.type = UISprite.Type.Sliced; } } } sprite.pivot = NGUISettings.pivot; sprite.width = 100; sprite.height = 100; sprite.MakePixelPerfect(); Selection.activeGameObject = sprite.gameObject; } else { Debug.Log("You must select a game object first."); } }
static public void AddSprite() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { //Undo.RegisterSceneUndo("Add a Sprite"); Undo.DestroyObjectImmediate(go); Undo.RegisterCreatedObjectUndo(go, "Add a Sprite"); UISprite sprite = NGUITools.AddWidget <UISprite>(go); sprite.name = "Sprite"; sprite.atlas = NGUISettings.atlas; if (sprite.atlas != null) { string sn = EditorPrefs.GetString("NGUI Sprite", ""); UIAtlas.Sprite sp = sprite.atlas.GetSprite(sn); if (sp != null) { sprite.spriteName = sn; if (sp.inner != sp.outer) { sprite.type = UISprite.Type.Sliced; } } } sprite.pivot = NGUISettings.pivot; sprite.cachedTransform.localScale = new Vector3(100f, 100f, 1f); sprite.MakePixelPerfect(); Selection.activeGameObject = sprite.gameObject; } else { Debug.Log("You must select a game object first."); } }
/// <summary> /// Convenience method -- add a sprite. /// </summary> static public UISprite AddSprite(GameObject go) { UISprite w = NGUITools.AddWidget <UISprite>(go); w.name = "Sprite"; w.atlas = atlas; w.spriteName = selectedSprite; if (w.atlas != null && !string.IsNullOrEmpty(w.spriteName)) { UISpriteData sp = w.atlas.GetSprite(w.spriteName); if (sp != null && sp.hasBorder) { w.type = UISprite.Type.Sliced; } } w.pivot = pivot; w.width = 100; w.height = 100; w.MakePixelPerfect(); return(w); }
/// <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)) { UILabel lbl = NGUITools.AddWidget<UILabel>(go); lbl.font = NGUISettings.font; lbl.text = "New Label"; lbl.color = mColor; lbl.MakePixelPerfect(); Selection.activeGameObject = lbl.gameObject; } }
/// <summary> /// Sprite creation function. /// </summary> bool CreateSprite <T> (GameObject go, ref string field) where T : UISprite { if (UISettings.atlas != null) { GUILayout.BeginHorizontal(); string sp = UISpriteInspector.SpriteField(UISettings.atlas, "Sprite", field, GUILayout.Width(200f)); if (!string.IsNullOrEmpty(sp)) { GUILayout.Space(20f); GUILayout.Label("Sprite that will be created"); } GUILayout.EndHorizontal(); if (sp != field) { field = sp; Save(); } } if (ShouldCreate(go, UISettings.atlas != null)) { T sprite = NGUITools.AddWidget <T>(go); sprite.name = sprite.name + " (" + field + ")"; sprite.atlas = UISettings.atlas; sprite.spriteName = field; sprite.MakePixelPerfect(); Selection.activeGameObject = sprite.gameObject; return(true); } else { return(false); } }
static public void AddLabel() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { #if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 Undo.RegisterSceneUndo("Add a Label"); #endif UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.name = "Label"; lbl.font = NGUISettings.font; lbl.text = "New Label"; lbl.pivot = NGUISettings.pivot; lbl.width = 120; lbl.height = 30; lbl.MakePixelPerfect(); Selection.activeGameObject = lbl.gameObject; } else { Debug.Log("You must select a game object first."); } }
static public void AddLabel() { GameObject go = NGUIEditorTools.SelectedRoot(true); if (go != null) { #if UNITY_3_5 || UNITY_4_0 || UNITY_4_1 || UNITY_4_2 Undo.RegisterSceneUndo("Add a Label"); #endif TextFxNGUI w = NGUITools.AddWidget <TextFxNGUI>(go); w.name = NEW_INSTANCE_NAME; w.ambigiousFont = NGUISettings.ambigiousFont; w.text = "New Label"; w.pivot = NGUISettings.pivot; w.width = 120; w.height = Mathf.Max(20, NGUISettings.GetInt("NGUI Font Height", 16)); w.fontStyle = NGUISettings.fontStyle; w.fontSize = NGUISettings.fontSize; w.applyGradient = true; w.gradientBottom = new Color(0.7f, 0.7f, 0.7f); w.AssumeNaturalSize(); // return w; if (w.bitmapFont == null && w.trueTypeFont == null) { w.trueTypeFont = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font; } Selection.activeGameObject = w.gameObject; } else { Debug.Log("You must select a game object first."); } }
/// <summary> /// スプライトウィジェットの追加 /// </summary> public static UISprite AddUISprite( GameObject go, Vector3 position, UIAtlas atlas, string spriteName, UISprite.Type spriteType, Color color, UIWidget.Pivot pivot, int depth, Vector2 dimensions ) { // パネルにスプライトを追加 UISprite sprite = NGUITools.AddWidget <UISprite>(go); // ウィジェットの設定 SetUIWidget( sprite, color, pivot, depth, dimensions ); sprite.transform.position = position; sprite.atlas = atlas; sprite.spriteName = spriteName; sprite.type = spriteType; return(sprite); }
/// <summary> /// Button creation function. /// </summary> public static void CreateButton(GameObject go) { if (ShouldCreate(go, NGUISettings.atlas != null)) { int depth = 0; //NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Button"; UISprite bg = NGUITools.AddWidget <UISprite>(go); bg.type = UISprite.Type.Sliced; bg.name = "Background"; bg.depth = depth; bg.atlas = NGUISettings.atlas; bg.spriteName = mButton; bg.width = 200; bg.height = 50; bg.MakePixelPerfect(); if (NGUISettings.ambigiousFont != null) { UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.ambigiousFont = NGUISettings.ambigiousFont; lbl.text = go.name; lbl.AssumeNaturalSize(); } // Add a collider NGUITools.AddWidgetCollider(go); // Add the scripts go.AddComponent <UIButton>().tweenTarget = bg != null ? bg.gameObject : null; go.AddComponent <UIPlaySound>(); Selection.activeGameObject = go; } }
/// <summary> /// Progress bar creation function. /// </summary> void CreateSlider(GameObject go, bool slider) { if (UISettings.atlas != null) { GUILayout.BeginHorizontal(); string bg = UISpriteInspector.SpriteField(UISettings.atlas, "Background", mSliderBG, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Sprite for the background (empty bar)"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); string fg = UISpriteInspector.SpriteField(UISettings.atlas, "Foreground", mSliderFG, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Sprite for the foreground (full bar)"); GUILayout.EndHorizontal(); string tb = mSliderTB; if (slider) { GUILayout.BeginHorizontal(); tb = UISpriteInspector.SpriteField(UISettings.atlas, "Thumb", mSliderTB, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Sprite for the thumb indicator"); GUILayout.EndHorizontal(); } if (mSliderBG != bg || mSliderFG != fg || mSliderTB != tb) { mSliderBG = bg; mSliderFG = fg; mSliderTB = tb; Save(); } } if (ShouldCreate(go, UISettings.atlas != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = slider ? "Slider" : "Progress Bar"; // Background sprite UIAtlas.Sprite bgs = UISettings.atlas.GetSprite(mSliderBG); UISprite back = (bgs.inner == bgs.outer) ? (UISprite)NGUITools.AddWidget <UISprite>(go) : (UISprite)NGUITools.AddWidget <UISlicedSprite>(go); back.name = "Background"; back.depth = depth; back.pivot = UIWidget.Pivot.Left; back.atlas = UISettings.atlas; back.spriteName = mSliderBG; back.transform.localScale = new Vector3(200f, 30f, 1f); back.MakePixelPerfect(); // Fireground sprite UIAtlas.Sprite fgs = UISettings.atlas.GetSprite(mSliderFG); UISprite front = (fgs.inner == fgs.outer) ? (UISprite)NGUITools.AddWidget <UIFilledSprite>(go) : (UISprite)NGUITools.AddWidget <UISlicedSprite>(go); front.name = "Foreground"; front.pivot = UIWidget.Pivot.Left; front.atlas = UISettings.atlas; front.spriteName = mSliderFG; front.transform.localScale = new Vector3(200f, 30f, 1f); front.MakePixelPerfect(); // Add a collider if (slider) { NGUITools.AddWidgetCollider(go); } // Add the slider script UISlider uiSlider = go.AddComponent <UISlider>(); uiSlider.foreground = front.transform; uiSlider.fullSize = front.transform.localScale; // Thumb sprite if (slider) { UIAtlas.Sprite tbs = UISettings.atlas.GetSprite(mSliderTB); UISprite thb = (tbs.inner == tbs.outer) ? (UISprite)NGUITools.AddWidget <UISprite>(go) : (UISprite)NGUITools.AddWidget <UISlicedSprite>(go); thb.name = "Thumb"; thb.atlas = UISettings.atlas; thb.spriteName = mSliderTB; thb.transform.localPosition = new Vector3(200f, 0f, 0f); thb.transform.localScale = new Vector3(20f, 40f, 1f); thb.MakePixelPerfect(); NGUITools.AddWidgetCollider(thb.gameObject); thb.gameObject.AddComponent <UIButtonColor>(); thb.gameObject.AddComponent <UIButtonScale>(); uiSlider.thumb = thb.transform; } uiSlider.sliderValue = 0.75f; // Select the slider Selection.activeGameObject = go; } }
/// <summary> /// Create a popup list or a menu. /// </summary> void CreatePopup(GameObject go, bool isDropDown) { if (UISettings.atlas != null) { GUILayout.BeginHorizontal(); string sprite = UISpriteInspector.SpriteField(UISettings.atlas, "Foreground", mListFG, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Foreground sprite (shown on the button)"); GUILayout.EndHorizontal(); if (mListFG != sprite) { mListFG = sprite; Save(); } GUILayout.BeginHorizontal(); sprite = UISpriteInspector.SpriteField(UISettings.atlas, "Background", mListBG, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Background sprite (envelops the options)"); GUILayout.EndHorizontal(); if (mListBG != sprite) { mListBG = sprite; Save(); } GUILayout.BeginHorizontal(); sprite = UISpriteInspector.SpriteField(UISettings.atlas, "Highlight", mListHL, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Sprite used to highlight the selected option"); GUILayout.EndHorizontal(); if (mListHL != sprite) { mListHL = sprite; Save(); } } if (ShouldCreate(go, UISettings.atlas != null && UISettings.font != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = isDropDown ? "Popup List" : "Popup Menu"; UIAtlas.Sprite sphl = UISettings.atlas.GetSprite(mListHL); UIAtlas.Sprite spfg = UISettings.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 UISprite sprite = NGUITools.AddSprite(go, UISettings.atlas, mListFG); sprite.depth = depth; sprite.atlas = UISettings.atlas; sprite.transform.localScale = new Vector3(150f + fgPadding.x * 2f, UISettings.font.size + fgPadding.y * 2f, 1f); sprite.pivot = UIWidget.Pivot.Left; sprite.MakePixelPerfect(); // Text label UILabel lbl = NGUITools.AddWidget <UILabel>(go); lbl.font = UISettings.font; lbl.text = go.name; lbl.pivot = UIWidget.Pivot.Left; lbl.cachedTransform.localPosition = new Vector3(fgPadding.x, 0f, 0f); lbl.MakePixelPerfect(); // Add a collider NGUITools.AddWidgetCollider(go); // Add the popup list UIPopupList list = go.AddComponent <UIPopupList>(); list.atlas = UISettings.atlas; list.font = UISettings.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 <UIButton>().tweenTarget = sprite.gameObject; go.AddComponent <UIButtonSound>(); Selection.activeGameObject = go; } }
/// <summary> /// Scroll bar template. /// </summary> void CreateScrollBar(GameObject go) { if (UISettings.atlas != null) { GUILayout.BeginHorizontal(); string bg = UISpriteInspector.SpriteField(UISettings.atlas, "Background", mScrollBG, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Sprite for the background"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); string fg = UISpriteInspector.SpriteField(UISettings.atlas, "Foreground", mScrollFG, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Sprite for the foreground (thumb)"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); UIScrollBar.Direction dir = (UIScrollBar.Direction)EditorGUILayout.EnumPopup("Direction", mScrollDir, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Add colliders?", GUILayout.Width(80f)); bool draggable = EditorGUILayout.Toggle(mScrollCL); GUILayout.EndHorizontal(); if (mScrollBG != bg || mScrollFG != fg || mScrollCL != draggable || mScrollDir != dir) { mScrollBG = bg; mScrollFG = fg; mScrollCL = draggable; mScrollDir = dir; Save(); } } if (ShouldCreate(go, UISettings.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 = UISettings.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 = UISettings.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> /// 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> /// Button creation function. /// </summary> void CreateImageButton(GameObject go) { if (UISettings.atlas != null) { GUILayout.BeginHorizontal(); string bg = UISpriteInspector.SpriteField(UISettings.atlas, "Normal", mImage0, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Normal state sprite"); GUILayout.EndHorizontal(); if (mImage0 != bg) { mImage0 = bg; Save(); } GUILayout.BeginHorizontal(); bg = UISpriteInspector.SpriteField(UISettings.atlas, "Hover", mImage1, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Hover state sprite"); GUILayout.EndHorizontal(); if (mImage1 != bg) { mImage1 = bg; Save(); } GUILayout.BeginHorizontal(); bg = UISpriteInspector.SpriteField(UISettings.atlas, "Pressed", mImage2, GUILayout.Width(200f)); GUILayout.Space(20f); GUILayout.Label("Pressed state sprite"); GUILayout.EndHorizontal(); if (mImage2 != bg) { mImage2 = bg; Save(); } } if (ShouldCreate(go, UISettings.atlas != null)) { int depth = NGUITools.CalculateNextDepth(go); go = NGUITools.AddChild(go); go.name = "Image Button"; UIAtlas.Sprite sp = UISettings.atlas.GetSprite(mImage0); UISprite sprite = (sp.inner == sp.outer) ? NGUITools.AddWidget <UISprite>(go) : (UISprite)NGUITools.AddWidget <UISlicedSprite>(go); sprite.name = "Background"; sprite.depth = depth; sprite.atlas = UISettings.atlas; sprite.spriteName = mImage0; sprite.transform.localScale = new Vector3(150f, 40f, 1f); sprite.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 UIImageButton ib = go.AddComponent <UIImageButton>(); ib.target = sprite; ib.normalSprite = mImage0; ib.hoverSprite = mImage1; ib.pressedSprite = mImage2; go.AddComponent <UIButtonSound>(); Selection.activeGameObject = go; } }
/// <summary> /// Display the drop-down list when the game object gets clicked on. /// </summary> void OnClick() { if (enabled && NGUITools.GetActive(gameObject) && mChild == null && atlas != null && isValid && items.Count > 0) { mLabelList.Clear(); // Automatically locate the panel responsible for this object if (mPanel == null) { mPanel = UIPanel.Find(transform); if (mPanel == null) { return; } } // Disable the navigation script handleEvents = 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 = UIWidget.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 = UIWidget.Pivot.TopLeft; mHighlight.color = highlightColor; UISpriteData hlsp = mHighlight.GetAtlasSprite(); if (hlsp == null) { return; } float hlspHeight = hlsp.borderTop; float fontHeight = activeFontSize; float dynScale = activeFontScale; float labelHeight = fontHeight * dynScale; float x = 0f, y = -padding.y; int labelFontSize = (bitmapFont != null) ? bitmapFont.defaultSize : fontSize; List <UILabel> labels = new List <UILabel>(); // Run through all items and create labels for each one for (int i = 0, imax = items.Count; i < imax; ++i) { string s = items[i]; UILabel lbl = NGUITools.AddWidget <UILabel>(mChild); lbl.pivot = UIWidget.Pivot.TopLeft; lbl.bitmapFont = bitmapFont; lbl.trueTypeFont = trueTypeFont; lbl.fontSize = labelFontSize; lbl.fontStyle = fontStyle; lbl.text = isLocalized ? Localization.Get(s) : s; lbl.color = textColor; lbl.cachedTransform.localPosition = new Vector3(bgPadding.x + padding.x, y, -1f); lbl.overflowMethod = UILabel.Overflow.ResizeFreely; lbl.MakePixelPerfect(); if (dynScale != 1f) { lbl.cachedTransform.localScale = Vector3.one * dynScale; } labels.Add(lbl); y -= labelHeight; y -= padding.y; x = Mathf.Max(x, lbl.printedSize.x); // Add an event listener UIEventListener listener = UIEventListener.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 || (i == 0 && string.IsNullOrEmpty(mSelectedItem))) { 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 * dynScale - (bgPadding.x + padding.x) * 2f); float cx = x / dynScale; Vector3 bcCenter = new Vector3(cx * 0.5f, -fontHeight * 0.5f, 0f); Vector3 bcSize = new Vector3(cx, (labelHeight + padding.y) / dynScale, 1f); // Run through all labels and add colliders for (int i = 0, imax = labels.Count; i < imax; ++i) { UILabel 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.width = Mathf.RoundToInt(x); mBackground.height = Mathf.RoundToInt(-y + bgPadding.y); // Scale the highlight sprite to envelop a single item float scaleFactor = 2f * atlas.pixelSize; float w = x - (bgPadding.x + padding.x) * 2f + hlsp.borderLeft * scaleFactor; float h = labelHeight + hlspHeight * scaleFactor; mHighlight.width = Mathf.RoundToInt(w); mHighlight.height = Mathf.RoundToInt(h); bool placeAbove = (position == Position.Above); if (position == Position.Auto) { UICamera cam = UICamera.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 + labelHeight; 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); } }
// Token: 0x060000F5 RID: 245 RVA: 0x0001A4AC File Offset: 0x000186AC private void OnClick() { if (this.mChild == null && this.atlas != null && this.font != null && this.items.Count > 0) { this.mLabelList.Clear(); this.handleEvents = true; if (this.mPanel == null) { this.mPanel = UIPanel.Find(base.transform, true); } Transform transform = base.transform; Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(transform.parent, transform); this.mChild = new GameObject("Drop-down List"); this.mChild.layer = base.gameObject.layer; Transform transform2 = this.mChild.transform; transform2.parent = transform.parent; transform2.localPosition = bounds.min; transform2.localRotation = Quaternion.identity; transform2.localScale = Vector3.one; this.mBackground = NGUITools.AddSprite(this.mChild, this.atlas, this.backgroundSprite); this.mBackground.pivot = UIWidget.Pivot.TopLeft; this.mBackground.depth = NGUITools.CalculateNextDepth(this.mPanel.gameObject); this.mBackground.color = this.backgroundColor; Vector4 border = this.mBackground.border; this.mBgBorder = border.y; this.mBackground.cachedTransform.localPosition = new Vector3(0f, border.y, 0f); this.mHighlight = NGUITools.AddSprite(this.mChild, this.atlas, this.highlightSprite); this.mHighlight.pivot = UIWidget.Pivot.TopLeft; this.mHighlight.color = this.highlightColor; UIAtlas.Sprite atlasSprite = this.mHighlight.GetAtlasSprite(); if (atlasSprite == null) { return; } float num = atlasSprite.inner.yMin - atlasSprite.outer.yMin; float num2 = (float)this.font.size * this.font.pixelSize * this.textScale; float num3 = 0f; float num4 = -this.padding.y; List <UILabel> list = new List <UILabel>(); int i = 0; int count = this.items.Count; while (i < count) { string text = this.items[i]; UILabel uilabel = NGUITools.AddWidget <UILabel>(this.mChild); uilabel.pivot = UIWidget.Pivot.TopLeft; uilabel.font = this.font; uilabel.text = ((!this.isLocalized || !(Localization.instance != null)) ? text : Localization.instance.Get(text)); uilabel.color = this.textColor; uilabel.cachedTransform.localPosition = new Vector3(border.x + this.padding.x, num4, -1f); uilabel.MakePixelPerfect(); if (this.textScale != 1f) { Vector3 localScale = uilabel.cachedTransform.localScale; uilabel.cachedTransform.localScale = localScale * this.textScale; } list.Add(uilabel); num4 -= num2; num4 -= this.padding.y; num3 = Mathf.Max(num3, uilabel.relativeSize.x * num2); UIEventListener uieventListener = UIEventListener.Get(uilabel.gameObject); uieventListener.onHover = new UIEventListener.BoolDelegate(this.OnItemHover); uieventListener.onPress = new UIEventListener.BoolDelegate(this.OnItemPress); uieventListener.parameter = text; if (this.mSelectedItem == text) { this.Highlight(uilabel, true); } this.mLabelList.Add(uilabel); i++; } num3 = Mathf.Max(num3, bounds.size.x - (border.x + this.padding.x) * 2f); Vector3 center = new Vector3(num3 * 0.5f / num2, -0.5f, 0f); Vector3 size = new Vector3(num3 / num2, (num2 + this.padding.y) / num2, 1f); int j = 0; int count2 = list.Count; while (j < count2) { UILabel uilabel2 = list[j]; BoxCollider boxCollider = NGUITools.AddWidgetCollider(uilabel2.gameObject); center.z = boxCollider.center.z; boxCollider.center = center; boxCollider.size = size; j++; } num3 += (border.x + this.padding.x) * 2f; num4 -= border.y; this.mBackground.cachedTransform.localScale = new Vector3(num3, -num4 + border.y, 1f); this.mHighlight.cachedTransform.localScale = new Vector3(num3 - (border.x + this.padding.x) * 2f + (atlasSprite.inner.xMin - atlasSprite.outer.xMin) * 2f, num2 + num * 2f, 1f); bool flag = this.position == UIPopupList.Position.Above; if (this.position == UIPopupList.Position.Auto) { UICamera uicamera = UICamera.FindCameraForLayer(base.gameObject.layer); if (uicamera != null) { flag = (uicamera.cachedCamera.WorldToViewportPoint(transform.position).y < 0.5f); } } if (this.isAnimated) { float bottom = num4 + num2; this.Animate(this.mHighlight, flag, bottom); int k = 0; int count3 = list.Count; while (k < count3) { this.Animate(list[k], flag, bottom); k++; } this.AnimateColor(this.mBackground); this.AnimateScale(this.mBackground, flag, bottom); } if (flag) { transform2.localPosition = new Vector3(bounds.min.x, bounds.max.y - num4 - border.y, bounds.min.z); } } else { this.OnSelect(false); } }