protected virtual TouchAngleDeflection CalculateAngle(ControllerInteractionEventArgs e)
        {
            TouchAngleDeflection touchAngleDeflection = new TouchAngleDeflection();

            touchAngleDeflection.angle      = 360 - e.touchpadAngle;
            touchAngleDeflection.deflection = e.touchpadAxis.magnitude;
            return(touchAngleDeflection);
        }
Esempio n. 2
0
        //Turns and Angle and Event type into a button action
        protected virtual void InteractButton(TouchAngleDeflection givenTouchAngleDeflection, ButtonEvent evt) //Can't pass ExecuteEvents as parameter? Unity gives error
        {
            //Get button ID from angle
            float buttonAngle = 360f / buttons.Count;                                                                                                      //Each button is an arc with this angle

            givenTouchAngleDeflection.angle = VRTK_SharedMethods.Mod((givenTouchAngleDeflection.angle + -offsetRotation), 360f);                           //Offset the touch coordinate with our offset

            int buttonID             = (int)VRTK_SharedMethods.Mod(((givenTouchAngleDeflection.angle + (buttonAngle / 2f)) / buttonAngle), buttons.Count); //Convert angle into ButtonID (This is the magic)
            PointerEventData pointer = new PointerEventData(EventSystem.current);                                                                          //Create a new EventSystem (UI) Event

            if (givenTouchAngleDeflection.deflection <= deadZone)
            {
                //No button selected. Use -1 to represent this
                buttonID = -1;
            }
            if (GetComponent <VRTK_IndependentRadialMenuController>().lockOption)
            {
                if (lockedOption == -1)
                {
                    lockedOption = buttonID;
                }
            }
            else
            {
                lockedOption = -1;
            }
            if (lockedOption != -1)
            {
                buttonID = lockedOption;
            }
            optionHovered = buttonID;

            //If we changed buttons while moving, un-hover and un-click the last button we were on
            if (currentHover != buttonID && currentHover != -1)
            {
                ExecuteEvents.Execute(menuButtons[currentHover], pointer, ExecuteEvents.pointerUpHandler);
                ExecuteEvents.Execute(menuButtons[currentHover], pointer, ExecuteEvents.pointerExitHandler);
                buttons[currentHover].OnHoverExit.Invoke();
                if (executeOnUnclick && currentPress != -1 && buttonID != -1)
                {
                    ExecuteEvents.Execute(menuButtons[buttonID], pointer, ExecuteEvents.pointerDownHandler);
                    AttempHapticPulse(baseHapticStrength * 1.666f);
                }
            }
            if (evt == ButtonEvent.click) //Click button if click, and keep track of current press (executes button action)
            {
                if (buttonID != -1)
                {
                    ExecuteEvents.Execute(menuButtons[buttonID], pointer, ExecuteEvents.pointerDownHandler);
                }
                currentPress = buttonID;
                if (!executeOnUnclick && buttonID != -1)
                {
                    buttons[buttonID].OnClick.Invoke();
                    AttempHapticPulse(baseHapticStrength * 2.5f);
                }
            }
            else if (evt == ButtonEvent.unclick) //Clear press id to stop invoking OnHold method (hide menu)
            {
                if (buttonID != -1)
                {
                    ExecuteEvents.Execute(menuButtons[buttonID], pointer, ExecuteEvents.pointerUpHandler);
                }
                currentPress = -1;
                if (executeOnUnclick && buttonID != -1)
                {
                    AttempHapticPulse(baseHapticStrength * 2.5f);
                    buttons[buttonID].OnClick.Invoke();
                }
            }
            else if (evt == ButtonEvent.hoverOn && currentHover != buttonID && buttonID != -1) // Show hover UI event (darken button etc). Show menu
            {
                ExecuteEvents.Execute(menuButtons[buttonID], pointer, ExecuteEvents.pointerEnterHandler);
                buttons[buttonID].OnHoverEnter.Invoke();
                AttempHapticPulse(baseHapticStrength);
            }
            currentHover = buttonID; //Set current hover ID, need this to un-hover if selected button changes
        }
Esempio n. 3
0
 /// <summary>
 /// The UnClickButton method is used to set the button unclick at a given angle and deflection.
 /// </summary>
 /// <param name="givenTouchAngleDeflection">The angle and deflection on the radial menu.</param>
 public virtual void UnClickButton(TouchAngleDeflection givenTouchAngleDeflection)
 {
     InteractButton(givenTouchAngleDeflection, ButtonEvent.unclick);
 }
Esempio n. 4
0
 /// <summary>
 /// The HoverButton method is used to set the button hover at a given angle and deflection.
 /// </summary>
 /// <param name="givenTouchAngleDeflection">The angle and deflection on the radial menu.</param>
 public virtual void HoverButton(TouchAngleDeflection givenTouchAngleDeflection)
 {
     InteractButton(givenTouchAngleDeflection, ButtonEvent.hoverOn);
 }
        protected virtual void DoChangeAngle(TouchAngleDeflection givenTouchAngleDeflection, object sender = null)
        {
            currentTad = givenTouchAngleDeflection;

            menu.HoverButton(currentTad);
        }
 protected virtual void DoShowMenu(TouchAngleDeflection initialTad, object sender = null)
 {
     menu.ShowMenu();
     DoChangeAngle(initialTad); // Needed to register initial touch position before the touchpad axis actually changes
 }