using System; using Framework.Services; namespace Framework.Input { /// Maps input from any number of devices to actions /// /// /// Actions need to be created through the method /// before they can be used. It is a good idea to assign default key bindings /// at the start of your game (even if loading the player's settings overwrites /// these bindings again) to ensure the game never ends up in a state where /// the player has no usable controls. /// /// /// Consider adding another layer between your code and the input mapper instead /// of querying inputs directory in order to allow for unit testing with simulated /// inputs. The can collect input and package it in /// arbitrary state structures that you could mock in your tests. /// /// /// Basic usage example: /// /// /// /// /// IAction fireAction = this.myInputManager.CreateAction("Fire"); /// fireAction.BoundKeys.Add(KeyCode.Mouse0); /// fireAction.BoundKeys.Add(KeyCode.Joystick1Button); /// /// IAction forwardAction = this.myInputManager.CreateAction("Forward"); /// forwardAction.BoundKeys.Add(KeyCode.W); /// forwardAction.BoundJoystickAxes.Add("Joystick1_Axis1"); /// /// if(fireAction.IsActive) { /// fireWeapon(); /// } /// /// transform.Translate(0.0f, 0.0f, forwardAction.State, Space.Self); /// /// /// /// [ ServiceScope(Scope.Global), DefaultBinding(typeof(InputMapper)) ] public interface IInputMapper { /// Actions that have been set up for binding inputs IActionCollection Actions { get; } /// Creates a new input action ready for binding /// Name of the action that will be created /// The newly created action /// /// If an action with the same name already exists, the existing action will /// be returned. /// IAction CreateAction(string name); /// Creates a new input action ready for binding /// Name of the action that will be created /// The newly created action /// /// If an action with the same name already exists, the existing action will /// be returned. /// IAction CreateAction(string name, string description); /// Updates the states of all inputs in Unity if needed /// /// /// Writing an input manager that relies on Update() or FixedUpdate() always runs /// the risk that it will update somewhere between other game objects (as the update /// order is undefined). If the game object carrying the InputMapper ends up near /// the beginning of the update queue, input will be fresh. If it's near the end /// of the udpate queue, input will already be one frame old when it's checked. /// /// /// To avoid any lag, you can call this method before processing any input to /// ensure that the input update for the current frame is performed before querying /// any inputs. /// /// void UpdateIfNeeded(); } } // namespace Framework.Input