示例#1
0
 public void AddBinding(InputButton button, InputTypes inputType) => InputBttnBindings.Add(button, inputType);
示例#2
0
        /// <summary>
        /// Checks the bindings to see if the action is triggered.
        /// </summary>
        /// <returns><c>true</c> if any of the bindings are active, <c>false</c> otherwise.</returns>
        public bool IsActionTriggered(out InputButton trigger)
        {
            // Prevents multiple toggles at once
            bool hasToggled = false;

            // InputButtons
            var iKs = InputBttnBindings?.Keys;

            if (iKs != null)
            {
                foreach (InputButton iBttn in iKs)
                {
                    // TODO: Implement Deadzone
                    switch (InputBttnBindings[iBttn])
                    {
                    case InputTypes.Toggle:
                        // If the key was pressed this frame & hasn't been toggled, switch the toggle.
                        if (inputManager.GetInputDown(iBttn) && !hasToggled)
                        {
                            IsToggledOn = !IsToggledOn;
                            hasToggled  = true;
                        }
                        if (IsToggledOn)
                        {
                            trigger = iBttn;
                            return(true);
                        }
                        break;

                    case InputTypes.OnPress:
                        if (inputManager.GetInputDown(iBttn))
                        {
                            trigger = iBttn;
                            return(true);
                        }
                        break;

                    case InputTypes.OnRelease:
                        if (inputManager.GetInputUp(iBttn))
                        {
                            trigger = iBttn;
                            return(true);
                        }
                        break;

                    case InputTypes.PushAndHold:
                    default:
                        if (inputManager.GetInput(iBttn))
                        {
                            trigger = iBttn;
                            return(true);
                        }
                        break;
                    }
                }
            }

            // Finally, if none of the registered binds were activated, then return false.
            trigger = new InputButton();
            return(false);
        }