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(""); } } }
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)); }
/// <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); }
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)); } } }
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)); } } }
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(""); } } }
public void TestAliasCreationForKey() { var alias = new ButtonAlias(Keys.A, -1, -1, "TestAlias"); Assert.IsNotNull(alias); }
private bool GetButtonDown(ButtonAlias alias, Handedness hand) { return(Input.GetButtonDown(AliasToControlString(alias, hand))); }
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)); } } }
/// <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; }
/// <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; } }
public virtual void UnsubscribeToButtonAliasEvent(ButtonAlias givenButton, bool startEvent, ControllerInteractionEventHandler callbackMethod) { ButtonAliasEventSubscription(false, givenButton, startEvent, callbackMethod); }
public virtual void Release(ButtonAlias button) { buttonPressed[(int)button] = false; }
public virtual void Press(ButtonAlias button) { buttonPressed[(int)button] = true; }
public bool IsButtonPressed(ButtonAlias button) { return(buttonPressed[(int)button]); }
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; } }
public abstract bool IsButtonPressed(ButtonAlias gripPress);
public static bool GetButtonUp(ButtonAlias alias, Handedness hand) { return(Input.GetButtonUp(AliasToControlString(alias, hand))); }
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)); } } }
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)); } } }
public override bool IsButtonPressed(ButtonAlias gripPress) => _eventComponent.IsButtonPressed(gripPress);