コード例 #1
0
    public static string AliasToControlString(ButtonAlias Alias, Handedness hand)
    {
        if (hand == Handedness.LEFT)
        {
            switch (Alias)
            {
            case ButtonAlias.AXIS_CLICK:
                return("VR_Primary2DAxisClickButton_Left");

            case ButtonAlias.AXIS_TOUCH:
                return("VR_Primary2DAxisTouchButton_Left");

            default:
                return("");
            }
        }
        else // RIGHT HAND
        {
            switch (Alias)
            {
            case ButtonAlias.AXIS_CLICK:
                return("VR_Primary2DAxisClickButton_Right");

            case ButtonAlias.AXIS_TOUCH:
                return("VR_Primary2DAxisTouchButton_Right");

            default:
                return("");
            }
        }
    }
コード例 #2
0
        public void TestButtonPressedTab()
        {
            var handler = new InputHandler();
            //var keystate = new KeyboardState();
            var aliasAButton  = new ButtonAlias(Buttons.A, -1, -1, "TestAlias");
            var aliasAKey     = new ButtonAlias(Keys.Down, -1, -1, "TestAlias");
            var dictionary    = new Dictionary <ButtonAction, List <ButtonAlias> >();
            var listOfAliases = new List <ButtonAlias> {
                aliasAButton, aliasAKey
            };

            dictionary.Add(ButtonAction.MenuUp, listOfAliases);

            var buttonsetter = typeof(InputHandler).GetField("_superButton", BindingFlags.Static | BindingFlags.NonPublic);

            buttonsetter.SetValue(handler, dictionary);

            var keystate  = typeof(InputHandler).GetField("_keyState", BindingFlags.NonPublic | BindingFlags.Instance);
            var keystatev = keystate.GetValue(handler);

            var test = typeof(KeyboardState).GetField("currentState0", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            // Tab Key
            test.SetValue(keystatev, UInt32.Parse("512"));

            keystate.SetValue(handler, keystatev);
            Assert.IsFalse(handler.IsButtonPressed(ButtonAction.MenuUp));
        }
コード例 #3
0
        /// <summary>
        /// The IsButtonPressed method takes a given button alias and returns a boolean whether that given button is currently being pressed or not.
        /// </summary>
        /// <param name="button">The button to check if it's being pressed.</param>
        /// <returns>Is true if the button is being pressed.</returns>
        public bool IsButtonPressed(ButtonAlias button)
        {
            switch (button)
            {
            case ButtonAlias.Trigger_Hairline:
                return(triggerHairlinePressed);

            case ButtonAlias.Trigger_Touch:
                return(triggerTouched);

            case ButtonAlias.Trigger_Press:
                return(triggerPressed);

            case ButtonAlias.Trigger_Click:
                return(triggerClicked);

            case ButtonAlias.Grip:
                return(grabPressed);

            case ButtonAlias.Touchpad_Touch:
                return(touchpadTouched);

            case ButtonAlias.Touchpad_Press:
                return(touchpadPressed);

            case ButtonAlias.Application_Menu:
                return(applicationMenuPressed);
            }
            return(false);
        }
コード例 #4
0
        private void EmitAlias(ButtonAlias type, bool touchDown, float buttonPressure, ref bool buttonBool)
        {
            if (pointerToggleButton == type)
            {
                if (touchDown)
                {
                    pointerPressed = true;
                    OnAliasPointerOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
                }
                else
                {
                    pointerPressed = false;
                    OnAliasPointerOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
                }
            }

            if (grabToggleButton == type)
            {
                if (touchDown)
                {
                    grabPressed = true;
                    OnAliasGrabOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
                }
                else
                {
                    grabPressed = false;
                    OnAliasGrabOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
                }
            }

            if (useToggleButton == type)
            {
                if (touchDown)
                {
                    usePressed = true;
                    OnAliasUseOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
                }
                else
                {
                    usePressed = false;
                    OnAliasUseOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
                }
            }

            if (menuToggleButton == type)
            {
                if (touchDown)
                {
                    menuPressed = true;
                    OnAliasMenuOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
                }
                else
                {
                    menuPressed = false;
                    OnAliasMenuOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
                }
            }
        }
コード例 #5
0
    void EmitAlias(ButtonAlias type, bool touchDown, ref bool buttonBool)
    {
        if (pointerToggleButton == type)
        {
            if (touchDown)
            {
                OnAliasPointerOn(SetButtonEvent(ref buttonBool, true));
            }
            else
            {
                OnAliasPointerOff(SetButtonEvent(ref buttonBool, false));
            }
        }

        if (grabToggleButton == type)
        {
            if (touchDown)
            {
                OnAliasGrabOn(SetButtonEvent(ref buttonBool, true));
            }
            else
            {
                OnAliasGrabOff(SetButtonEvent(ref buttonBool, false));
            }
        }

        if (useToggleButton == type)
        {
            if (touchDown)
            {
                OnAliasUseOn(SetButtonEvent(ref buttonBool, true));
            }
            else
            {
                OnAliasUseOff(SetButtonEvent(ref buttonBool, false));
            }
        }

        if (menuToggleButton == type)
        {
            if (touchDown)
            {
                OnAliasMenuOn(SetButtonEvent(ref buttonBool, true));
            }
            else
            {
                OnAliasMenuOff(SetButtonEvent(ref buttonBool, false));
            }
        }
    }
コード例 #6
0
    private string AliasToControlString(ButtonAlias Alias, Handedness hand)
    {
        if (hand == Handedness.LEFT)
        {
            switch (Alias)
            {
            case ButtonAlias.AXIS_CLICK:
                if (XRSettings.loadedDeviceName == "WindowsMR")
                {
                    return("VR_Thumbrest_Left");
                }
                else
                {
                    return("VR_Primary2DAxisClickButton_Left");
                }

            case ButtonAlias.AXIS_TOUCH:
                return("VR_Primary2DAxisTouchButton_Left");

            default:
                return("");
            }
        }
        else // RIGHT HAND
        {
            switch (Alias)
            {
            case ButtonAlias.AXIS_CLICK:
                if (XRSettings.loadedDeviceName == "WindowsMR")
                {
                    return("VR_Thumbrest_Right");
                }
                else
                {
                    return("VR_Primary2DAxisClickButton_Right");
                }

            case ButtonAlias.AXIS_TOUCH:
                return("VR_Primary2DAxisTouchButton_Right");

            default:
                return("");
            }
        }
    }
コード例 #7
0
        public void TestAliasCreationForKey()
        {
            var alias = new ButtonAlias(Keys.A, -1, -1, "TestAlias");

            Assert.IsNotNull(alias);
        }
コード例 #8
0
 private bool GetButtonDown(ButtonAlias alias, Handedness hand)
 {
     return(Input.GetButtonDown(AliasToControlString(alias, hand)));
 }
コード例 #9
0
    void EmitAlias(ButtonAlias type, bool touchDown, float buttonPressure, ref bool buttonBool)
    {
        if (pointerToggleButton == type)
        {
            if (touchDown)
            {
                OnAliasPointerOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
            } else
            {
                OnAliasPointerOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
            }
        }

        if (grabToggleButton == type)
        {
            if (touchDown)
            {
                OnAliasGrabOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
            }
            else
            {
                OnAliasGrabOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
            }
        }

        if (useToggleButton == type)
        {
            if (touchDown)
            {
                OnAliasUseOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
            }
            else
            {
                OnAliasUseOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
            }
        }

        if (menuToggleButton == type)
        {
            if (touchDown)
            {
                OnAliasMenuOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
            }
            else
            {
                OnAliasMenuOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
            }
        }
    }
コード例 #10
0
 /// <summary>
 /// The IsButtonPressed method takes a given button alias and returns a boolean whether that given button is currently being pressed or not.
 /// </summary>
 /// <param name="button">The button to check if it's being pressed.</param>
 /// <returns>Is true if the button is being pressed.</returns>
 public bool IsButtonPressed(ButtonAlias button)
 {
     switch (button)
     {
         case ButtonAlias.Trigger_Hairline:
             return triggerHairlinePressed;
         case ButtonAlias.Trigger_Touch:
             return triggerTouched;
         case ButtonAlias.Trigger_Press:
             return triggerPressed;
         case ButtonAlias.Trigger_Click:
             return triggerClicked;
         case ButtonAlias.Grip:
             return grabPressed;
         case ButtonAlias.Touchpad_Touch:
             return touchpadTouched;
         case ButtonAlias.Touchpad_Press:
             return touchpadPressed;
         case ButtonAlias.Application_Menu:
             return applicationMenuPressed;
     }
     return false;
 }
コード例 #11
0
    /// <summary>
    /// 更原始的添加方案,subscribe是决定是添加还是删除事件
    /// </summary>
    /// <param name="subscribe"></param>
    /// <param name="givenButton"></param>
    /// <param name="startEvent"></param>
    /// <param name="callbackMethod"></param>
    protected virtual void ButtonAliasEventSubscription(bool subscribe, ButtonAlias givenButton, bool startEvent, ControllerInteractionEventHandler callbackMethod)
    {
        //Debug.Log("开始注册抓取事件: " + givenButton.ToString());
        switch (givenButton)
        {
        case ButtonAlias.Trigger:
            if (subscribe)
            {
                if (startEvent)
                {
                    TriggerPressed += callbackMethod;
                }
                else
                {
                    TriggerReleased += callbackMethod;
                }
            }
            else
            {
                if (startEvent)
                {
                    TriggerPressed -= callbackMethod;
                }
                else
                {
                    TriggerReleased -= callbackMethod;
                }
            }
            break;

        case ButtonAlias.Grip:
            if (subscribe)
            {
                if (startEvent)
                {
                    //Debug.Log("抓取事件注册完毕");
                    GripClicked += callbackMethod;
                }
                else
                {
                    //Debug.Log("释放事件注册完毕");
                    GripUnclicked += callbackMethod;
                }
            }
            else
            {
                if (startEvent)
                {
                    GripClicked -= callbackMethod;
                }
                else
                {
                    GripUnclicked -= callbackMethod;
                }
            }
            break;

        case ButtonAlias.A:
            if (subscribe)
            {
                if (startEvent)
                {
                    AClicked += callbackMethod;
                }
                else
                {
                    AUnclicked += callbackMethod;
                }
            }
            else
            {
                if (startEvent)
                {
                    AClicked -= callbackMethod;
                }
                else
                {
                    AUnclicked -= callbackMethod;
                }
            }
            break;

        case ButtonAlias.B:
            if (subscribe)
            {
                if (startEvent)
                {
                    BClicked += callbackMethod;
                }
                else
                {
                    BUnclicked += callbackMethod;
                }
            }
            else
            {
                if (startEvent)
                {
                    BClicked -= callbackMethod;
                }
                else
                {
                    BUnclicked -= callbackMethod;
                }
            }
            break;

        case ButtonAlias.X:
            if (subscribe)
            {
                if (startEvent)
                {
                    XClicked += callbackMethod;
                }
                else
                {
                    XUnclicked += callbackMethod;
                }
            }
            else
            {
                if (startEvent)
                {
                    XClicked -= callbackMethod;
                }
                else
                {
                    XUnclicked -= callbackMethod;
                }
            }
            break;

        case ButtonAlias.Y:
            if (subscribe)
            {
                if (startEvent)
                {
                    YClicked += callbackMethod;
                }
                else
                {
                    YUnclicked += callbackMethod;
                }
            }
            else
            {
                if (startEvent)
                {
                    YClicked -= callbackMethod;
                }
                else
                {
                    YUnclicked -= callbackMethod;
                }
            }
            break;
        }
    }
コード例 #12
0
 public virtual void UnsubscribeToButtonAliasEvent(ButtonAlias givenButton, bool startEvent, ControllerInteractionEventHandler callbackMethod)
 {
     ButtonAliasEventSubscription(false, givenButton, startEvent, callbackMethod);
 }
コード例 #13
0
 public virtual void Release(ButtonAlias button)
 {
     buttonPressed[(int)button] = false;
 }
コード例 #14
0
 public virtual void Press(ButtonAlias button)
 {
     buttonPressed[(int)button] = true;
 }
コード例 #15
0
 public bool IsButtonPressed(ButtonAlias button)
 {
     return(buttonPressed[(int)button]);
 }
コード例 #16
0
        public void PressButton(ButtonAlias buttonToPress)
        {
            ControllerInteractionEventArgs controllerEventArgs = SetControllerEvent();

            switch (buttonToPress)
            {
            case ButtonAlias.Undefined:
                break;

            case ButtonAlias.TriggerHairline:
                OnTriggerHairlineStart(controllerEventArgs);
                break;

            case ButtonAlias.TriggerTouch:
                OnTriggerTouchStart(controllerEventArgs);
                break;

            case ButtonAlias.TriggerPress:
                OnTriggerPressed(controllerEventArgs);
                break;

            case ButtonAlias.TriggerClick:
                OnTriggerClicked(controllerEventArgs);
                break;

            case ButtonAlias.GripHairline:
                OnGripHairlineStart(controllerEventArgs);
                break;

            case ButtonAlias.GripTouch:
                OnGripTouchStart(controllerEventArgs);
                break;

            case ButtonAlias.GripPress:
                OnGripPressed(controllerEventArgs);
                break;

            case ButtonAlias.GripClick:
                OnGripClicked(controllerEventArgs);
                break;

            case ButtonAlias.TouchpadTouch:
                OnTouchpadTouchStart(controllerEventArgs);
                break;

            case ButtonAlias.TouchpadPress:
                OnTouchpadPressed(controllerEventArgs);
                break;

            case ButtonAlias.TouchpadTwoTouch:
                OnTouchpadTwoTouchStart(controllerEventArgs);
                break;

            case ButtonAlias.TouchpadTwoPress:
                OnTouchpadTwoPressed(controllerEventArgs);
                break;

            case ButtonAlias.ButtonOneTouch:
                OnButtonOneTouchStart(controllerEventArgs);
                break;

            case ButtonAlias.ButtonOnePress:
                OnButtonOnePressed(controllerEventArgs);
                break;

            case ButtonAlias.ButtonTwoTouch:
                OnButtonTwoTouchStart(controllerEventArgs);
                break;

            case ButtonAlias.ButtonTwoPress:
                OnButtonTwoPressed(controllerEventArgs);
                break;

            case ButtonAlias.StartMenuPress:
                OnStartMenuPressed(controllerEventArgs);
                break;

            case ButtonAlias.TouchpadSense:
                OnTouchpadSenseAxisChanged(controllerEventArgs);
                break;

            case ButtonAlias.TriggerSense:
                OnTriggerSenseAxisChanged(controllerEventArgs);
                break;

            case ButtonAlias.MiddleFingerSense:
                OnMiddleFingerSenseAxisChanged(controllerEventArgs);
                break;

            case ButtonAlias.RingFingerSense:
                OnRingFingerSenseAxisChanged(controllerEventArgs);
                break;

            case ButtonAlias.PinkyFingerSense:
                OnPinkyFingerSenseAxisChanged(controllerEventArgs);
                break;

            case ButtonAlias.GripSense:
                OnGripSenseAxisChanged(controllerEventArgs);
                break;

            case ButtonAlias.GripSensePress:
                OnGripSensePressed(controllerEventArgs);
                break;

            default:
                break;
            }
        }
コード例 #17
0
 public abstract bool IsButtonPressed(ButtonAlias gripPress);
コード例 #18
0
 public static bool GetButtonUp(ButtonAlias alias, Handedness hand)
 {
     return(Input.GetButtonUp(AliasToControlString(alias, hand)));
 }
コード例 #19
0
        private void EmitAlias(ButtonAlias type, bool touchDown, float buttonPressure, ref bool buttonBool)
        {
            if (pointerToggleButton == type)
            {
                if (touchDown)
                {
                    pointerPressed = true;
                    OnAliasPointerOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
                }
                else
                {
                    pointerPressed = false;
                    OnAliasPointerOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
                }
            }

            if (pointerSetButton == type)
            {
                if (!touchDown)
                {
                    OnAliasPointerSet(SetButtonEvent(ref buttonBool, false, buttonPressure));
                }
            }

            if (grabToggleButton == type)
            {
                if (touchDown)
                {
                    grabPressed = true;
                    OnAliasGrabOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
                }
                else
                {
                    grabPressed = false;
                    OnAliasGrabOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
                }
            }

            if (useToggleButton == type)
            {
                if (touchDown)
                {
                    usePressed = true;
                    OnAliasUseOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
                }
                else
                {
                    usePressed = false;
                    OnAliasUseOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
                }
            }

            if (uiClickButton == type)
            {
                if (touchDown)
                {
                    uiClickPressed = true;

                    OnAliasUIClickOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
                }
                else
                {
                    uiClickPressed = false;
                    OnAliasUIClickOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
                }
            }

            if (menuToggleButton == type)
            {
                if (touchDown)
                {
                    menuPressed = true;
                    Application.LoadLevel(Application.loadedLevel);

                    OnAliasMenuOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
                }
                else
                {
                    menuPressed = false;
                    OnAliasMenuOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
                }
            }
        }
コード例 #20
0
        private void EmitAlias(ButtonAlias type, bool touchDown, float buttonPressure, ref bool buttonBool)
        {
            if (pointerToggleButton == type)
            {
                if (touchDown)
                {
                    pointerPressed = true;
                    OnAliasPointerOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
                }
                else
                {
                    pointerPressed = false;
                    OnAliasPointerOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
                }
            }

            if (pointerSetButton == type)
            {
                if (! touchDown)
                {
                    OnAliasPointerSet(SetButtonEvent(ref buttonBool, true, buttonPressure));
                }
            }

            if (grabToggleButton == type)
            {
                if (touchDown)
                {
                    grabPressed = true;
                    OnAliasGrabOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
                }
                else
                {
                    grabPressed = false;
                    OnAliasGrabOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
                }
            }

            if (useToggleButton == type)
            {
                if (touchDown)
                {
                    usePressed = true;
                    OnAliasUseOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
                }
                else
                {
                    usePressed = false;
                    OnAliasUseOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
                }
            }

            if (menuToggleButton == type)
            {
                if (touchDown)
                {
                    menuPressed = true;
                    OnAliasMenuOn(SetButtonEvent(ref buttonBool, true, buttonPressure));
                }
                else
                {
                    menuPressed = false;
                    OnAliasMenuOff(SetButtonEvent(ref buttonBool, false, buttonPressure));
                }
            }
        }
コード例 #21
0
 public override bool IsButtonPressed(ButtonAlias gripPress) => _eventComponent.IsButtonPressed(gripPress);