public void RaiseXboxInputUpdate(IInputSource source, uint sourceId, XboxControllerData inputData) { // Create input event xboxControllerEventData.Initialize(source, sourceId, inputData); // Pass handler through HandleEvent to perform modal/fallback logic HandleEvent(xboxControllerEventData, OnXboxAxisUpdateHandler); }
public void Initialize(IInputSource inputSource, uint sourceId, XboxControllerData inputData, object tag = null) { BaseInitialize(inputSource, sourceId, tag); GamePadName = inputData.GamePadName; XboxLeftStickHorizontalAxis = inputData.XboxLeftStickHorizontalAxis; XboxLeftStickVerticalAxis = inputData.XboxLeftStickVerticalAxis; XboxRightStickHorizontalAxis = inputData.XboxRightStickHorizontalAxis; XboxRightStickVerticalAxis = inputData.XboxRightStickVerticalAxis; XboxDpadHorizontalAxis = inputData.XboxDpadHorizontalAxis; XboxDpadVerticalAxis = inputData.XboxDpadVerticalAxis; XboxLeftTriggerAxis = inputData.XboxLeftTriggerAxis; XboxRightTriggerAxis = inputData.XboxRightTriggerAxis; XboxSharedTriggerAxis = inputData.XboxSharedTriggerAxis; XboxA_Down = inputData.XboxA_Down; XboxB_Down = inputData.XboxB_Down; XboxX_Down = inputData.XboxX_Down; XboxY_Down = inputData.XboxY_Down; XboxLeftBumper_Down = inputData.XboxLeftBumper_Down; XboxRightBumper_Down = inputData.XboxRightBumper_Down; XboxLeftStick_Down = inputData.XboxLeftStick_Down; XboxRightStick_Down = inputData.XboxRightStick_Down; XboxView_Down = inputData.XboxView_Down; XboxMenu_Down = inputData.XboxMenu_Down; XboxA_Pressed = inputData.XboxA_Pressed; XboxB_Pressed = inputData.XboxB_Pressed; XboxX_Pressed = inputData.XboxX_Pressed; XboxY_Pressed = inputData.XboxY_Pressed; XboxLeftBumper_Pressed = inputData.XboxLeftBumper_Pressed; XboxRightBumper_Pressed = inputData.XboxRightBumper_Pressed; XboxLeftStick_Pressed = inputData.XboxLeftStick_Pressed; XboxRightStick_Pressed = inputData.XboxRightStick_Pressed; XboxView_Pressed = inputData.XboxView_Pressed; XboxMenu_Pressed = inputData.XboxMenu_Pressed; XboxA_Up = inputData.XboxA_Up; XboxB_Up = inputData.XboxB_Up; XboxX_Up = inputData.XboxX_Up; XboxY_Up = inputData.XboxY_Up; XboxLeftBumper_Up = inputData.XboxLeftBumper_Up; XboxRightBumper_Up = inputData.XboxRightBumper_Up; XboxLeftStick_Up = inputData.XboxLeftStick_Up; XboxRightStick_Up = inputData.XboxRightStick_Up; XboxView_Up = inputData.XboxView_Up; XboxMenu_Up = inputData.XboxMenu_Up; }
protected override void RefreshDevices() { var joystickNames = Input.GetJoystickNames(); if (joystickNames.Length <= 0) { return; } bool devicesChanged = LastDeviceList == null; if (LastDeviceList != null && joystickNames.Length == LastDeviceList.Length) { for (int i = 0; i < LastDeviceList.Length; i++) { if (!joystickNames[i].Equals(LastDeviceList[i])) { devicesChanged = true; if (LastDeviceList == null) { LastDeviceList = joystickNames; } } } } if (LastDeviceList != null && devicesChanged) { foreach (var gamePadInputSource in gamePadInputDatas) { InputManager.Instance.RaiseSourceLost(this, gamePadInputSource.Key); } gamePadInputDatas.Clear(); if (gamePadInputDatas.Count == 0) { // Reset our input module to it's previous state. InputModule.forceModuleActive = PreviousForceActiveState; InputModule.verticalAxis = PreviousVerticalAxis; InputModule.horizontalAxis = PreviousHorizontalAxis; InputModule.submitButton = PreviousSubmitButton; InputModule.cancelButton = PreviousCancelButton; } } motionControllerCount = 0; for (var i = 0; i < joystickNames.Length; i++) { if (joystickNames[i].Contains(MotionControllerLeft) || joystickNames[i].Contains(MotionControllerRight)) { // If we don't have any matching joystick types, continue. // If we have motion controllers connected we override the xbox input. motionControllerCount++; continue; } if (joystickNames[i].Contains(XboxController) || joystickNames[i].Contains(XboxOneForWindows) || joystickNames[i].Contains(XboxBluetoothGamePad) || joystickNames[i].Contains(XboxWirelessController)) { // We will only register the first device we find. Input is taken from all joysticks. if (gamePadInputDatas.Count != 0) { return; } SourceId = (uint)i; controllerData = new XboxControllerData { GamePadName = joystickNames[i] }; gamePadInputDatas.Add(SourceId, controllerData); InputManager.Instance.RaiseSourceDetected(this, SourceId); // Setup the Input Module to use our custom axis settings. InputModule.forceModuleActive = true; if (verticalAxis != XboxControllerMappingTypes.None) { InputModule.verticalAxis = XboxControllerMapping.GetMapping(verticalAxis); } if (horizontalAxis != XboxControllerMappingTypes.None) { InputModule.horizontalAxis = XboxControllerMapping.GetMapping(horizontalAxis); } if (submitButton != XboxControllerMappingTypes.None) { InputModule.submitButton = XboxControllerMapping.GetMapping(submitButton); } if (cancelButton != XboxControllerMappingTypes.None) { InputModule.cancelButton = XboxControllerMapping.GetMapping(cancelButton); } } } LastDeviceList = joystickNames; LastDeviceUpdateCount = joystickNames.Length; }
protected override void RefreshDevices() { var joystickNames = Input.GetJoystickNames(); if (joystickNames.Length <= 0) { return; } bool devicesChanged = LastDeviceList == null; if (LastDeviceList != null && joystickNames.Length == LastDeviceList.Length) { for (int i = 0; i < LastDeviceList.Length; i++) { if (!joystickNames[i].Equals(LastDeviceList[i])) { devicesChanged = true; if (LastDeviceList == null) { LastDeviceList = joystickNames; } } } } if (LastDeviceList != null && devicesChanged) { foreach (var gamePadInputSource in gamePadInputDatas) { // Reset our input module to it's previous state. inputModule.forceModuleActive = previousForceActiveState; inputModule.verticalAxis = previousVerticalAxis; inputModule.horizontalAxis = previousHorizontalAxis; inputModule.submitButton = previousSubmitButton; inputModule.cancelButton = previousCancelButton; InputManager.Instance.RaiseGamePadLost(this, gamePadInputSource.Key, LastDeviceList[gamePadInputSource.Key]); } gamePadInputDatas.Clear(); } for (var i = 0; i < joystickNames.Length; i++) { if (string.IsNullOrEmpty(joystickNames[i]) || gamePadInputDatas.ContainsKey((uint)i)) { continue; } if (joystickNames[i].Contains(XboxController) || joystickNames[i].Contains(XboxOneForWindows) || joystickNames[i].Contains(XboxBluetoothGamePad) || joystickNames[i].Contains(XboxWirelessController)) { // We will only register the first device we find. Input is taken from all joysticks. if (gamePadInputDatas.Count != 0) { return; } sourceId = (uint)i; controllerData = new XboxControllerData(); gamePadInputDatas.Add(sourceId, controllerData); // Setup the Input Module to use our custom axis settings. inputModule.forceModuleActive = true; inputModule.verticalAxis = XboxControllerMapping.GetMapping(verticalAxis); inputModule.horizontalAxis = XboxControllerMapping.GetMapping(horizontalAxis); inputModule.submitButton = XboxControllerMapping.GetMapping(submitButton); inputModule.cancelButton = XboxControllerMapping.GetMapping(cancelButton); InputManager.Instance.RaiseGamePadDetected(this, sourceId, joystickNames[i]); } else { Debug.LogWarning("Unimplemented Controller type Detected: " + joystickNames[i]); } } LastDeviceList = joystickNames; LastDeviceUpdateCount = joystickNames.Length; }