Example #1
0
        private void MenuButton_Click(object sender, EventArgs e)
        {
            //Prepare
            IMenuButton <MapFile, IndexEntry, Xbox>      menuItem        = null;
            IContextMenuItem <MapFile, IndexEntry, Xbox> contextMenuItem = null;

            //Get Sender
            if (sender is ToolStripItem)
            {
                //Get
                ToolStripItem Sender = (ToolStripItem)sender;
                if (Sender.Tag is IMenuButton <MapFile, IndexEntry, Xbox> )
                {
                    menuItem = (IMenuButton <MapFile, IndexEntry, Xbox>)Sender.Tag;
                }
                if (Sender.Tag is IContextMenuItem <MapFile, IndexEntry, Xbox> )
                {
                    contextMenuItem = (IContextMenuItem <MapFile, IndexEntry, Xbox>)Sender.Tag;
                }
            }

            //Click
            menuItem?.OnClick();
            contextMenuItem?.OnClick();
        }
    void Update()
    {
        bool       isTriggerDown = controller.GetPressDown(triggerButton);
        RaycastHit hit;
        Ray        ray = new Ray(rayStartPosition.position, transform.forward);

        Physics.Raycast(ray, out hit);

        if (hit.transform != null && (hit.transform.tag == "MenuButton"))
        {
            isPointing = true;
            hitPoint   = hit.point;
            CursorOn();

            if (hit.transform.GetComponent <IMenuButton>() != null)
            {
                if (lastButton != null)
                {
                    lastButton.Deselect();
                }
                lastButton = hit.transform.GetComponent <IMenuButton>();
                lastButton.Select();
            }

            if (isTriggerDown)
            {
                lastButton.OnClick();
            }
        }
        else if (isPointing)
        {
            CursorOff();
            isPointing = false;
            if (lastButton != null)
            {
                lastButton.Deselect();
                lastButton = null;
            }
        }
    }