public static float GetAxis(AxisCode axis) { XRController controller = GetXRController(axis); if (controller != null) { InputControl tmp = GetInputControlAxis(controller, axis); AxisControl aControl = null; if (axis == AxisCode.LeftStick_Horizontal || axis == AxisCode.RightStick_Horizontal) { aControl = ((Vector2Control)tmp).x; } else if (axis == AxisCode.LeftStick_Vertical || axis == AxisCode.RightStick_Vertical) { aControl = ((Vector2Control)tmp).y; } else { aControl = (AxisControl)tmp; } return(aControl.ReadValue()); } return(0); }
protected override float ImpGetAxis(AxisCode axis) { InputControl tmp = GetInputControlAxis(_inputDevice, axis); float aValue = 0; float dZone = 0; if (tmp != null) { AxisControl aControl = null; if (axis == AxisCode.LeftStick_Horizontal || axis == AxisCode.RightStick_Horizontal) { aControl = ((Vector2Control)tmp).x; dZone = _deadZoneThumbStick; } else if (axis == AxisCode.LeftStick_Vertical || axis == AxisCode.RightStick_Vertical) { aControl = ((Vector2Control)tmp).y; dZone = _deadZoneThumbStick; } else { aControl = (AxisControl)tmp; dZone = _deadZoneIndexTrigger; } aValue = aControl.ReadValue(); } return(Mathf.Abs(aValue) > dZone ? aValue : 0); }
// Update visual element for twist and pressue private void OnAxisChange(AxisControl control) { if (control.name == "twist") { pen_rotation.GetChild(0).localEulerAngles = m_rotateAdjust + new Vector3(0, control.ReadValue() * -360, 0); } else if (control.name == "pressure") { Color newColor = Color.red; newColor.a = control.ReadValue(); var main = m_highlightPS.main; main.startColor = newColor; m_pressureText.color = newColor; m_pressureText.text = "Pressure: " + control.ReadValue().ToString("F2"); } }
private void UpdateAxis(InputAction.CallbackContext context) { AxisControl control = context.control as AxisControl; if (control != null) { float value = control.ReadValue(); statusSlider.value = value; } }
void OnEnable() { axisAction.Enable(); axisAction.performed += UpdateAxis; axisAction.started += UpdateAxis; axisAction.cancelled += UpdateAxis; ReadOnlyArray <InputControl> controls = axisAction.controls; for (int i = 0; i < controls.Count; i++) { AxisControl control = controls[i] as AxisControl; if (control != null) { float value = control.ReadValue(); statusSlider.value = value; } else { Debug.LogWarningFormat(this, "AxisControlActionStatus expects bindings of type {1}, but found {1} binding named {2}.", typeof(AxisControl).FullName, controls[i].GetType().FullName, controls[i].name); } } }
public void State_LinuxJoystickStickAxesReportProperValues() { runtime.ReportNewInputDevice(TestSDLJoystick.descriptorString); InputSystem.Update(); Assert.That(InputSystem.devices, Has.Count.EqualTo(1)); var device = InputSystem.devices[0]; ButtonControl leftButton = device["stick/left"] as ButtonControl; ButtonControl rightButton = device["stick/right"] as ButtonControl; AxisControl xAxis = device["stick/x"] as AxisControl; ButtonControl downButton = device["stick/down"] as ButtonControl; ButtonControl upButton = device["stick/up"] as ButtonControl; AxisControl yAxis = device["stick/y"] as AxisControl; TestSDLJoystick joystickState = new TestSDLJoystick(); InputSystem.QueueStateEvent(device, joystickState); InputSystem.Update(); joystickState.yAxis = short.MaxValue; joystickState.xAxis = short.MaxValue; InputSystem.QueueStateEvent(device, joystickState); InputSystem.Update(); float leftValue = leftButton.ReadValue(); float rightValue = rightButton.ReadValue(); float xValue = xAxis.ReadValue(); float downValue = downButton.ReadValue(); float upValue = upButton.ReadValue(); float yValue = yAxis.ReadValue(); Assert.That(downValue, Is.EqualTo(1.0f)); Assert.That(upValue, Is.EqualTo(0.0f)); Assert.That(yValue, Is.EqualTo(-1.0f)); Assert.That(leftValue, Is.EqualTo(0.0f)); Assert.That(rightValue, Is.EqualTo(1.0f)); Assert.That(xValue, Is.EqualTo(1.0f)); joystickState.yAxis = short.MinValue; joystickState.xAxis = short.MinValue; InputSystem.QueueStateEvent(device, joystickState); InputSystem.Update(); leftValue = leftButton.ReadValue(); rightValue = rightButton.ReadValue(); xValue = xAxis.ReadValue(); downValue = downButton.ReadValue(); upValue = upButton.ReadValue(); yValue = yAxis.ReadValue(); Assert.That(downValue, Is.EqualTo(0.0f)); Assert.That(upValue, Is.EqualTo(1.0f)); Assert.That(yValue, Is.EqualTo(1.0f)); Assert.That(leftValue, Is.EqualTo(1.0f)); Assert.That(rightValue, Is.EqualTo(0.0f)); Assert.That(xValue, Is.EqualTo(-1.0f)); joystickState.yAxis = 0; joystickState.xAxis = 0; InputSystem.QueueStateEvent(device, joystickState); InputSystem.Update(); leftValue = leftButton.ReadValue(); rightValue = rightButton.ReadValue(); xValue = xAxis.ReadValue(); downValue = downButton.ReadValue(); upValue = upButton.ReadValue(); yValue = yAxis.ReadValue(); Assert.That(downValue, Is.EqualTo(0.0f)); Assert.That(upValue, Is.EqualTo(0.0f)); Assert.That(yValue, Is.EqualTo(0.0f)); Assert.That(leftValue, Is.EqualTo(0.0f)); Assert.That(rightValue, Is.EqualTo(0.0f)); Assert.That(xValue, Is.EqualTo(0.0f)); }
protected virtual float ReadValue() { return(_axisControl.ReadValue()); }