This script adds the NGUI menu options to the Unity Editor.
示例#1
0
    public static void AddMenuBar()
    {
        GameObject gameObj = NGUIMenu.SelectedRoot();

        if (gameObj != null)
        {
            EditorUtility.SetDirty(gameObj);

            GameObject ctxMenuObj = new GameObject("MenuBar");
            ctxMenuObj.layer = gameObj.layer;

            Transform ct = ctxMenuObj.transform;
            ct.parent        = gameObj.transform;
            ct.localPosition = Vector3.zero;
            ct.localRotation = Quaternion.identity;
            ct.localScale    = Vector3.one;

            CtxMenu ctxMenu = ctxMenuObj.AddComponent <CtxMenu>();
            ctxMenu.menuBar = true;
            ctxMenu.style   = CtxMenu.Style.Horizontal;

            Selection.activeGameObject = ctxMenuObj;

            Undo.RegisterCreatedObjectUndo(ctxMenuObj, "Add a Menu Bar");
        }
    }
示例#2
0
    static public void AddLabel()
    {
        GameObject root = NGUIMenu.SelectedRoot();

        if (NGUIEditorTools.WillLosePrefab(root))
        {
            NGUIEditorTools.RegisterUndo("Add a System Font Label", root);

            GameObject obj = new GameObject("UISystemFontLabel");
            obj.layer            = root.layer;
            obj.transform.parent = root.transform;

            UISystemFontLabel label = obj.AddComponent <UISystemFontLabel>();
            label.MakePixelPerfect();
            label.transform.localPosition = new Vector3(0, 0, -1);
            label.transform.localScale    = new Vector3(1, 1, 1);
            label.text        = "System Font Label";
            label.size        = 16;
            label.lineSpacing = 1;
            label.width       = 500;
            label.height      = 100;

            Selection.activeGameObject = obj;
        }
    }
    static public void AddLabel()
    {
        GameObject go = NGUIMenu.SelectedRoot();

        if (NGUIEditorTools.WillLosePrefab(go))
        {
            NGUIEditorTools.RegisterUndo("Add a SysFont Label", go);

            GameObject child = new GameObject("UISysFontLabel");
            child.layer            = go.layer;
            child.transform.parent = go.transform;

            UISysFontLabel label = child.AddComponent <UISysFontLabel>();
            label.MakePixelPerfect();
            Vector3 pos = label.transform.localPosition;
            pos.z = -1f;
            label.transform.localPosition = pos;
            label.Text = "Hello World";
            Selection.activeGameObject = child;
        }
    }
示例#4
0
    static public void AddLWFObject()
    {
        GameObject root = NGUIMenu.SelectedRoot();

        if (NGUIEditorTools.WillLosePrefab(root))
        {
            NGUIEditorTools.RegisterUndo("Add a LWFObject", root);

            GameObject obj = new GameObject("UILWFObject");
            obj.layer = root.layer;
            Transform transform = obj.transform;
            transform.parent        = root.transform;
            transform.localPosition = Vector3.zero;
            transform.localRotation = Quaternion.identity;
            transform.localScale    = Vector3.one;

            UILWFObject lwfObject = obj.AddComponent <UILWFObject>();
            lwfObject.zRate = 1;

            Selection.activeGameObject = obj;
        }
    }
示例#5
0
    public static void AddMenuButton()
    {
        GameObject rootObj = NGUIMenu.SelectedRoot();

        if (rootObj != null)
        {
            EditorUtility.SetDirty(rootObj);

            // Create a menu object.
            GameObject ctxMenuObj = new GameObject("Button Menu");
            ctxMenuObj.layer = rootObj.layer;

            Transform ct = ctxMenuObj.transform;
            ct.parent        = rootObj.transform;
            ct.localPosition = Vector3.zero;
            ct.localRotation = Quaternion.identity;
            ct.localScale    = Vector3.one;

            CtxMenu menu = ctxMenuObj.AddComponent <CtxMenu>();
            menu.atlas = PickAtlas();
            menu.font  = PickFont();

            // Create button object.
            GameObject ctxButtonObj = new GameObject("Menu Button");
            ctxButtonObj.layer = rootObj.layer;

            ct               = ctxButtonObj.transform;
            ct.parent        = rootObj.transform;
            ct.localPosition = Vector3.zero;
            ct.localRotation = Quaternion.identity;
            ct.localScale    = Vector3.one;

            int depth = NGUITools.CalculateNextDepth(ctxButtonObj);

            // Create child objects.

            UISprite bg = NGUITools.AddSprite(ctxButtonObj, PickAtlas(), "Button");
            bg.name   = "Background";
            bg.depth  = depth;
            bg.width  = 150;
            bg.height = 40;
            bg.MakePixelPerfect();

            UILabel lbl = NGUITools.AddWidget <UILabel>(ctxButtonObj);
            lbl.bitmapFont = PickFont();
            lbl.text       = ctxButtonObj.name;
            lbl.color      = Color.black;
            lbl.MakePixelPerfect();
            Vector2 size = lbl.printedSize;                     // Force NGUI to process metrics before adding collider. Otherwise you get incorrect-sized collider.
            size.x -= 1f;                                       // Supress compiler warning for unused 'size' variable. Sheesh...

            // Attach button and menu components.
            NGUITools.AddWidgetCollider(ctxButtonObj, true);

            CtxMenuButton menuButton = ctxButtonObj.AddComponent <CtxMenuButton>();
            menuButton.contextMenu      = menu;
            menuButton.currentItemLabel = lbl;

            ctxButtonObj.AddComponent <UIButton>().tweenTarget = bg.gameObject;
            ctxButtonObj.AddComponent <UIButtonScale>();
            ctxButtonObj.AddComponent <UIButtonOffset>();
            ctxButtonObj.AddComponent <UIPlaySound>();

            Selection.activeGameObject = ctxButtonObj;

            Undo.RegisterCreatedObjectUndo(ctxButtonObj, "Add a Menu Button");
        }
    }
示例#6
0
    static void AddPanel()
    {
        UIPanelEx panel = NGUISettingsEx.AddPanel(NGUIMenu.SelectedRoot());

        Selection.activeGameObject = (panel == null) ? NGUIEditorTools.SelectedRoot(true) : panel.gameObject;
    }
示例#7
0
 static void AddLoopTitleGrid()
 {
     NGUIMenu.Add <UILoopTitleGrid>();
 }
示例#8
0
 static void AddMikuSprite()
 {
     NGUIMenu.Add <Miku.UI.MikuSprite>();
 }
示例#9
0
    static void AddPolygonBar()
    {
        UIPolygonBar bar = NGUIMenu.Add <UIPolygonBar>();

        bar.ReframeMeshs();
    }