public IInputMap GetCurrentInput(InputAction.Properties properties)
            {
                foreach (Button button in EnumX <Button> .Values)
                {
                    if (GetButton(button))
                    {
                        return(new GamepadMap()
                        {
                            button
                        });
                    }
                }

                foreach (Axis axis in EnumX <Axis> .Values)
                {
                    float axisVal         = GetAxis(axis);
                    float previousAxisVal = GetPreviousAxis(axis);

                    if (Mathf.Abs(axisVal - previousAxisVal) > kRebindIntendedDeltaInputThreshold && Mathf.Abs(axisVal) > kRebindIntendedInputThreshold)
                    {
                        AxisDir dir = properties.anyDirectionAxis ? AxisDir.Any :
                                      (axisVal > 0 ? AxisDir.Positive : AxisDir.Negative);

                        return(new GamepadMap()
                        {
                            { axis, dir }
                        });
                    }
                }

                return(null);
            }
            public IInputMap GetCurrentInput(InputAction.Properties properties)
            {
                // Check buttons
                {
                    bool          allowMultiInput = properties.allowSameFrameMultiInput;
                    List <Button> buttons         = new List <Button>();

                    foreach (Button button in EnumX <Button> .Values)
                    {
                        if (GetButton(button))
                        {
                            buttons.Add(button);

                            if (!allowMultiInput)
                            {
                                break;
                            }
                        }
                    }

                    if (buttons.Count > 0)
                    {
                        return(new GamepadMap()
                        {
                            buttons
                        });
                    }
                }

                foreach (Axis axis in EnumX <Axis> .Values)
                {
                    float axisVal         = GetAxis(axis);
                    float previousAxisVal = GetPreviousAxis(axis);

                    if (Mathf.Abs(axisVal - previousAxisVal) > kRebindIntendedDeltaInputThreshold && Mathf.Abs(axisVal) > kRebindIntendedInputThreshold)
                    {
                        AxisDir dir = properties.anyDirectionAxis ? AxisDir.Any :
                                      (axisVal > 0 ? AxisDir.Positive : AxisDir.Negative);

                        return(new GamepadMap()
                        {
                            { axis, dir }
                        });
                    }
                }

                return(null);
            }
Exemplo n.º 3
0
            public bool HasConflict(IInputMap other, InputAction.Properties properties)
            {
                KeyboardMap otherKbMap = other as KeyboardMap;

                if (otherKbMap == null || otherKbMap.IsEmpty)
                {
                    return(false);
                }

                KeyboardDevice.ModifierKeys manualModifierKeysPressed = KeyboardDevice.ModifierKeys.None;
                foreach (KeyCode otherKeyCode in otherKbMap.keys)
                {
                    manualModifierKeysPressed |= KeyboardDevice.ToModifierKey(otherKeyCode);
                }

                if (keys.Count <= 0 && modifiers == manualModifierKeysPressed && modifiers != KeyboardDevice.ModifierKeys.None)
                {
                    return(true);
                }

                if (modifiers != otherKbMap.modifiers)
                {
                    return(false);
                }

                foreach (KeyCode keyCode in keys)
                {
                    foreach (KeyCode otherKeyCode in otherKbMap.keys)
                    {
                        bool modifierKeyConflict = (KeyboardDevice.ToModifierKey(keyCode) & otherKbMap.modifiers) != 0;

                        if (modifierKeyConflict || keyCode == otherKeyCode)
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
            public IInputMap GetCurrentInput(InputAction.Properties properties)
            {
                currentKeys.Clear();
                releasedModifierKeys.Clear();

                ModifierKeys modifiersActive        = ModifierKeys.None;
                bool         containsNonModifierKey = false;

                foreach (KeyCode kCode in EnumX <KeyCode> .Values)
                {
                    if ((int)kCode >= (int)KeyCode.Menu)
                    {
                        break;
                    }

                    bool isModifierKey = IsModifierKey(kCode);
                    if (UnityEngine.Input.GetKey(kCode))
                    {
                        currentKeys.Add(kCode);
                        modifiersActive |= ToModifierKey(kCode);

                        if (!isModifierKey)
                        {
                            containsNonModifierKey = true;
                        }
                    }

                    if (isModifierKey && UnityEngine.Input.GetKeyUp(kCode))
                    {
                        releasedModifierKeys.Add(kCode);
                    }
                }

                // Create map if no modifier keys are active, or if they are, they are released or have another input with it
                if (currentKeys.Count > 0 && containsNonModifierKey)
                {
                    KeyboardMap map = new KeyboardMap(modifiersActive);

                    foreach (KeyCode kCode in currentKeys)
                    {
                        if (!IsModifierKey(kCode))
                        {
                            map.Add(kCode);
                        }
                    }

                    return(map);
                }

                // If we wanted to use modifier keys as regular keys
                if (currentKeys.Count <= 0 && releasedModifierKeys.Count == 1)
                {
                    KeyboardMap map = new KeyboardMap(ModifierKeys.None);

                    foreach (KeyCode kCode in releasedModifierKeys)
                    {
                        map.Add(kCode);
                    }

                    return(map);
                }

                return(null);
            }
            public bool HasConflict(IInputMap other, InputAction.Properties properties)
            {
                GamepadMap otherGpMap = other as GamepadMap;

                if (otherGpMap == null || otherGpMap.IsEmpty)
                {
                    return(false);
                }

                bool allowSameFrameMultiInput = properties.allowSameFrameMultiInput;

                if (allowSameFrameMultiInput)
                {
                    if (buttons.Count > 0 && otherGpMap.buttons.Count > 0)
                    {
                        // Check if they match exactly, or if one map is a sub-set of the other
                        var smallerButtonMap = buttons.Count < otherGpMap.buttons.Count ? buttons : otherGpMap.buttons;
                        var largerButtonMap  = buttons.Count < otherGpMap.buttons.Count ? otherGpMap.buttons : buttons;

                        int sameInputCount = 0;
                        foreach (var button in smallerButtonMap)
                        {
                            if (largerButtonMap.Contains(button))
                            {
                                ++sameInputCount;
                            }
                        }

                        if (sameInputCount == smallerButtonMap.Count)
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    foreach (var button in buttons)
                    {
                        foreach (var otherButton in otherGpMap.buttons)
                        {
                            if (button == otherButton)
                            {
                                return(true);
                            }
                        }
                    }
                }

                foreach (var axis in axes)
                {
                    foreach (var otherAxis in otherGpMap.axes)
                    {
                        if (axis.axis == otherAxis.axis && (axis.dir == otherAxis.dir || axis.dir == GamepadDevice.AxisDir.Any || otherAxis.dir == GamepadDevice.AxisDir.Any))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
            public bool HasConflict(IInputMap other, InputAction.Properties properties)
            {
                JoystickMap otherMap = other as JoystickMap;

                if (otherMap == null || otherMap.IsEmpty)
                {
                    return(false);
                }

                bool allowSameFrameMultiInput = properties.allowSameFrameMultiInput;

                if (allowSameFrameMultiInput)
                {
                    if (buttons.Count > 0 && otherMap.buttons.Count > 0)
                    {
                        // Check if they match exactly, or if one map is a sub-set of the other
                        var smallerButtonMap = buttons.Count < otherMap.buttons.Count ? buttons : otherMap.buttons;
                        var largerButtonMap  = buttons.Count < otherMap.buttons.Count ? otherMap.buttons : buttons;

                        int sameInputCount = 0;
                        foreach (var button in smallerButtonMap)
                        {
                            bool contains = false;
                            foreach (var otherButton in largerButtonMap)
                            {
                                if (button.buttonIndex == otherButton.buttonIndex)
                                {
                                    contains = true;
                                    break;
                                }
                            }

                            if (contains)
                            {
                                ++sameInputCount;
                            }
                        }

                        if (sameInputCount == smallerButtonMap.Count)
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    foreach (var button in buttons)
                    {
                        foreach (var otherButton in otherMap.buttons)
                        {
                            if (button.buttonIndex == otherButton.buttonIndex)
                            {
                                return(true);
                            }
                        }
                    }
                }

                foreach (var axis in axes)
                {
                    foreach (var otherAxis in otherMap.axes)
                    {
                        if (axis.axisIndex == otherAxis.axisIndex && (axis.dir == otherAxis.dir || axis.dir == JoystickDevice.AxisDir.Any || otherAxis.dir == JoystickDevice.AxisDir.Any))
                        {
                            return(true);
                        }
                    }
                }

                foreach (var ballIndex in balls)
                {
                    foreach (var otherBallIndex in otherMap.balls)
                    {
                        if (ballIndex.ballIndex == otherBallIndex.ballIndex)
                        {
                            return(true);
                        }
                    }
                }

                foreach (var hat in hats)
                {
                    foreach (var otherHat in otherMap.hats)
                    {
                        if (hat.hatIndex == otherHat.hatIndex && hat.position == otherHat.position)
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }