public pvrVector2f GetButtonAxis(int hand, PVR.pvrButton btn)
            {
                pvrVector2f axis = new pvrVector2f();

                switch (btn)
                {
                case pvrButton.pvrButton_Grip:
                    axis.x = _InputState.Grip[hand];
                    break;

                case pvrButton.pvrButton_Trigger:
                    axis.x = _InputState.Trigger[hand];
                    break;

                case pvrButton.pvrButton_JoyStick:
                    axis.x = _InputState.JoyStick[hand].x;


                    axis.y = _InputState.JoyStick[hand].y;
                    break;

                case pvrButton.pvrButton_TouchPad:
                    axis.x = _InputState.TouchPad[hand].x;
                    axis.y = _InputState.TouchPad[hand].y;
                    break;

                default:
                    axis.x = IsButtonInPress(hand, btn) ? 1.0f : 0.0f;
                    break;
                }
                return(axis);
            }
示例#2
0
 public PVRAxisEventData(EventSystem eventSystem, int hand, pvrButton btn, pvrVector2f axis)
     : base(eventSystem)
 {
     _btn  = btn;
     _axis = axis;
     _hand = hand;
 }
 public static Vector2 ConvertPosition(pvrVector2f vec)
 {
     return(new Vector2((float)vec.x, (float)vec.y));
 }
示例#4
0
            // Update is called once per frame
            void Update()
            {
                if (PVRSession.instance.ready)
                {
                    pvrInputState inputState = PVRSession.instance.inputState;

                    for (int hand = 0; hand < 2; hand++)
                    {
                        uint oldButtons = _PrevInputState.HandButtons[hand];
                        uint oldTouches = _PrevInputState.HandTouches[hand];
                        if (inputState.HandButtons[hand] != oldButtons)
                        {
                            for (int i = 0; i < _Buttons.Length; i++)
                            {
                                bool currPress = ((inputState.HandButtons[hand] & (uint)_Buttons[i]) != 0);
                                bool oldPress  = ((oldButtons & (uint)_Buttons[i]) != 0);
                                if (currPress != oldPress)
                                {
                                    if (currPress)
                                    {
                                        //Debug.LogFormat("[PVR-Unity] Button {0} is just pressed.", _Buttons[i]);
                                        ExecuteEvents.Execute <IPVRInputEventTarget>(gameObject, new PVRButtonEventData(EventSystem.current, hand, _Buttons[i]), (x, y) => x.OnButtonPress((PVRButtonEventData)y));
                                    }
                                    else
                                    {
                                        //Debug.LogFormat("[PVR-Unity] Button {0} is just released.", _Buttons[i]);
                                        ExecuteEvents.Execute <IPVRInputEventTarget>(gameObject, new PVRButtonEventData(EventSystem.current, hand, _Buttons[i]), (x, y) => x.OnButtonRelease((PVRButtonEventData)y));
                                    }
                                }

                                bool currTouch = ((inputState.HandTouches[hand] & (uint)_Buttons[i]) != 0);
                                bool oldTouch  = ((oldTouches & (uint)_Buttons[i]) != 0);
                                if (currTouch != oldTouch)
                                {
                                    if (currTouch)
                                    {
                                        ExecuteEvents.Execute <IPVRInputEventTarget>(gameObject, new PVRButtonEventData(EventSystem.current, hand, _Buttons[i]), (x, y) => x.OnButtonTouch((PVRButtonEventData)y));
                                    }
                                    else
                                    {
                                        ExecuteEvents.Execute <IPVRInputEventTarget>(gameObject, new PVRButtonEventData(EventSystem.current, hand, _Buttons[i]), (x, y) => x.OnButtonUntouch((PVRButtonEventData)y));
                                    }
                                }
                                pvrVector2f oldAxis = new pvrVector2f();
                                switch (_Buttons[i])
                                {
                                case pvrButton.pvrButton_Grip:
                                    oldAxis.x = _PrevInputState.Grip[hand];
                                    break;

                                case pvrButton.pvrButton_Trigger:
                                    oldAxis.x = _PrevInputState.Trigger[hand];
                                    break;

                                case pvrButton.pvrButton_TouchPad:
                                    oldAxis.x = _PrevInputState.TouchPad[hand].x;
                                    oldAxis.y = _PrevInputState.TouchPad[hand].y;
                                    break;

                                case pvrButton.pvrButton_JoyStick:
                                    oldAxis.x = _PrevInputState.JoyStick[hand].x;
                                    oldAxis.y = _PrevInputState.JoyStick[hand].y;
                                    break;

                                default:
                                    oldAxis.x = oldPress ? 1.0f : 0.0f;
                                    break;
                                }
                                pvrVector2f newAxis = PVRSession.instance.GetButtonAxis(hand, _Buttons[i]);
                                if (newAxis.x != oldAxis.x || newAxis.y != oldAxis.y)
                                {
                                    ExecuteEvents.Execute <IPVRInputEventTarget>(gameObject, new PVRAxisEventData(EventSystem.current, hand, _Buttons[i], newAxis), (x, y) => x.OnAxisChange((PVRAxisEventData)y));
                                }
                            }
                        }

                        _PrevInputState.HandButtons[hand] = inputState.HandButtons[hand];
                        _PrevInputState.HandTouches[hand] = inputState.HandTouches[hand];
                        _PrevInputState.Grip[hand]        = inputState.Grip[hand];
                        _PrevInputState.JoyStick[hand]    = inputState.JoyStick[hand];
                        _PrevInputState.Trigger[hand]     = inputState.Trigger[hand];
                        _PrevInputState.TouchPad[hand]    = inputState.TouchPad[hand];
                    }
                    _PrevInputState.TimeInSeconds = inputState.TimeInSeconds;
                }
            }