Пример #1
0
 /// <summary>
 /// Sets the gamepad buttons/axis layout. Use <see cref="GamepadLayout.CreateMapping()"/> to generate proper layout and override the default logic.
 /// </summary>
 /// <param name="layout">The layout.</param>
 public void SetLayout(GamepadLayout layout)
 {
     if (_version != Input.gamepadsVersion)
     {
         throw new AccessViolationException();
     }
     if (layout.Buttons == null || layout.Axis == null || layout.AxisMap == null)
     {
         throw new ArgumentNullException();
     }
     Internal_SetLayout(_index, layout.Buttons, layout.Axis, layout.AxisMap);
 }
Пример #2
0
        /// <summary>
        /// Creates the gamepad layout from the input buttons/axis mapping.
        /// </summary>
        /// <param name="buttons">The buttons.</param>
        /// <param name="axis">The axis.</param>
        /// <returns>The gamepad layout</returns>
        public static GamepadLayout CreateMapping(Dictionary <Gamepad.ButtonTypes, GamePadButton> buttons, Dictionary <Gamepad.AxisTypes, GamePadAxis> axis)
        {
            if (buttons == null)
            {
                throw new ArgumentNullException(nameof(buttons));
            }
            if (axis == null)
            {
                throw new ArgumentNullException(nameof(axis));
            }

            GamepadLayout layout = CreateMapping();

            foreach (var e in buttons)
            {
                layout.Buttons[(int)e.Key] = e.Value;
            }
            foreach (var e in axis)
            {
                layout.Axis[(int)e.Key] = e.Value;
            }

            return(layout);
        }