Input to Input System Migration
Migrate your use of Input to the new Input System.
This document describes a Input compatibility class to ease the transition from Unity's legacy input to its new Input
System. The AppMana Plugin only supports Input System, so you must migrate from the old Input methods to use AppMana's
streaming features.
Enabling Input Compatibility
These instructions will use Rider, the best performing IDE for Unity development. But you can use these instructions in any IDE.
Navigate to Assets > Open C# Project.
In your Explorer tool window (also known as the Project tool window or file hierarchy), switch your view by clicking
Unity at the top of the pane and choosing File System instead. Then, right-click on your Assets/ directory,
and navigate to Edit > Find in Files.... In the search box, search for the string \bInput.\b, and switch to
regular expression search by clicking the button that looks like .* and enable case sensitivity by clicking the button
that looks like Cc. This is the list of files in your project that
probably use legacy Input (i.e. UnityEngine.Input) instead of Input System. Open the first matching file. Let's look
at the top of an example file:
Example: MovePlayer.cs
namespace SomeUnityAsset.SomeNamespace
{
using UnityEngine;
using System.Collections;
public class MovePlayer : MonoBehaviour
{
public float gravityForce = 9.81f;
public float maxSpeed = 90f;
public float acceleration = 10f;
...
Find the first using statement inside your file. Observe that in this file, using appears inside a namespace
block, which can be surprising. Just below your last using statement, add the following line:
using Input = AppMana.Compatibility.Input;
Now your code should look like this:
namespace SomeUnityAsset.SomeNamespace
{
using UnityEngine;
using System.Collections;
// ADDED
using Input = AppMana.Compatibility.Input;
public class MovePlayer : MonoBehaviour
{
public float gravityForce = 9.81f;
public float maxSpeed = 90f;
public float acceleration = 10f;
...
This compatibility class AppMana.Compatibility.Input will allow you to continue to use the Input. syntax you are
familiar with but instead backed by the Input System, which AppMana requires.
This edit should be done for every file that uses UnityEngine.Input.
Supported Features
These are all the Input. symbols or features supported by the AppMana compatibility class:
Properties
acceleration: Gets the current acceleration vector of the device.anyKey: Checks if any key or button is currently pressed.anyKeyDown: Checks if any key or button was pressed in the current frame.compensateSensors: Gets or sets whether the sensor input should compensate for screen orientation.compositionCursorPos: Sets the position of the IME (Input Method Editor) composition window.mousePosition: Gets the last non-zero touch or current mouse position.multiTouchEnabled: Indicates whether multitouch is enabled (alwaystruein this compatibility layer).simulateMouseWithTouches: Indicates if mouse simulation with touches is enabled (alwaystrue).touches: Gets a read-only array of active touches.touchPressureSupported: Indicates if touch pressure is supported (alwaysfalse).touchSupported: Indicates if touch is supported (alwaystrue).
Methods
GetAxis(string name): Retrieves the value of a virtual axis identified by name.*GetButton(string name): Checks if a virtual button identified by name is currently held down.GetButtonDown(string name): Checks if a virtual button identified by name was pressed in the current frame.GetButtonUp(string name): Checks if a virtual button identified by name was released in the current frame.GetKey(string name): Checks if a key identified by name is currently held down.GetKey(Key key): Checks if a key identified by aKeyenum value is currently held down.GetKey(KeyCode key): Checks if a key identified by aKeyCodeis currently held down.GetKeyDown(string name): Checks if a key identified by name was pressed in the current frame.GetKeyDown(Key key): Checks if a key identified by aKeyenum value was pressed in the current frame.GetKeyDown(KeyCode key): Checks if a key identified by aKeyCodewas pressed in the current frame.GetKeyUp(string name): Checks if a key identified by name was released in the current frame.GetKeyUp(Key key): Checks if a key identified by aKeyenum value was released in the current frame.GetKeyUp(KeyCode key): Checks if a key identified by aKeyCodewas released in the current frame.GetMouseButton(int index): Checks if a mouse button identified by index is currently held down.GetMouseButtonDown(int index): Checks if a mouse button identified by index was pressed in the current frame.GetMouseButtonUp(int index): Checks if a mouse button identified by index was released in the current frame.GetTouch(int index): Retrieves aTouchobject by its index.ResetInputAxes(): Resets all input axes.
*GetAxis is typically used to get mouse inputs:
forwardInput = Input.GetAxis("Vertical");
sidewaysInput = Input.GetAxis("Horizontal");
The only named input axes that are supported by the compatibility layer are:
Horizontal/Mouse XVertical/Mouse YFire1Fire2SubmitCancelJump
If you use other named input methods, consider migrating directly to the new Input System.
