Exemplo n.º 1
0
    /// <summary>
    /// Add commonly NGUI context menu options.
    /// </summary>

    static public void AddCommonItems(GameObject target)
    {
        if (target != null)
        {
            UIWidget widget = target.GetComponent <UIWidget>();

            string myName = string.Format("Selected {0}", (widget != null) ? NGUITools.GetTypeName(widget) : "Object");

            AddItem(myName + "/Bring to Front", false,
                    delegate(object obj) { NGUITools.BringForward(Selection.activeGameObject); }, null);

            AddItem(myName + "/Push to Back", false,
                    delegate(object obj) { NGUITools.PushBack(Selection.activeGameObject); }, null);

            AddItem(myName + "/Nudge Forward", false,
                    delegate(object obj) { NGUITools.AdjustDepth(Selection.activeGameObject, 1); }, null);

            AddItem(myName + "/Nudge Back", false,
                    delegate(object obj) { NGUITools.AdjustDepth(Selection.activeGameObject, -1); }, null);

            if (widget != null)
            {
                NGUIContextMenu.AddSeparator(myName + "/");

                AddItem(myName + "/Make Pixel-Perfect", false, OnMakePixelPerfect, Selection.activeTransform);

                if (target.GetComponent <BoxCollider>() != null)
                {
                    AddItem(myName + "/Reset Collider Size", false, OnBoxCollider, target);
                }
            }

            NGUIContextMenu.AddSeparator(myName + "/");
            AddItem(myName + "/Delete", false, OnDelete, target);
            NGUIContextMenu.AddSeparator("");

            if (Selection.activeTransform.parent != null && widget != null)
            {
                AddChildWidget("Create/Sprite/Child", false, NGUISettings.AddSprite);
                AddChildWidget("Create/Label/Child", false, NGUISettings.AddLabel);
                AddChildWidget("Create/Invisible Widget/Child", false, NGUISettings.AddWidget);
                AddChildWidget("Create/Simple Texture/Child", false, NGUISettings.AddTexture);
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
                AddChildWidget("Create/Unity 2D Sprite/Child", false, NGUISettings.Add2DSprite);
#endif
                AddSiblingWidget("Create/Sprite/Sibling", false, NGUISettings.AddSprite);
                AddSiblingWidget("Create/Label/Sibling", false, NGUISettings.AddLabel);
                AddSiblingWidget("Create/Invisible Widget/Sibling", false, NGUISettings.AddWidget);
                AddSiblingWidget("Create/Simple Texture/Sibling", false, NGUISettings.AddTexture);
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
                AddSiblingWidget("Create/Unity 2D Sprite/Sibling", false, NGUISettings.Add2DSprite);
#endif
            }
            else
            {
                AddChildWidget("Create/Sprite", false, NGUISettings.AddSprite);
                AddChildWidget("Create/Label", false, NGUISettings.AddLabel);
                AddChildWidget("Create/Invisible Widget", false, NGUISettings.AddWidget);
                AddChildWidget("Create/Simple Texture", false, NGUISettings.AddTexture);
#if !UNITY_3_5 && !UNITY_4_0 && !UNITY_4_1 && !UNITY_4_2
                AddChildWidget("Create/Unity 2D Sprite", false, NGUISettings.Add2DSprite);
#endif
            }

            NGUIContextMenu.AddSeparator("Create/");

            AddItem("Create/Panel", false, AddPanel, target);
            AddItem("Create/Scroll View", false, AddScrollView, target);
            AddItem("Create/Grid", false, AddChild <UIGrid>, target);
            AddItem("Create/Table", false, AddChild <UITable>, target);
            AddItem("Create/Anchor (Legacy)", false, AddChild <UIAnchor>, target);

            if (target.GetComponent <UIPanel>() != null)
            {
                if (target.GetComponent <UIScrollView>() == null)
                {
                    AddItem("Attach/Scroll View", false, delegate(object obj) { target.AddComponent <UIScrollView>(); }, null);
                    NGUIContextMenu.AddSeparator("Attach/");
                }
            }
            else if (target.collider == null)
            {
                AddItem("Attach/Box Collider", false, delegate(object obj) { NGUITools.AddWidgetCollider(target); }, null);
                NGUIContextMenu.AddSeparator("Attach/");
            }

            if (target.collider != null)
            {
                if (target.GetComponent <UIDragScrollView>() == null)
                {
                    for (int i = 0; i < UIPanel.list.size; ++i)
                    {
                        UIPanel pan = UIPanel.list[i];
                        if (pan.clipping == UIDrawCall.Clipping.None)
                        {
                            continue;
                        }

                        UIScrollView dr = pan.GetComponent <UIScrollView>();
                        if (dr == null)
                        {
                            continue;
                        }

                        AddItem("Attach/Drag Scroll View", false, delegate(object obj)
                                { target.AddComponent <UIDragScrollView>().scrollView = dr; }, null);

                        NGUIContextMenu.AddSeparator("Attach/");
                        break;
                    }
                }

                AddItem("Attach/Button Script", false, delegate(object obj) { target.AddComponent <UIButton>(); }, null);
                AddItem("Attach/Toggle Script", false, delegate(object obj) { target.AddComponent <UIToggle>(); }, null);
                AddItem("Attach/Slider Script", false, delegate(object obj) { target.AddComponent <UISlider>(); }, null);
                AddItem("Attach/Scroll Bar Script", false, delegate(object obj) { target.AddComponent <UIScrollBar>(); }, null);
                AddItem("Attach/Progress Bar Script", false, delegate(object obj) { target.AddComponent <UISlider>(); }, null);
                AddItem("Attach/Popup List Script", false, delegate(object obj) { target.AddComponent <UIPopupList>(); }, null);
                AddItem("Attach/Input Field Script", false, delegate(object obj) { target.AddComponent <UIInput>(); }, null);
                NGUIContextMenu.AddSeparator("Attach/");
                if (target.GetComponent <UIAnchor>() == null)
                {
                    AddItem("Attach/Anchor Script", false, delegate(object obj) { target.AddComponent <UIAnchor>(); }, null);
                }
                if (target.GetComponent <UIStretch>() == null)
                {
                    AddItem("Attach/Stretch Script", false, delegate(object obj) { target.AddComponent <UIStretch>(); }, null);
                }
                AddItem("Attach/Key Binding Script", false, delegate(object obj) { target.AddComponent <UIKeyBinding>(); }, null);

                NGUIContextMenu.AddSeparator("Attach/");

                AddItem("Attach/Play Tween Script", false, delegate(object obj) { target.AddComponent <UIPlayTween>(); }, null);
                AddItem("Attach/Play Animation Script", false, delegate(object obj) { target.AddComponent <UIPlayAnimation>(); }, null);
                AddItem("Attach/Play Sound Script", false, delegate(object obj) { target.AddComponent <UIPlaySound>(); }, null);
            }

            if (widget != null)
            {
                AddMissingItem <TweenAlpha>(target, "Tween/Alpha");
                AddMissingItem <TweenColor>(target, "Tween/Color");
                AddMissingItem <TweenWidth>(target, "Tween/Width");
                AddMissingItem <TweenHeight>(target, "Tween/Height");
            }
            else if (target.GetComponent <UIPanel>() != null)
            {
                AddMissingItem <TweenAlpha>(target, "Tween/Alpha");
            }

            NGUIContextMenu.AddSeparator("Tween/");

            AddMissingItem <TweenPosition>(target, "Tween/Position");
            AddMissingItem <TweenRotation>(target, "Tween/Rotation");
            AddMissingItem <TweenScale>(target, "Tween/Scale");
            AddMissingItem <TweenTransform>(target, "Tween/Transform");

            if (target.GetComponent <AudioSource>() != null)
            {
                AddMissingItem <TweenVolume>(target, "Tween/Volume");
            }

            if (target.GetComponent <Camera>() != null)
            {
                AddMissingItem <TweenFOV>(target, "Tween/Field of View");
                AddMissingItem <TweenOrthoSize>(target, "Tween/Orthographic Size");
            }
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Add commonly NGUI context menu options.
    /// </summary>

    static public void AddCommonItems(GameObject target)
    {
        if (target != null)
        {
            UIWidget widget = target.GetComponent <UIWidget>();

            string myName = string.Format("Selected {0}", (widget != null) ? NGUITools.GetTypeName(widget) : "Object");

            AddItem(myName + "/Bring to Front", false,
                    delegate(object obj)
            {
                for (int i = 0; i < Selection.gameObjects.Length; ++i)
                {
                    NGUITools.BringForward(Selection.gameObjects[i]);
                }
            },
                    null);

            AddItem(myName + "/Push to Back", false,
                    delegate(object obj)
            {
                for (int i = 0; i < Selection.gameObjects.Length; ++i)
                {
                    NGUITools.PushBack(Selection.gameObjects[i]);
                }
            },
                    null);

            AddItem(myName + "/Nudge Forward", false,
                    delegate(object obj)
            {
                for (int i = 0; i < Selection.gameObjects.Length; ++i)
                {
                    NGUITools.AdjustDepth(Selection.gameObjects[i], 1);
                }
            },
                    null);

            AddItem(myName + "/Nudge Back", false,
                    delegate(object obj)
            {
                for (int i = 0; i < Selection.gameObjects.Length; ++i)
                {
                    NGUITools.AdjustDepth(Selection.gameObjects[i], -1);
                }
            },
                    null);

            if (widget != null)
            {
                NGUIContextMenu.AddSeparator(myName + "/");

                AddItem(myName + "/Make Pixel-Perfect", false, OnMakePixelPerfect, Selection.activeTransform);

                if (target.GetComponent <BoxCollider>() != null)
                {
                    AddItem(myName + "/Reset Collider Size", false, OnBoxCollider, target);
                }
            }

            NGUIContextMenu.AddSeparator(myName + "/");
            AddItem(myName + "/Delete", false, OnDelete, target);
            NGUIContextMenu.AddSeparator("");

            if (Selection.activeTransform.parent != null && widget != null)
            {
                AddChildWidget("Create/Sprite/Child", false, NGUISettings.AddSprite);
                AddChildWidget("Create/Label/Child", false, NGUISettings.AddLabel);
                AddChildWidget("Create/Invisible Widget/Child", false, NGUISettings.AddWidget);
                AddChildWidget("Create/Simple Texture/Child", false, NGUISettings.AddTexture);
                AddChildWidget("Create/Unity 2D Sprite/Child", false, NGUISettings.Add2DSprite);

                AddSiblingWidget("Create/Sprite/Sibling", false, NGUISettings.AddSprite);
                AddSiblingWidget("Create/Label/Sibling", false, NGUISettings.AddLabel);
                AddSiblingWidget("Create/Invisible Widget/Sibling", false, NGUISettings.AddWidget);
                AddSiblingWidget("Create/Simple Texture/Sibling", false, NGUISettings.AddTexture);
                AddSiblingWidget("Create/Unity 2D Sprite/Sibling", false, NGUISettings.Add2DSprite);
            }
            else
            {
                AddChildWidget("Create/Sprite", false, NGUISettings.AddSprite);
                AddChildWidget("Create/Label", false, NGUISettings.AddLabel);
                AddChildWidget("Create/Invisible Widget", false, NGUISettings.AddWidget);
                AddChildWidget("Create/Simple Texture", false, NGUISettings.AddTexture);
                AddChildWidget("Create/Unity 2D Sprite", false, NGUISettings.Add2DSprite);
            }

            NGUIContextMenu.AddSeparator("Create/");

            AddItem("Create/Panel", false, AddPanel, target);
            AddItem("Create/Scroll View", false, AddScrollView, target);
            AddItem("Create/Grid", false, AddChild <UIGrid>, target);
            AddItem("Create/Table", false, AddChild <UITable>, target);
            AddItem("Create/Anchor (Legacy)", false, AddChild <UIAnchor>, target);

            if (target.GetComponent <UIPanel>() != null)
            {
                if (target.GetComponent <UIScrollView>() == null)
                {
                    AddItem("Attach/Scroll View", false, Attach, typeof(UIScrollView));
                    NGUIContextMenu.AddSeparator("Attach/");
                }
            }
            else if (target.GetComponent <Collider>() == null && target.GetComponent <Collider2D>() == null)
            {
                AddItem("Attach/Box Collider", false, AttachCollider, null);
                NGUIContextMenu.AddSeparator("Attach/");
            }

            bool         header     = false;
            UIScrollView scrollView = NGUITools.FindInParents <UIScrollView>(target);

            if (scrollView != null)
            {
                if (scrollView.GetComponentInChildren <UICenterOnChild>() == null)
                {
                    AddItem("Attach/Center Scroll View on Child", false, Attach, typeof(UICenterOnChild));
                    header = true;
                }
            }

            if (target.GetComponent <Collider>() != null || target.GetComponent <Collider2D>() != null)
            {
                if (scrollView != null)
                {
                    if (target.GetComponent <UIDragScrollView>() == null)
                    {
                        AddItem("Attach/Drag Scroll View", false, Attach, typeof(UIDragScrollView));
                        header = true;
                    }

                    if (target.GetComponent <UICenterOnClick>() == null && NGUITools.FindInParents <UICenterOnChild>(target) != null)
                    {
                        AddItem("Attach/Center Scroll View on Click", false, Attach, typeof(UICenterOnClick));
                        header = true;
                    }
                }

                if (header)
                {
                    NGUIContextMenu.AddSeparator("Attach/");
                }

                AddItem("Attach/Button Script", false, Attach, typeof(UIButton));
                AddItem("Attach/Toggle Script", false, Attach, typeof(UIToggle));
                AddItem("Attach/Slider Script", false, Attach, typeof(UISlider));
                AddItem("Attach/Scroll Bar Script", false, Attach, typeof(UIScrollBar));
                AddItem("Attach/Progress Bar Script", false, Attach, typeof(UIProgressBar));
                AddItem("Attach/Popup List Script", false, Attach, typeof(UIPopupList));
                AddItem("Attach/Input Field Script", false, Attach, typeof(UIInput));
                NGUIContextMenu.AddSeparator("Attach/");

                if (target.GetComponent <UIDragResize>() == null)
                {
                    AddItem("Attach/Drag Resize Script", false, Attach, typeof(UIDragResize));
                }

                if (target.GetComponent <UIDragScrollView>() == null)
                {
                    for (int i = 0; i < UIPanel.list.Count; ++i)
                    {
                        UIPanel pan = UIPanel.list[i];
                        if (pan.clipping == UIDrawCall.Clipping.None)
                        {
                            continue;
                        }

                        UIScrollView dr = pan.GetComponent <UIScrollView>();
                        if (dr == null)
                        {
                            continue;
                        }

                        AddItem("Attach/Drag Scroll View", false, delegate(object obj)
                                { target.AddComponent <UIDragScrollView>().scrollView = dr; }, null);

                        header = true;
                        break;
                    }
                }

                AddItem("Attach/Key Binding Script", false, Attach, typeof(UIKeyBinding));

                if (target.GetComponent <UIKeyNavigation>() == null)
                {
                    AddItem("Attach/Key Navigation Script", false, Attach, typeof(UIKeyNavigation));
                }

                NGUIContextMenu.AddSeparator("Attach/");

                AddItem("Attach/Play Tween Script", false, Attach, typeof(UIPlayTween));
                AddItem("Attach/Play Animation Script", false, Attach, typeof(UIPlayAnimation));
                AddItem("Attach/Play Sound Script", false, Attach, typeof(UIPlaySound));
            }

            AddItem("Attach/Property Binding", false, Attach, typeof(PropertyBinding));

            if (target.GetComponent <UILocalize>() == null)
            {
                AddItem("Attach/Localization Script", false, Attach, typeof(UILocalize));
            }

            if (widget != null)
            {
                AddMissingItem <TweenAlpha>(target, "Tween/Alpha");
                AddMissingItem <TweenColor>(target, "Tween/Color");
                AddMissingItem <TweenWidth>(target, "Tween/Width");
                AddMissingItem <TweenHeight>(target, "Tween/Height");
            }
            else if (target.GetComponent <UIPanel>() != null)
            {
                AddMissingItem <TweenAlpha>(target, "Tween/Alpha");
            }

            NGUIContextMenu.AddSeparator("Tween/");

            AddMissingItem <TweenPosition>(target, "Tween/Position");
            AddMissingItem <TweenRotation>(target, "Tween/Rotation");
            AddMissingItem <TweenScale>(target, "Tween/Scale");
            AddMissingItem <TweenTransform>(target, "Tween/Transform");

            if (target.GetComponent <AudioSource>() != null)
            {
                AddMissingItem <TweenVolume>(target, "Tween/Volume");
            }

            if (target.GetComponent <Camera>() != null)
            {
                AddMissingItem <TweenFOV>(target, "Tween/Field of View");
                AddMissingItem <TweenOrthoSize>(target, "Tween/Orthographic Size");
            }
        }
    }