public override bool GetInput(IInputMap inputMap)
        {
            KeyboardMap map = inputMap as KeyboardMap;

            if (map == null)
            {
                return(false);
            }

            if (!CheckDesiredModifierKeysActive(map.modifiers))
            {
                return(false);
            }

            if (map.modifiers == ModifierKeys.None && map.keys.Count <= 0)
            {
                return(false);
            }

            foreach (KeyCode keyCode in map.keys)
            {
                if (!CheckKey(keyCode, inputGetFn))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        public IInputMap Clone()
        {
            KeyboardMap clone = new KeyboardMap();

            clone.modifiers = modifiers;
            clone.keys.AddRange(keys);

            return(clone);
        }
        public float?GetAxis(IInputMap inputMap)
        {
            KeyboardMap map = inputMap as KeyboardMap;

            if (map == null)
            {
                return(null);
            }

            return(GetInput(inputMap) ? (float?)1.0f : null);
        }
Exemplo n.º 4
0
        public bool SetFrom(IInputMap that)
        {
            KeyboardMap kbCast = that as KeyboardMap;

            if (kbCast == null)
            {
                Debug.LogError("Type incompatibility when trying to call SetFrom on a keyboard input map");
                return(false);
            }

            modifiers = kbCast.modifiers;
            keys.Clear();
            keys.AddRange(kbCast.keys);

            return(true);
        }
Exemplo n.º 5
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 override bool GetInputUp(IInputMap inputMap)
        {
            KeyboardMap map = inputMap as KeyboardMap;

            if (map == null)
            {
                return(false);
            }

            if (!CheckDesiredModifierKeysActive(map.modifiers))
            {
                return(false);
            }

            if (map.modifiers == ModifierKeys.None && map.keys.Count <= 0)
            {
                return(false);
            }

            // Look for at least 1 key that is coming up. The rest just need to be pressed
            bool hasInputDir = false;

            foreach (KeyCode keyCode in map.keys)
            {
                if (!CheckKey(keyCode, inputUpFn))
                {
                    if (!CheckKey(keyCode, inputGetFn))
                    {
                        return(false);
                    }
                }
                else
                {
                    hasInputDir = true;
                }
            }

            return(hasInputDir);
        }
            public void Add(IInputMap map)
            {
                KeyboardMap kbMap = map as KeyboardMap;

                if (kbMap != null)
                {
                    kbMaps.Add(kbMap);
                }

                GamepadMap gpButtonMap = map as GamepadMap;

                if (gpButtonMap != null)
                {
                    gpButtonMaps.Add(gpButtonMap);
                }

                JoystickMap jsButtonMap = map as JoystickMap;

                if (jsButtonMap != null)
                {
                    jsMaps.Add(jsButtonMap);
                }
            }
        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);
        }