using System;
namespace UnityEngine.XR.Interaction.Toolkit
{
///
/// Helper class for different kinds of input.
///
[Obsolete("InputHelpers has been deprecated in version 3.0.0. Use XRInputDeviceButtonReader or XRInputDeviceValueReader instead.")]
public static class InputHelpers
{
///
/// A list of buttons that can be bound to.
///
[Obsolete("Button has been deprecated in version 3.0.0. Use XRInputDeviceButtonReader or XRInputDeviceValueReader instead.")]
public enum Button
{
///
/// Represents and invalid button.
///
None = 0,
///
/// Represents a menu button, used to pause, go back, or otherwise exit gameplay.
///
MenuButton,
///
/// A binary measure of whether the index finger is activating the trigger.
///
Trigger,
///
/// Represents the user's grip on the controller.
///
Grip,
///
/// A binary measure of whether the index finger is activating the trigger.
///
TriggerButton,
///
/// A binary measure of whether the device is being gripped.
///
GripButton,
///
/// The primary face button being pressed on a device, or sole button if only one is available.
///
PrimaryButton,
///
/// The primary face button being touched on a device.
///
PrimaryTouch,
///
/// The secondary face button being pressed on a device.
///
SecondaryButton,
///
/// The secondary face button being touched on a device.
///
SecondaryTouch,
///
/// Represents the primary 2D axis being touched.
///
Primary2DAxisTouch,
///
/// Represents the primary 2D axis being clicked or otherwise depressed.
///
Primary2DAxisClick,
///
/// Represents the primary 2D axis being touched.
///
Secondary2DAxisTouch,
///
/// Represents the secondary 2D axis being clicked or otherwise depressed.
///
Secondary2DAxisClick,
///
/// Represents an upwards motion on the primary touchpad or joystick on a device.
///
PrimaryAxis2DUp,
///
/// Represents a downwards motion on the primary touchpad or joystick on a device.
///
PrimaryAxis2DDown,
///
/// Represents a leftwards motion on the primary touchpad or joystick on a device.
///
PrimaryAxis2DLeft,
///
/// Represents a rightwards motion on the primary touchpad or joystick on a device.
///
PrimaryAxis2DRight,
///
/// Represents an upwards motion on the secondary touchpad or joystick on a device.
///
SecondaryAxis2DUp,
///
/// Represents a downwards motion on the secondary touchpad or joystick on a device.
///
SecondaryAxis2DDown,
///
/// Represents a leftwards motion on the secondary touchpad or joystick on a device.
///
SecondaryAxis2DLeft,
///
/// Represents a rightwards motion on the secondary touchpad or joystick on a device.
///
SecondaryAxis2DRight,
///
/// A binary measure of whether the index finger is activating the trigger.
///
///
/// TriggerPressed has been deprecated. Use instead.
///
[Obsolete("TriggerPressed has been deprecated. Use TriggerButton instead. (UnityUpgradable) -> TriggerButton", true)]
TriggerPressed = TriggerButton,
///
/// A binary measure of whether the device is being gripped.
///
///
/// GripPressed has been deprecated. Use instead.
///
[Obsolete("GripPressed has been deprecated. Use GripButton instead. (UnityUpgradable) -> GripButton", true)]
GripPressed = GripButton,
}
///
/// A list of 2D axis inputs that can be bound to.
///
[Obsolete("Axis2D has been deprecated in version 3.0.0. Use XRInputDeviceButtonReader or XRInputDeviceValueReader instead.")]
public enum Axis2D
{
///
/// Represents an invalid 2D axis.
///
None = 0,
///
/// Represents the primary touchpad or joystick on a device.
///
PrimaryAxis2D,
///
/// Represents the secondary touchpad or joystick on a device.
///
SecondaryAxis2D,
}
enum ButtonReadType
{
None = 0,
Binary,
Axis1D,
Axis2DUp,
Axis2DDown,
Axis2DLeft,
Axis2DRight,
}
struct ButtonInfo
{
public ButtonInfo(string name, ButtonReadType type)
{
this.name = name;
this.type = type;
}
public string name;
public ButtonReadType type;
}
static readonly ButtonInfo[] s_ButtonData =
{
new ButtonInfo("", ButtonReadType.None),
new ButtonInfo("MenuButton", ButtonReadType.Binary),
new ButtonInfo("Trigger", ButtonReadType.Axis1D),
new ButtonInfo("Grip", ButtonReadType.Axis1D),
new ButtonInfo("TriggerButton", ButtonReadType.Binary),
new ButtonInfo("GripButton", ButtonReadType.Binary),
new ButtonInfo("PrimaryButton", ButtonReadType.Binary),
new ButtonInfo("PrimaryTouch", ButtonReadType.Binary),
new ButtonInfo("SecondaryButton", ButtonReadType.Binary),
new ButtonInfo("SecondaryTouch", ButtonReadType.Binary),
new ButtonInfo("Primary2DAxisTouch", ButtonReadType.Binary),
new ButtonInfo("Primary2DAxisClick", ButtonReadType.Binary),
new ButtonInfo("Secondary2DAxisTouch", ButtonReadType.Binary),
new ButtonInfo("Secondary2DAxisClick", ButtonReadType.Binary),
new ButtonInfo("Primary2DAxis", ButtonReadType.Axis2DUp),
new ButtonInfo("Primary2DAxis", ButtonReadType.Axis2DDown),
new ButtonInfo("Primary2DAxis", ButtonReadType.Axis2DLeft),
new ButtonInfo("Primary2DAxis", ButtonReadType.Axis2DRight),
new ButtonInfo("Secondary2DAxis", ButtonReadType.Axis2DUp),
new ButtonInfo("Secondary2DAxis", ButtonReadType.Axis2DDown),
new ButtonInfo("Secondary2DAxis", ButtonReadType.Axis2DLeft),
new ButtonInfo("Secondary2DAxis", ButtonReadType.Axis2DRight),
};
static readonly string[] s_Axis2DNames =
{
"",
"Primary2DAxis",
"Secondary2DAxis",
};
const float k_DefaultPressThreshold = 0.1f;
///
/// Checks whether button is pressed or not.
///
/// The input device.
/// The button that is being checked.
/// A boolean that will be true if button is pressed and false if not.
/// The threshold of what defines a press.
/// Returns if device and button are valid. Otherwise, returns .
[Obsolete("IsPressed has been deprecated in version 3.0.0. Use XRInputDeviceButtonReader instead.")]
public static bool IsPressed(this InputDevice device, Button button, out bool isPressed, float pressThreshold = -1.0f)
{
if ((int)button >= s_ButtonData.Length)
{
throw new ArgumentException("[InputHelpers.IsPressed] The value of