public float?GetAxis() { float?axis = null; if (m_type == InputType.DigitalAxis || m_type == InputType.RemoteAxis) { axis = m_invert ? -m_value : m_value; } else if (m_type == InputType.MouseAxis) { if (m_rawAxisName != null) { axis = Input.GetAxis(m_rawAxisName) * m_sensitivity; axis = m_invert ? -axis : axis; } } else if (m_type == InputType.AnalogAxis) { if (m_rawAxisName != null) { axis = Input.GetAxis(m_rawAxisName); if (Mathf.Abs(axis.Value) < m_deadZone) { axis = AXIS_NEUTRAL; } axis = Mathf.Clamp(axis.Value * m_sensitivity, -1, 1); axis = m_invert ? -axis : axis; } } else if (m_type == InputType.GamepadAxis) { axis = GamepadState.GetAxis(m_gamepadAxis, m_gamepadIndex); if (Mathf.Abs(axis.Value) < m_deadZone) { axis = AXIS_NEUTRAL; } axis = Mathf.Clamp(axis.Value * m_sensitivity, -1, 1); axis = m_invert ? -axis : axis; } if (axis.HasValue && Mathf.Abs(axis.Value) <= 0.0f) { axis = null; } return(axis); }
public void OnAfterUpdate() { Profiler.BeginSample("DeviceChangeService.OnAfterUpdate"); if (CurrentDevice == InputDevice.KeyboardAndMouse && GamepadState.AnyInput()) { CurrentDevice = InputDevice.Gamepad; if (m_deviceChangedHandler != null) { m_deviceChangedHandler(CurrentDevice); } } else if (CurrentDevice == InputDevice.Gamepad && KeyboardState.AnyInput()) { CurrentDevice = InputDevice.KeyboardAndMouse; if (m_deviceChangedHandler != null) { m_deviceChangedHandler(CurrentDevice); } } Profiler.EndSample(); }
///<summary> /// Returns raw input with no sensitivity or smoothing applyed. /// </summary> public float?GetAxisRaw() { float?axis = null; if (m_type == InputType.DigitalAxis) { if (Input.GetKey(m_positive)) { axis = m_invert ? -AXIS_POSITIVE : AXIS_POSITIVE; } else if (Input.GetKey(m_negative)) { axis = m_invert ? -AXIS_NEGATIVE : AXIS_NEGATIVE; } } else if (m_type == InputType.MouseAxis || m_type == InputType.AnalogAxis) { if (m_rawAxisName != null) { axis = Input.GetAxisRaw(m_rawAxisName); axis = m_invert ? -axis : axis; } } else if (m_type == InputType.GamepadAxis) { axis = GamepadState.GetAxisRaw(m_gamepadAxis, m_gamepadIndex); axis = m_invert ? -axis : axis; } if (axis.HasValue && Mathf.Abs(axis.Value) <= 0.0f) { axis = null; } return(axis); }