Esempio n. 1
0
 private void OnActionPress(ButtonActionsPress ev)
 {
     switch (ev.button)
     {
     case BtnAction.D1:
     case BtnAction.D2:
         Select();
         break;
     }
 }
Esempio n. 2
0
        private void OnActionUnpress(ButtonActionsPress ev)
        {
            // if (!IsValidHand(ev.hand)) return;
            Debug.Log("Hand " + ev.hand.ToString() + " OnActionUnpress " + ev.button.ToString());

            if (joyBtnMap.ContainsKey(ev.button))
            {
                uint btnNumber = joyBtnMap[ev.button];
                UnpressButton(btnNumber);
            }
        }
Esempio n. 3
0
        private UnpressHandlerDelegate <ButtonActionsPress> OnActionPress(ButtonActionsPress pEv)
        {
            switch (pEv.button)
            {
            case BtnAction.D1:
            case BtnAction.D2:
                var unpress = Select();
                return((ButtonActionsPress uEv) => unpress());
            }

            return((ButtonActionsPress uEv) => {});
        }
        private void OnActionUnpress(ButtonActionsPress ev)
        {
            if (!IsValidHand(ev.hand))
            {
                return;
            }

            if (joyBtnMap.ContainsKey(ev.button))
            {
                uint btnIndex = joyBtnMap[ev.button];
                UnpressButton(btnIndex);
            }
        }
        private void OnActionPress(ButtonActionsPress ev)
        {
            if (!IsValidHand(ev.hand))
            {
                return;
            }

            if (joyBtnMap.ContainsKey(ev.button))
            {
                uint btnNumber = joyBtnMap[ev.button];
                PressButton(btnNumber);
            }
        }
 private void OnActionUnpress(ButtonActionsPress ev)
 {
     if (grabbedHand == Hand.Unknown)
     {
         return;                              // not grabbing
     }
     if (grabbedHand != ev.hand)
     {
         return;                         // wrong hand
     }
     if (joyBtnMap.ContainsKey(ev.button))
     {
         uint btnNumber = joyBtnMap[ev.button];
         if (output)
         {
             output.SetButton(btnNumber, false);
         }
     }
 }
        void OnButtonUnpress(VREvent_t ev)
        {
            ButtonPress btn;
            var         hand   = GetHandForDevice(ev.trackedDeviceIndex);
            var         button = (EVRButtonId)ev.data.controller.button;

            if (button == triggerButton)
            {
                btn = new ButtonPress(hand, Button.Trigger, false);
                TriggerUnpress.Send(btn);
            }
            if (button == grabButton)
            {
                btn = new ButtonPress(hand, Button.Grab, false);
                GrabUnpress.Send(btn);
            }
            if (button == menuButton)
            {
                btn = new ButtonPress(hand, Button.Menu, false);
                MenuUnpress.Send(btn);
            }

            if (basicBtnActions.ContainsKey(button))
            {
                var btnAction = basicBtnActions[button];
                var press     = new ButtonActionsPress(hand, btnAction, false);
                ButtonActionUnpress.Send(press);
            }

            if (button == EVRButtonId.k_EButton_SteamVR_Touchpad)
            {
                if (UnpressTouchpadHandler != null)
                {
                    UnpressTouchpadHandler();
                    UnpressTouchpadHandler = null;
                }
            }
        }
Esempio n. 8
0
 public static bool ButtonActionsPressComparator(ButtonActionsPress pEv, ButtonActionsPress uEv)
 {
     return(uEv.hand == pEv.hand && uEv.button == pEv.button);
 }
        void OnButtonPress(VREvent_t ev)
        {
            ButtonPress btn;
            var         hand   = GetHandForDevice(ev.trackedDeviceIndex);
            var         button = (EVRButtonId)ev.data.controller.button;

            if (button == triggerButton)
            {
                btn = new ButtonPress(hand, Button.Trigger, true);
                TriggerPress.Send(btn);
            }
            if (button == grabButton)
            {
                btn = new ButtonPress(hand, Button.Grab, true);
                GrabPress.Send(btn);
            }
            if (button == menuButton)
            {
                btn = new ButtonPress(hand, Button.Menu, true);
                MenuPress.Send(btn);
            }

            if (basicBtnActions.ContainsKey(button))
            {
                var btnAction = basicBtnActions[button];
                var press     = new ButtonActionsPress(hand, btnAction, true);
                ButtonActionPress.Send(press);
            }

            if (button == EVRButtonId.k_EButton_SteamVR_Touchpad)
            {
                var vr = OpenVR.System;
                // For now this only handles the SteamVR Touchpad
                // In the future Joysticks and small WMR touchpads should be supported
                // Though it's probably easiest to switch to get the SteamVR Input API working to replace this first
                var err         = ETrackedPropertyError.TrackedProp_Success;
                var axisTypeInt = vr.GetInt32TrackedDeviceProperty(ev.trackedDeviceIndex, ETrackedDeviceProperty.Prop_Axis0Type_Int32, ref err);
                if (err == ETrackedPropertyError.TrackedProp_Success)
                {
                    var axisType = (EVRControllerAxisType)axisTypeInt;
                    if (axisType == EVRControllerAxisType.k_eControllerAxis_TrackPad)
                    {
                        var state = new VRControllerState_t();
                        var size  = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VRControllerState_t));
                        if (vr.GetControllerState(ev.trackedDeviceIndex, ref state, size))
                        {
                            var       axis      = ControllerAxisToVector2(state.rAxis0);
                            float     magnitude = 0;
                            Direction dir       = GetLargestVectorDirection(axis, ref magnitude);

                            if (magnitude > trackpadCenterButtonRadius)
                            {
                                // Directional button press
                                var dirBtn = new DirectionActionsPress(hand, DirectionAction.D1, dir, true);
                                DirectionActionPress.Send(dirBtn);

                                UnpressTouchpadHandler = () =>
                                {
                                    var dirBtnUnpress = new DirectionActionsPress(hand, DirectionAction.D1, dir, false);
                                    DirectionActionUnpress.Send(dirBtnUnpress);
                                };
                            }
                            else
                            {
                                // Center button press
                                var press = new ButtonActionsPress(hand, BtnAction.D1, true);
                                ButtonActionPress.Send(press);

                                UnpressTouchpadHandler = () =>
                                {
                                    var unpress = new ButtonActionsPress(hand, BtnAction.D1, false);
                                    ButtonActionUnpress.Send(unpress);
                                };
                            }
                        }
                    }
                }
            }
        }