Example #1
0
        public override void Initialize(InputManager inputManager)
        {
            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();
        }
Example #2
0
        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();
        }