Class LinearAccelerationSensor
Input device representing linear acceleration affecting the device playing the content.
Inherited Members
Namespace: UnityEngine.InputSystem
Assembly: Unity.InputSystem.dll
Syntax
public class LinearAccelerationSensor : Sensor
Remarks
An accelerometer let's you measure the acceleration of a device, and can be useful to control content by moving a device around. Linear acceleration is the acceleration of a device unaffected by gravity forces. This is usually derived from a hardware Accelerometer, by subtracting the effect of gravity (see GravitySensor).
Properties
acceleration
Declaration
public Vector3Control acceleration { get; protected set; }
Property Value
| Type | Description |
|---|---|
| Vector3Control |
current
The linear acceleration sensor that most recently became current.
Declaration
public static LinearAccelerationSensor current { get; }
Property Value
| Type | Description |
|---|---|
| LinearAccelerationSensor | Current linear acceleration sensor or |
Remarks
When a linear acceleration sensor is added, it becomes current only if no other linear acceleration sensor is current, because its controls are noisy. When the current linear acceleration sensor is removed, the remaining linear acceleration sensor that was updated last becomes current. For more information about when a device becomes current, refer to MakeCurrent().
Methods
FinishSetup()
Perform final initialization tasks after the control hierarchy has been put into place.
Declaration
protected override void FinishSetup()
Overrides
Remarks
This method can be overridden to perform control- or device-specific setup work. The most common use case is for looking up child controls and storing them in local getters.
Examples
public class MyDevice : InputDevice
{
public ButtonControl button { get; private set; }
public AxisControl axis { get; private set; }
protected override void OnFinishSetup()
{
// Cache controls in getters.
button = GetChildControl("button");
axis = GetChildControl("axis");
}
}
MakeCurrent()
Makes this device the current device of its type.
Declaration
public override void MakeCurrent()
Overrides
Remarks
Many types of devices have .current getters that return the current device of that type
(for example, current). The current device of a type is the device of that
type that most recently became current. For a built-in sensor, the type is the class that derives directly
from Sensor. For example, an Android gyroscope becomes current.
The Input System calls this method in the following cases:
- When a device is added. If all the device's controls are noisy, the device becomes current only if no other device of its type is current. For example, a second gyroscope doesn't replace the first one as current, because all of a gyroscope sensor's controls are noisy.
- When input changes a control that isn't noisy. Input on noisy controls doesn't call this method.
- When a device's usage changes, with the same rule as when the device is added.
- When a layout change recreates a device. The new device is current if the old one was.
- When a device is removed. The remaining device of its type that was updated last becomes current.
If no device of that type is left,
.currentisnull. If you remove a sensor that isn't current,.currentstays the same.
A device with noisy controls (noisy) can receive events that carry no user interaction. For example, the PlayStation®4 (PS4) gamepad has a gyro and keeps sending events when nobody uses it. Without the rule for noisy controls, the PS4 gamepad would make itself current while the user plays with another gamepad.
When you call this method yourself, the device becomes current even if its controls are noisy.
If you override this method, call base.MakeCurrent(). Otherwise, the built-in .current
getters don't return the device, and the rules above don't apply to it.
See Also
OnRemoved()
Called by the system when the device is removed from devices.
Declaration
protected override void OnRemoved()
Overrides
Remarks
Examples
using UnityEngine.InputSystem;
public class MyDevice : InputDevice
{
public static MyDevice current { get; private set; }
protected override void OnRemoved()
{
// use this context to unassign the current device for instance
base.OnRemoved();
if (current == this)
current = null;
}
}