public override void Update(ulong updateTick, float deltaTime) { for (var deviceIndex = 0; deviceIndex < 4; deviceIndex++) { var device = devices[deviceIndex] as XInputDevice; // Unconnected devices won't be updated otherwise, so poll here. if (!device.IsConnected) { device.Update(updateTick, deltaTime); } if (device.IsConnected == _deviceConnected[deviceIndex]) { continue; } if (device.IsConnected) { HInput.AttachDevice(device); } else { HInput.DetachDevice(device); } _deviceConnected[deviceIndex] = device.IsConnected; } }
void DetectDetachedJoystickDevices() { string[] joystickNames = Input.GetJoystickNames(); for (int i = devices.Count - 1; i >= 0; i--) { var inputDevice = devices[i] as UnityInputDevice; if (inputDevice == null || !inputDevice.Profile.IsJoystick) { continue; } if (joystickNames.Length >= inputDevice.JoystickId && inputDevice.Profile.HasJoystickOrRegexName(joystickNames[inputDevice.JoystickId - 1])) { continue; } devices.Remove(inputDevice); HInput.DetachDevice(inputDevice); Log.Info("Detached device: {0}", inputDevice.Profile.Name); } }