Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCS: improve migration docs #1933

Merged
merged 32 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2186a85
migration page improvements WIP
duckets May 16, 2024
ae672e7
More WIP for improving Migration page
duckets May 17, 2024
0f891a0
more WIP - migrating action-based input
duckets May 21, 2024
d8f4464
More WIP on Migration page
duckets May 21, 2024
8908df2
Migration page improvements WIP
duckets May 22, 2024
4b54e02
Merge branch 'develop' into DOCF-5410-improve-migration-docs
duckets May 22, 2024
0d21a11
Amendments from PR review comments
duckets May 29, 2024
2a29b1e
Merge branch 'develop' into DOCF-5410-improve-migration-docs
ekcoh Jun 18, 2024
6fcaa9d
Merge branch 'develop' into DOCF-5410-improve-migration-docs
ekcoh Jun 25, 2024
d1f23b7
Merge branch 'develop' into DOCF-5410-improve-migration-docs
ekcoh Jun 27, 2024
c35ae06
Update Migration.md
lyndon-unity Jun 27, 2024
a4cf9e1
Merge branch 'develop' into DOCF-5410-improve-migration-docs
ekcoh Jun 28, 2024
d7acd69
Fix broken api links for KeyControl.displayName
duckets Jun 28, 2024
9bccbbc
Formatting fix
duckets Jun 28, 2024
0e68c81
Updates to migration guide for Pen events
duckets Jul 1, 2024
3c58f51
Updates to migration guide for Keyboard IME text composition
duckets Jul 1, 2024
58c03f4
Merge branch 'develop' into DOCF-5410-improve-migration-docs
duckets Jul 1, 2024
c6e39ff
Removed migration info for Input.mousePresent
duckets Jul 3, 2024
eec1efb
Merge branch 'develop' into DOCF-5410-improve-migration-docs
duckets Jul 8, 2024
50cb96d
Merge branch 'develop' into DOCF-5410-improve-migration-docs
lyndon-unity Jul 9, 2024
104ae35
Formatting fix
duckets Jul 9, 2024
5f1972f
Merge branch 'develop' into DOCF-5410-improve-migration-docs
duckets Jul 22, 2024
d42e862
Merge branch 'develop' into DOCF-5410-improve-migration-docs
duckets Jul 25, 2024
c18f788
Merge branch 'develop' into DOCF-5410-improve-migration-docs
duckets Jul 25, 2024
b92137b
Merge branch 'develop' into DOCF-5410-improve-migration-docs
AlexTyrer Jul 25, 2024
3420074
Merge branch 'develop' into DOCF-5410-improve-migration-docs
duckets Jul 30, 2024
00155ac
fix xml for ButtonControl
duckets Jul 30, 2024
127549c
xml fix
duckets Jul 31, 2024
a375f3f
xml doc fix
duckets Jul 31, 2024
63b55f1
whitespace format fix
duckets Jul 31, 2024
7a67b47
added para tags for example plain text
duckets Jul 31, 2024
3735c41
Merge branch 'develop' into DOCF-5410-improve-migration-docs
lyndon-unity Aug 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 44 additions & 10 deletions Packages/com.unity.inputsystem/Documentation~/Gamepad.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ uid: input-system-gamepad
---
# Gamepad Support

- [Gamepad Support](#gamepad-support)
- [Controls](#controls)
- [Deadzones](#deadzones)
- [Polling](#polling)
- [Rumble](#rumble)
- [Pausing, resuming, and stopping haptics](#pausing-resuming-and-stopping-haptics)
- [PlayStation controllers](#playstation-controllers)
- [Xbox controllers](#xbox-controllers)
- [Switch controllers](#switch-controllers)
- [Cursor Control](#cursor-control)
- [Controls](#controls)
- [Deadzones](#deadzones)
- [Polling](#polling)
- [Rumble](#rumble)
- [Pausing, resuming, and stopping haptics](#pausing-resuming-and-stopping-haptics)
- [PlayStation controllers](#playstation-controllers)
- [Xbox controllers](#xbox-controllers)
- [Switch controllers](#switch-controllers)
- [Cursor Control](#cursor-control)
- [Discover all connected devices](#discover-all-connected-devices)

A [`Gamepad`](../api/UnityEngine.InputSystem.Gamepad.html) is narrowly defined as a Device with two thumbsticks, a D-pad, and four face buttons. Additionally, gamepads usually have two shoulder and two trigger buttons. Most gamepads also have two buttons in the middle.

Expand Down Expand Up @@ -198,3 +198,37 @@ The Input System support Switch Pro controllers on desktop computers via the [`S
## Cursor Control

To give gamepads and joysticks control over a hardware or software cursor, you can use the [`VirtualMouseInput`](../api/UnityEngine.InputSystem.UI.VirtualMouseInput.html) component. See [`VirtualMouseInput` component](UISupport.md#virtual-mouse-cursor-control) in the UI section of the manual.

## Discover all connected devices

There are various ways to discover the currently connected devices, as shown in the code samples below.

To query a list of all connected devices (does not allocate; read-only access):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed for the add/remove onDeviceChange part so could go down with the "To find all gamepads and joysticks" section

```
InputSystem.devices
```

To get notified when a device is added or removed:
```
InputSystem.onDeviceChange +=
(device, change) =>
{
if (change == InputDeviceChange.Added || change == InputDeviceChange.Removed)
{
Debug.Log($"Device '{device}' was {change}");
}
}
```

To find all gamepads and joysticks:
```
var devices = InputSystem.devices;
for (var i = 0; i < devices.Count; ++i)
{
var device = devices[i];
if (device is Joystick || device is Gamepad)
{
Debug.Log("Found " + device);
}
}
```
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
261 changes: 90 additions & 171 deletions Packages/com.unity.inputsystem/Documentation~/Migration.md

Large diffs are not rendered by default.

48 changes: 35 additions & 13 deletions Packages/com.unity.inputsystem/Documentation~/Sensors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ uid: input-system-sensors
---
# Sensor support

* [Sampling Frequency](#sampling-frequency)
* [Accelerometer](#accelerometer)
* [Gyroscope](#gyroscope)
* [GravitySensor](#gravitysensor)
* [AttitudeSensor](#attitudesensor)
* [LinearAccelerationSensor](#linearaccelerationsensor)
* [MagneticFieldSensor](#magneticfieldsensor)
* [LightSensor](#lightsensor)
* [PressureSensor](#pressuresensor)
* [ProximitySensor](#proximitysensor)
* [HumiditySensor](#humiditysensor)
* [AmbientTemperatureSensor](#ambienttemperaturesensor)
* [StepCounter](#stepcounter)
- [Sampling frequency](#sampling-frequency)
- [`Accelerometer`](#accelerometer)
- [`Gyroscope`](#gyroscope)
- [`GravitySensor`](#gravitysensor)
- [`AttitudeSensor`](#attitudesensor)
- [`LinearAccelerationSensor`](#linearaccelerationsensor)
- [`MagneticFieldSensor`](#magneticfieldsensor)
- [`LightSensor`](#lightsensor)
- [`PressureSensor`](#pressuresensor)
- [`ProximitySensor`](#proximitysensor)
- [`HumiditySensor`](#humiditysensor)
- [`AmbientTemperatureSensor`](#ambienttemperaturesensor)
- [`StepCounter`](#stepcounter)

Sensors are [`InputDevices`](Devices.md) that measure environmental characteristics of the device that the content is running on. Unity currently supports sensors on iOS and Android. Android supports a wider range of sensors than iOS.

Expand Down Expand Up @@ -84,6 +84,28 @@ Gyroscope.current.samplingFrequency = 16;

Use the accelerometer to measure the acceleration of a device. This is useful to control content by moving a device around. It reports the acceleration measured on a device both due to moving the device around, and due to gravity pulling the device down. You can use `GravitySensor` and `LinearAccelerationSensor` to get separate values for these. Values are affected by the [__Compensate Orientation__](Settings.md#compensate-orientation) setting.

The following code traces all input events on the [`Accelerometer.current`](../api/UnityEngine.InputSystem.Accelerometer.html) device.
```CSharp
private InputEventTrace trace;

void StartTrace()
{
InputSystem.EnableDevice(Accelerometer.current);

trace = new InputEventTrace(Accelerometer.current);
trace.Enable();
}

void Update()
{
foreach (var e in trace)
{
//...
}
trace.Clear();
}
```

## <a name="gyroscope"></a>[`Gyroscope`](../api/UnityEngine.InputSystem.Gyroscope.html)

Use the gyroscope to measure the angular velocity of a device. This is useful to control content by rotating a device. Values are affected by the [__Compensate Orientation__](Settings.md#compensate-orientation) setting.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
* [Input testing](Testing.md)
* [How do I...?](HowDoI.md)
* [Architecture](Architecture.md)
* [Migrating from the old input system](Migration.md)
* [Migrating from the old Input Manager](Migration.md)
duckets marked this conversation as resolved.
Show resolved Hide resolved
* [Contributing](Contributing.md)
* [Known Limitations](KnownLimitations.md)
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,55 @@ public ButtonControl()
/// </summary>
/// <value>True if button is currently pressed.</value>
/// <remarks>
/// A button is considered press if it's value is equal to or greater
/// A button is considered pressed if its value is equal to or greater
/// than its button press threshold (<see cref="pressPointOrDefault"/>).
/// </remarks>
/// <example>
/// <para>You can use this to read whether specific keys are currently pressed by using isPressed on keys, as shown in the following examples:</para>
/// <code>
/// <![CDATA[
/// // Using KeyControl property directly.
/// Keyboard.current.spaceKey.isPressed
/// Keyboard.current.aKey.isPressed // etc.
///
/// // Using Key enum.
/// Keyboard.current[Key.Space].isPressed
///
/// // Using key name.
/// ((KeyControl)Keyboard.current["space"]).isPressed
/// ]]>
/// </code>
/// <para>Note: The Input System identifies keys by physical layout, not according to the current language mapping of the keyboard. To query the name of the key according to the language mapping, use <see cref="InputControl.displayName"/>.
///
/// You can also use this to read mouse buttons, as shown in the following examples:</para>
/// <code>
/// <![CDATA[
/// bool leftPressed = Mouse.current.leftButton.isPressed;
/// bool rightPressed = Mouse.current.rightButton.isPressed;
/// bool middlePressed = Mouse.current.middleButton.isPressed;
/// ]]>
/// </code>
/// <para>You can also check through all numbered buttons on the mouse: (this example does not cause allocations)</para>
/// <code>
/// <![CDATA[
/// var controls = Mouse.current.allControls;
/// for (var i = 0; i < controls.Count; ++i)
/// {
/// var button = controls[i] as ButtonControl;
/// if (button != null && button.isPressed)
/// {
/// // respond to mouse button press here...
/// }
/// }
/// ]]>
/// </code>
/// <para>Or you can look up controls by name, like this:</para>
/// <code>
/// <![CDATA[
/// bool leftPressed = ((ButtonControl)Mouse.current["leftButton"]).isPressed;
/// ]]>
/// </code>
/// </example>
/// <seealso cref="InputSettings.defaultButtonPressPoint"/>
/// <seealso cref="pressPoint"/>
/// <seealso cref="InputSystem.onAnyButtonPress"/>
Expand Down Expand Up @@ -177,6 +223,19 @@ private void BeginTestingForFramePresses(bool currentlyPressed, bool pressedLast
/// }
/// </code>
/// </example>
/// _Note_: The Input System identifies keys by physical layout, not according to the current language mapping of the keyboard. To query the name of the key according to the language mapping, use <see cref="InputControl.displayName"/>.
///
/// You can also use this property to read mouse buttons. For example:
///
/// <example>
/// <code>
/// Mouse.current.leftButton.wasPressedThisFrame
/// Mouse.current.rightButton.wasPressedThisFrame
/// Mouse.current.middleButton.wasPressedThisFrame
/// </code>
/// </example>
///
///
/// </remarks>
public bool wasPressedThisFrame
{
Expand All @@ -200,6 +259,29 @@ public bool wasPressedThisFrame
}
}

/// <summary>
/// Whether the press ended this frame.
/// </summary>
/// <value>True if the current press of the button ended this frame.</value>
/// <remarks>
/// _Note_: The Input System identifies keys by physical layout, not according to the current language mapping of the keyboard. To query the name of the key according to the language mapping, use <see cref="InputControl.displayName"/>.
/// </remarks>
/// <example>
/// <para>An example showing the use of this property on a gamepad button and a keyboard key:</para>
/// <code>
/// using UnityEngine;
/// using UnityEngine.InputSystem;
///
/// public class ExampleScript : MonoBehaviour
/// {
/// void Update()
/// {
/// bool buttonPressed = Gamepad.current.aButton.wasReleasedThisFrame;
/// bool spaceKeyPressed = Keyboard.current.spaceKey.wasReleasedThisFrame;
/// }
/// }
/// </code>
/// </example>
public bool wasReleasedThisFrame
{
get
Expand All @@ -214,7 +296,7 @@ public bool wasReleasedThisFrame
return device.wasUpdatedThisFrame && !currentlyPressed && pressedLastFrame;
}

#if UNITY_EDITOR
#if UNITY_EDITOR
if (InputUpdate.s_LatestUpdateType.IsEditorUpdate())
return InputUpdate.s_UpdateStepCount == m_UpdateCountLastReleasedEditor;
#endif
Expand Down
10 changes: 10 additions & 0 deletions Packages/com.unity.inputsystem/InputSystem/Devices/Keyboard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,16 @@ public event Action<char> onTextInput
///
/// See <see cref="Keyboard.SetIMEEnabled"/> for turning IME on/off
/// </remarks>
/// <example>
/// <para>To subscribe to the onIMECompositionChange event, use the following sample code:</para>
/// <code>
/// var compositionString = "";
/// Keyboard.current.onIMECompositionChange += composition =>
/// {
/// compositionString = composition.ToString();
/// };
/// </code>
/// </example>
public event Action<IMECompositionString> onIMECompositionChange
{
add
Expand Down