public virtual ControllerType Update()
        {
            OVRPlugin.InputState state = OVRPlugin.GetInputState((uint)controllerType);

            if (state.LIndexTrigger >= AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.LIndexTrigger;
            if (state.LHandTrigger >= AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.LHandTrigger;
            if (state.LThumbstick.y >= AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.LThumbstickUp;
            if (state.LThumbstick.y <= -AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.LThumbstickDown;
            if (state.LThumbstick.x <= -AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.LThumbstickLeft;
            if (state.LThumbstick.x >= AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.LThumbstickRight;

            if (state.RIndexTrigger >= AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.RIndexTrigger;
            if (state.RHandTrigger >= AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.RHandTrigger;
            if (state.RThumbstick.y >= AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.RThumbstickUp;
            if (state.RThumbstick.y <= -AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.RThumbstickDown;
            if (state.RThumbstick.x <= -AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.RThumbstickLeft;
            if (state.RThumbstick.x >= AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.RThumbstickRight;

            previousInputState = currentInputState;
            currentInputState = state;

            return ((ControllerType)currentInputState.ConnectedControllerTypes & controllerType);
        }
        public override ControllerType Update()
        {
            if (!initialized || !ShouldUpdate())
            {
                return ControllerType.None;
            }

            OVRPlugin.InputState state = new OVRPlugin.InputState();

            bool result = OVR_GamepadController_Update();

            if (result)
                state.ConnectedControllerTypes = (uint)ControllerType.Xbox;

            if (OVR_GamepadController_GetButton((int)ButtonGPC.A))
                state.Buttons |= (uint)RawButton.A;
            if (OVR_GamepadController_GetButton((int)ButtonGPC.B))
                state.Buttons |= (uint)RawButton.B;
            if (OVR_GamepadController_GetButton((int)ButtonGPC.X))
                state.Buttons |= (uint)RawButton.X;
            if (OVR_GamepadController_GetButton((int)ButtonGPC.Y))
                state.Buttons |= (uint)RawButton.Y;
            if (OVR_GamepadController_GetButton((int)ButtonGPC.Up))
                state.Buttons |= (uint)RawButton.DpadUp;
            if (OVR_GamepadController_GetButton((int)ButtonGPC.Down))
                state.Buttons |= (uint)RawButton.DpadDown;
            if (OVR_GamepadController_GetButton((int)ButtonGPC.Left))
                state.Buttons |= (uint)RawButton.DpadLeft;
            if (OVR_GamepadController_GetButton((int)ButtonGPC.Right))
                state.Buttons |= (uint)RawButton.DpadRight;
            if (OVR_GamepadController_GetButton((int)ButtonGPC.Start))
                state.Buttons |= (uint)RawButton.Start;
            if (OVR_GamepadController_GetButton((int)ButtonGPC.Back))
                state.Buttons |= (uint)RawButton.Back;
            if (OVR_GamepadController_GetButton((int)ButtonGPC.LStick))
                state.Buttons |= (uint)RawButton.LThumbstick;
            if (OVR_GamepadController_GetButton((int)ButtonGPC.RStick))
                state.Buttons |= (uint)RawButton.RThumbstick;
            if (OVR_GamepadController_GetButton((int)ButtonGPC.LeftShoulder))
                state.Buttons |= (uint)RawButton.LShoulder;
            if (OVR_GamepadController_GetButton((int)ButtonGPC.RightShoulder))
                state.Buttons |= (uint)RawButton.RShoulder;

            state.LThumbstick.x = OVR_GamepadController_GetAxis((int)AxisGPC.LeftXAxis);
            state.LThumbstick.y = OVR_GamepadController_GetAxis((int)AxisGPC.LeftYAxis);
            state.RThumbstick.x = OVR_GamepadController_GetAxis((int)AxisGPC.RightXAxis);
            state.RThumbstick.y = OVR_GamepadController_GetAxis((int)AxisGPC.RightYAxis);
            state.LIndexTrigger = OVR_GamepadController_GetAxis((int)AxisGPC.LeftTrigger);
            state.RIndexTrigger = OVR_GamepadController_GetAxis((int)AxisGPC.RightTrigger);

            if (state.LIndexTrigger >= AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.LIndexTrigger;
            if (state.LHandTrigger >= AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.LHandTrigger;
            if (state.LThumbstick.y >= AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.LThumbstickUp;
            if (state.LThumbstick.y <= -AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.LThumbstickDown;
            if (state.LThumbstick.x <= -AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.LThumbstickLeft;
            if (state.LThumbstick.x >= AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.LThumbstickRight;

            if (state.RIndexTrigger >= AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.RIndexTrigger;
            if (state.RHandTrigger >= AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.RHandTrigger;
            if (state.RThumbstick.y >= AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.RThumbstickUp;
            if (state.RThumbstick.y <= -AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.RThumbstickDown;
            if (state.RThumbstick.x <= -AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.RThumbstickLeft;
            if (state.RThumbstick.x >= AXIS_AS_BUTTON_THRESHOLD)
                state.Buttons |= (uint)RawButton.RThumbstickRight;

            previousInputState = currentInputState;
            currentInputState = state;

            return ((ControllerType)currentInputState.ConnectedControllerTypes & controllerType);
        }
Example #3
0
		public override Controller Update()
		{
			if (!ShouldUpdate())
			{
				return Controller.None;
			}

			OVRPlugin.InputState state = new OVRPlugin.InputState();

			state.ConnectedControllers = (uint)Controller.Gamepad;

			if (Input.GetKey(AndroidButtonNames.A))
				state.Buttons |= (uint)RawButton.A;
			if (Input.GetKey(AndroidButtonNames.B))
				state.Buttons |= (uint)RawButton.B;
			if (Input.GetKey(AndroidButtonNames.X))
				state.Buttons |= (uint)RawButton.X;
			if (Input.GetKey(AndroidButtonNames.Y))
				state.Buttons |= (uint)RawButton.Y;
			if (Input.GetKey(AndroidButtonNames.Start))
				state.Buttons |= (uint)RawButton.Start;
			if (Input.GetKey(AndroidButtonNames.Back) || Input.GetKey(KeyCode.Escape))
				state.Buttons |= (uint)RawButton.Back;
			if (Input.GetKey(AndroidButtonNames.LThumbstick))
				state.Buttons |= (uint)RawButton.LThumbstick;
			if (Input.GetKey(AndroidButtonNames.RThumbstick))
				state.Buttons |= (uint)RawButton.RThumbstick;
			if (Input.GetKey(AndroidButtonNames.LShoulder))
				state.Buttons |= (uint)RawButton.LShoulder;
			if (Input.GetKey(AndroidButtonNames.RShoulder))
				state.Buttons |= (uint)RawButton.RShoulder;

			state.LThumbstick.x = Input.GetAxisRaw(AndroidAxisNames.LThumbstickX);
			state.LThumbstick.y = Input.GetAxisRaw(AndroidAxisNames.LThumbstickY);
			state.RThumbstick.x = Input.GetAxisRaw(AndroidAxisNames.RThumbstickX);
			state.RThumbstick.y = Input.GetAxisRaw(AndroidAxisNames.RThumbstickY);
			state.LIndexTrigger = Input.GetAxisRaw(AndroidAxisNames.LIndexTrigger);
			state.RIndexTrigger = Input.GetAxisRaw(AndroidAxisNames.RIndexTrigger);

			if (state.LIndexTrigger >= AXIS_AS_BUTTON_THRESHOLD)
				state.Buttons |= (uint)RawButton.LIndexTrigger;
			if (state.LHandTrigger >= AXIS_AS_BUTTON_THRESHOLD)
				state.Buttons |= (uint)RawButton.LHandTrigger;
			if (state.LThumbstick.y >= AXIS_AS_BUTTON_THRESHOLD)
				state.Buttons |= (uint)RawButton.LThumbstickUp;
			if (state.LThumbstick.y <= -AXIS_AS_BUTTON_THRESHOLD)
				state.Buttons |= (uint)RawButton.LThumbstickDown;
			if (state.LThumbstick.x <= -AXIS_AS_BUTTON_THRESHOLD)
				state.Buttons |= (uint)RawButton.LThumbstickLeft;
			if (state.LThumbstick.x >= AXIS_AS_BUTTON_THRESHOLD)
				state.Buttons |= (uint)RawButton.LThumbstickRight;

			if (state.RIndexTrigger >= AXIS_AS_BUTTON_THRESHOLD)
				state.Buttons |= (uint)RawButton.RIndexTrigger;
			if (state.RHandTrigger >= AXIS_AS_BUTTON_THRESHOLD)
				state.Buttons |= (uint)RawButton.RHandTrigger;
			if (state.RThumbstick.y >= AXIS_AS_BUTTON_THRESHOLD)
				state.Buttons |= (uint)RawButton.RThumbstickUp;
			if (state.RThumbstick.y <= -AXIS_AS_BUTTON_THRESHOLD)
				state.Buttons |= (uint)RawButton.RThumbstickDown;
			if (state.RThumbstick.x <= -AXIS_AS_BUTTON_THRESHOLD)
				state.Buttons |= (uint)RawButton.RThumbstickLeft;
			if (state.RThumbstick.x >= AXIS_AS_BUTTON_THRESHOLD)
				state.Buttons |= (uint)RawButton.RThumbstickRight;

			float dpadX = Input.GetAxisRaw(AndroidAxisNames.DpadX);
			float dpadY = Input.GetAxisRaw(AndroidAxisNames.DpadY);

			if (dpadX <= -AXIS_AS_BUTTON_THRESHOLD)
				state.Buttons |= (uint)RawButton.DpadLeft;
			if (dpadX >= AXIS_AS_BUTTON_THRESHOLD)
				state.Buttons |= (uint)RawButton.DpadRight;
			if (dpadY <= -AXIS_AS_BUTTON_THRESHOLD)
				state.Buttons |= (uint)RawButton.DpadDown;
			if (dpadY >= AXIS_AS_BUTTON_THRESHOLD)
				state.Buttons |= (uint)RawButton.DpadUp;

			previousInputState = currentInputState;
			currentInputState = state;

			return ((Controller)currentInputState.ConnectedControllers & controllerType);
		}