コード例 #1
0
        void ClickListener(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource, bool newState)
        {
            if (fromSource != SteamVR_Input_Sources.LeftHand && fromSource != SteamVR_Input_Sources.RightHand)
            {
                return;
            }

            // Get button according to control type
            ViveControlType  controlType = ViveControlInputs.First(x => fromAction == x.Value.actionClick || fromAction == x.Value.actionTouch).Key;
            ViveControlInput input       = ViveControlInputs[controlType];

            // Get button click status
            ButtonStage status = GetInputActionStatus(fromAction, input);

            if (status == ButtonStage.None)
            {
                return;
            }

            // Call each button's delegate behavior
            if (controlType == ViveControlType.Grip)
            {
                if (gripDelegate != null)
                {
                    gripDelegate(status, Vector2.zero);
                }
                if (gripDelegate_Late != null)
                {
                    gripDelegate_Late(status, Vector2.zero);
                }
            }
            else if (controlType == ViveControlType.Trigger)
            {
                if (triggerDelegate != null)
                {
                    triggerDelegate(status, Vector2.zero);
                }
                if (triggerDelegate_Late != null)
                {
                    triggerDelegate_Late(status, Vector2.zero);
                }
            }
            else if (controlType == ViveControlType.Touchpad)
            {
                if (touchpadDelegate != null)
                {
                    touchpadDelegate(status, input.actionPosition.GetAxis(hand.handType));
                }
                if (touchpadDelegate_Late != null)
                {
                    touchpadDelegate_Late(status, input.actionPosition.GetAxis(hand.handType));
                }
            }
        }
コード例 #2
0
        private ButtonStage GetInputActionStatus(SteamVR_Action_Boolean actionIn, ViveControlInput input)
        {
            SteamVR_Action_Boolean actionClick = input.actionClick;
            SteamVR_Action_Boolean actionTouch = input.actionTouch;
            ButtonStage            status      = ButtonStage.None;

            if (actionIn == actionClick)
            {
                if (actionClick.GetStateDown(hand.handType))
                {
                    status = ButtonStage.PressDown;
                }
                else if (actionClick.GetStateUp(hand.handType))
                {
                    status = ButtonStage.PressUp;
                }
                else if (actionClick.GetState(hand.handType))
                {
                    status = ButtonStage.Press;
                }
            }
            else if (actionIn == actionTouch)
            {
                if (actionTouch.GetStateDown(hand.handType))
                {
                    status = ButtonStage.TouchDown;
                }
                else if (actionTouch.GetStateUp(hand.handType))
                {
                    status = ButtonStage.TouchUp;
                }
                else if (actionTouch.GetState(hand.handType))
                {
                    status = ButtonStage.Touch;
                }
            }

            return(status);
        }