예제 #1
0
        // TODO: Maybe reduce it to only the inputs actually used in the game?
        private void MapPlayerInput(InputMapper inputMapper, GamePadState state, GamePadState previousState)
        {
            foreach (int axisInt in InputMapperAsset.GetMappedXboxAxis())
            {
                MapXboxAxis(axisInt, inputMapper, state);
            }

            foreach (int buttonInt in InputMapperAsset.GetMappedXboxButtons())
            {
                MapXboxButton(buttonInt, inputMapper, state, previousState);
            }

            // TODO: Put the following code into another class, so we can have 2 distinct XboxManager and KeyboardManager classes

            // We map only the keyboard keys that are going to be used in the game

            foreach (int key in InputMapperAsset.GetMappedKeyboardKeys())
            {
                inputMapper.SetRawButtonState(100 + key, Input.GetKey((KeyCode)key), Input.GetKey((KeyCode)key) && !Input.GetKeyDown((KeyCode)key));
            }

            foreach (int key in InputMapperAsset.GetMappedKeyboardKeysAxis())
            {
                float value = Input.GetKey((KeyCode)key) ? 1f : 0f;

                inputMapper.SetRawAxisValue(100 + key, value);
            }
        }
        // TODO: Maybe reduce it to only the inputs actually used in the game?
        private void MapPlayerInput(InputMapper inputMapper, GamePadState state, GamePadState previousState)
        {
            foreach (int axisInt in InputMapperAsset.GetMappedXboxAxis())
            {
                MapXboxAxis(axisInt, inputMapper, state);
            }

            foreach (int buttonInt in InputMapperAsset.GetMappedXboxButtons())
            {
                MapXboxButton(buttonInt, inputMapper, state, previousState);
            }

            // TODO: Put the following code into another class, so we can have 2 distinct XboxManager and KeyboardManager classes

            // We map only the keyboard keys that are going to be used in the game

            foreach (int key in InputMapperAsset.GetMappedKeyboardKeys())
            {
                inputMapper.SetRawButtonState(100 + key, Input.GetKey((KeyCode)key), Input.GetKey((KeyCode)key) && !Input.GetKeyDown((KeyCode)key));
            }

            foreach (int key in InputMapperAsset.GetMappedKeyboardKeysAxis())
            {
                float value = Input.GetKey((KeyCode)key) ? 1f : 0f;

                inputMapper.SetRawAxisValue(100 + key, value);
            }
        }
예제 #3
0
        private void MapXboxAxis(int axisInt, InputMapper inputMapper, GamePadState state)
        {
            XboxInputConstants.Axis axis = (XboxInputConstants.Axis)axisInt;

            float value = 0f;

            switch (axis)
            {
            case XboxInputConstants.Axis.LeftStickLeft:
                // If the left stick X value is negative, we keep it and take its absolute value
                value = state.ThumbSticks.Left.X < 0f ? -state.ThumbSticks.Left.X : 0f;
                break;

            case XboxInputConstants.Axis.LeftStickRight:
                // If the left stick X value is positive, we keep it
                value = state.ThumbSticks.Left.X > 0f ? state.ThumbSticks.Left.X : 0f;
                break;

            case XboxInputConstants.Axis.LeftStickDown:
                value = state.ThumbSticks.Left.Y < 0f ? -state.ThumbSticks.Left.Y : 0f;
                break;

            case XboxInputConstants.Axis.LeftStickUp:
                value = state.ThumbSticks.Left.Y > 0f ? state.ThumbSticks.Left.Y : 0f;
                break;

            case XboxInputConstants.Axis.RightStickLeft:
                value = state.ThumbSticks.Right.X < 0f ? -state.ThumbSticks.Right.X : 0f;
                break;

            case XboxInputConstants.Axis.RightStickRight:
                value = state.ThumbSticks.Right.X > 0f ? state.ThumbSticks.Right.X : 0f;
                break;

            case XboxInputConstants.Axis.RightStickDown:
                value = state.ThumbSticks.Right.Y < 0f ? -state.ThumbSticks.Right.Y : 0f;
                break;

            case XboxInputConstants.Axis.RightStickUp:
                value = state.ThumbSticks.Right.Y > 0f ? state.ThumbSticks.Right.Y : 0f;
                break;

            case XboxInputConstants.Axis.TriggerLeft:
                value = state.Triggers.Left;
                break;

            case XboxInputConstants.Axis.TriggerRight:
                value = state.Triggers.Right;
                break;
            }

            inputMapper.SetRawAxisValue(axisInt, value);
        }
        private void MapXboxAxis(int axisInt, InputMapper inputMapper, GamePadState state)
        {
            XboxInputConstants.Axis axis = (XboxInputConstants.Axis)axisInt;

            float value = 0f;

            switch (axis)
            {
                case XboxInputConstants.Axis.LeftStickLeft:
                    // If the left stick X value is negative, we keep it and take its absolute value
                    value = state.ThumbSticks.Left.X < 0f ? -state.ThumbSticks.Left.X : 0f;
                    break;
                case XboxInputConstants.Axis.LeftStickRight:
                    // If the left stick X value is positive, we keep it
                    value = state.ThumbSticks.Left.X > 0f ? state.ThumbSticks.Left.X : 0f;
                    break;
                case XboxInputConstants.Axis.LeftStickDown:
                    value = state.ThumbSticks.Left.Y < 0f ? -state.ThumbSticks.Left.Y : 0f;
                    break;
                case XboxInputConstants.Axis.LeftStickUp:
                    value = state.ThumbSticks.Left.Y > 0f ? state.ThumbSticks.Left.Y : 0f;
                    break;
                case XboxInputConstants.Axis.RightStickLeft:
                    value = state.ThumbSticks.Right.X < 0f ? -state.ThumbSticks.Right.X : 0f;
                    break;
                case XboxInputConstants.Axis.RightStickRight:
                    value = state.ThumbSticks.Right.X > 0f ? state.ThumbSticks.Right.X : 0f;
                    break;
                case XboxInputConstants.Axis.RightStickDown:
                    value = state.ThumbSticks.Right.Y < 0f ? -state.ThumbSticks.Right.Y : 0f;
                    break;
                case XboxInputConstants.Axis.RightStickUp:
                    value = state.ThumbSticks.Right.Y > 0f ? state.ThumbSticks.Right.Y : 0f;
                    break;
                case XboxInputConstants.Axis.TriggerLeft:
                    value = state.Triggers.Left;
                    break;
                case XboxInputConstants.Axis.TriggerRight:
                    value = state.Triggers.Right;
                    break;
            }

            inputMapper.SetRawAxisValue(axisInt, value);
        }