internal InputManagerBase(IServiceRegistry registry) : base(registry) { Enabled = true; gamePads = new GamePad[MaximumGamePadCount]; gamePadStates = new GamePadState[MaximumGamePadCount]; KeyDown = downKeysList; KeyEvents = new List <KeyEvent>(); PointerEvents = currentPointerEvents; GestureEvents = currentGestureEvents; ActivatedGestures = new GestureConfigCollection(); ActivatedGestures.CollectionChanged += ActivatedGesturesChanged; Services.AddService(typeof(InputManager), this); Accelerometer = new AccelerometerSensor(); Compass = new CompassSensor(); Gyroscope = new GyroscopeSensor(); UserAcceleration = new UserAccelerationSensor(); Gravity = new GravitySensor(); Orientation = new OrientationSensor(); Sensors.Add(Accelerometer); Sensors.Add(Compass); Sensors.Add(Gyroscope); Sensors.Add(UserAcceleration); Sensors.Add(Gravity); Sensors.Add(Orientation); supportedGamePadButtons.Add(GamePadButton.A); supportedGamePadButtons.Add(GamePadButton.B); supportedGamePadButtons.Add(GamePadButton.X); supportedGamePadButtons.Add(GamePadButton.Y); supportedGamePadButtons.Add(GamePadButton.Start); supportedGamePadButtons.Add(GamePadButton.Back); supportedGamePadButtons.Add(GamePadButton.LeftShoulder); supportedGamePadButtons.Add(GamePadButton.RightShoulder); supportedGamePadButtons.Add(GamePadButton.RightThumb); supportedGamePadButtons.Add(GamePadButton.LeftThumb); supportedGamePadButtons.Add(GamePadButton.PadUp); supportedGamePadButtons.Add(GamePadButton.PadDown); supportedGamePadButtons.Add(GamePadButton.PadLeft); supportedGamePadButtons.Add(GamePadButton.PadRight); for (var i = 0; i < MaximumGamePadCount; i++) { pressedGamePadButtonsSet[i] = new HashSet <GamePadButton>(); releasedGamePadButtonsSet[i] = new HashSet <GamePadButton>(); currentGamePadButtonsSet[i] = new HashSet <GamePadButton>(); activeGamePadButtonsSet[i] = new HashSet <GamePadButton>(); } }
public override void Initialize(InputManager inputManager) { var context = inputManager.Game.Context as GameContextiOS; var uiControl = context.Control; var gameController = context.Control.GameViewController; pointer = new PointeriOS(this, uiControl, gameController); RegisterDevice(pointer); // Create sensor managers motionManager = new CMMotionManager(); locationManager = new CLLocationManager(); // Set desired sensor sampling intervals double updateInterval = 1 / InputManager.DesiredSensorUpdateRate; motionManager.AccelerometerUpdateInterval = updateInterval; motionManager.GyroUpdateInterval = updateInterval; motionManager.DeviceMotionUpdateInterval = updateInterval; // Determine supported sensors if (motionManager.AccelerometerAvailable) { accelerometerSensor = new AccelerometerSensor(this, "iOS"); RegisterDevice(accelerometerSensor); } if (CLLocationManager.HeadingAvailable) { compassSensor = new CompassSensor(this, "iOS"); RegisterDevice(compassSensor); } if (motionManager.GyroAvailable) { gyroscopeSensor = new GyroscopeSensor(this, "iOS"); RegisterDevice(gyroscopeSensor); } if (motionManager.DeviceMotionAvailable) { gravitySensor = new GravitySensor(this, "iOS"); userAccelerationSensor = new UserAccelerationSensor(this, "iOS"); orientationSensor = new OrientationSensor(this, "iOS"); RegisterDevice(gravitySensor); RegisterDevice(userAccelerationSensor); RegisterDevice(orientationSensor); } }
public override void Initialize(InputManager inputManager) { var context = inputManager.Game.Context as GameContextAndroid; uiControl = context.Control; // Create android pointer and keyboard keyboard = new KeyboardAndroid(this, uiControl); pointer = new PointerAndroid(this, uiControl); RegisterDevice(keyboard); RegisterDevice(pointer); // Create android sensors if ((accelerometerListener = TryGetSensorListener(SensorType.Accelerometer)) != null) { accelerometerSensor = new AccelerometerSensor(this, "Android"); RegisterDevice(accelerometerSensor); } if ((linearAccelerationListener = TryGetSensorListener(SensorType.LinearAcceleration)) != null) { userAccelerationSensor = new UserAccelerationSensor(this, "Android"); RegisterDevice(userAccelerationSensor); } if ((gyroscopeListener = TryGetSensorListener(SensorType.Gyroscope)) != null) { gyroscopeSensor = new GyroscopeSensor(this, "Android"); RegisterDevice(gyroscopeSensor); } if ((gravityListener = TryGetSensorListener(SensorType.Gravity)) != null) { gravitySensor = new GravitySensor(this, "Android"); RegisterDevice(gravitySensor); } if ((orientationListener = TryGetSensorListener(SensorType.RotationVector)) != null) { orientationSensor = new OrientationSensor(this, "Android"); compassSensor = new CompassSensor(this, "Android"); RegisterDevice(orientationSensor); RegisterDevice(compassSensor); } }
public override void Initialize(InputManager inputManager) { var nativeWindow = inputManager.Game.Window.NativeWindow; CoreWindow coreWindow; if (nativeWindow.Context == AppContextType.UWPCoreWindow) { coreWindow = (CoreWindow)nativeWindow.NativeWindow; } else if (nativeWindow.Context == AppContextType.UWPXaml) { coreWindow = Window.Current.CoreWindow; } else { throw new ArgumentException(string.Format("WindowContext [{0}] not supported", nativeWindow.Context)); } var mouseCapabilities = new MouseCapabilities(); if (mouseCapabilities.MousePresent > 0) { pointer = new MouseUWP(this, coreWindow); RegisterDevice(pointer); } var keyboardCapabilities = new KeyboardCapabilities(); if (keyboardCapabilities.KeyboardPresent > 0) { keyboard = new KeyboardUWP(this, coreWindow); RegisterDevice(keyboard); } // get sensor default instances windowsAccelerometer = WindowsAccelerometer.GetDefault(); if (windowsAccelerometer != null) { accelerometer = new AccelerometerSensor(this, "UWP"); RegisterDevice(accelerometer); } windowsCompass = WindowsCompass.GetDefault(); if (windowsCompass != null) { compass = new CompassSensor(this, "UWP"); RegisterDevice(compass); } windowsGyroscope = WindowsGyroscope.GetDefault(); if (windowsGyroscope != null) { gyroscope = new GyroscopeSensor(this, "UWP"); RegisterDevice(gyroscope); } windowsOrientation = WindowsOrientation.GetDefault(); if (windowsOrientation != null) { orientation = new OrientationSensor(this, "UWP"); RegisterDevice(orientation); } // Virtual sensors if (windowsOrientation != null && windowsAccelerometer != null) { gravity = new GravitySensor(this, "UWP"); userAcceleration = new UserAccelerationSensor(this, "UWP"); RegisterDevice(gravity); RegisterDevice(userAcceleration); } Gamepad.GamepadAdded += GamepadOnGamepadAdded; Gamepad.GamepadRemoved += GamepadOnGamepadRemoved; Scan(); }