Esempio n. 1
0
        /// <summary>
        /// Adds the specified InputBinding instance to the cache.
        /// </summary>
        /// <param name="inputBinding">InputBinding instance to add.</param>
        /// <exception cref="System.ArgumentNullException">Thrown if the inputBinding parameter is null.</exception>
        public void AddInputBinding(InputBinding inputBinding)
        {
            if (inputBinding == null)
            {
                throw new ArgumentNullException("inputBinding");
            }

            string name = inputBinding.Name;

            if (InputBindings.ContainsKey(name))
            {
                InputBindings[name] = inputBinding;
            }
            else
            {
                InputBindings.Add(name, inputBinding);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Checks the InputBinding instance with the specified name to see if it is matched and runs its action if so.
        /// </summary>
        /// <param name="name">Name of the InputBinding instance to check.</param>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        /// <returns>True if the InputBinding instance was found and matched, false if not.</returns>
        public bool CheckAndRunInputBinding(string name, GameTime gameTime)
        {
            if (!InputBindings.ContainsKey(name))
            {
                return(false);
            }

            InputBinding inputBinding = InputBindings[name];

            foreach (IInputMatcher matcher in inputBinding.InputMatchers)
            {
                if (matcher.Matched())
                {
                    inputBinding.Action.DynamicInvoke(gameTime);
                    return(true);
                }
            }

            return(false);
        }