Пример #1
0
    void OnPress(bool isPressed)
    {
        // Filter for touches or selected mouse button.

        if (UICamera.currentTouchID >= 0 || UICamera.currentTouchID == (-1 - mouseButton))
        {
            // We show the menu on the up-press not the down-press. Otherwise NGUI would steal
            // the selection state from the context menu on the up-press, causing the menu to
            // close immediately.

            if (!isPressed)
            {
                current = this;
                EventDelegate.Execute(onShow);

                Vector3 menuPosition = placeAtTouchPosition ? new Vector3(UICamera.currentTouch.pos.x, UICamera.currentTouch.pos.y, 0f) :
                                       CtxHelper.ComputeMenuPosition(contextMenu, gameObject);

                CtxMenu.Item[] items = MenuItems;

                if (items != null || contextMenu.onShow.Count > 0)
                {
                    EventDelegate.Add(contextMenu.onSelection, OnMenuSelection);
                    EventDelegate.Add(contextMenu.onHide, OnHide, true);

                    if (menuItems != null && menuItems.Length > 0)
                    {
                        contextMenu.Show(menuPosition, menuItems);
                    }
                    else
                    {
                        contextMenu.Show(menuPosition);
                    }
                }
            }
        }
    }
Пример #2
0
    void OnPress(bool isPressed)
    {
        if (isPressed)
        {
            // We compute the menu position on the down-press. Why? Because
            // UIButtonScale and UIButtonOffset will distort the button's transform
            // and throw off our calculations if we do it on the up-press. We don't
            // want to not support those NGUI features, so...
            menuPosition = CtxHelper.ComputeMenuPosition(contextMenu, gameObject);
        }
        else if (enabled && contextMenu != null)
        {
            current = this;
            if (onShow != null)
            {
                EventDelegate.Execute(onShow);
            }

            CtxMenu.Item[] items = MenuItems;

            if (items != null || contextMenu.onShow != null)
            {
                EventDelegate.Add(contextMenu.onSelection, OnMenuSelection);
                EventDelegate.Add(contextMenu.onHide, OnHide, true);

                if (menuItems != null && menuItems.Length > 0)
                {
                    contextMenu.Show(menuPosition, menuItems);
                }
                else
                {
                    contextMenu.Show(menuPosition);
                }
            }
        }
    }