82 lines
3.4 KiB
C#
82 lines
3.4 KiB
C#
using System;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.InputSystem.Controls;
|
|
using UnityEngine.XR.Interaction.Toolkit.Inputs;
|
|
using UnityEngine.XR.Interaction.Toolkit.Locomotion;
|
|
|
|
namespace UnityEngine.XR.Interaction.Toolkit
|
|
{
|
|
/// <summary>
|
|
/// Locomotion provider that allows the user to smoothly move their rig continuously over time
|
|
/// using a specified input action.
|
|
/// </summary>
|
|
/// <seealso cref="LocomotionProvider"/>
|
|
[AddComponentMenu("XR/Locomotion/Legacy/Continuous Move Provider (Action-based)", 11)]
|
|
[HelpURL(XRHelpURLConstants.k_ActionBasedContinuousMoveProvider)]
|
|
[Obsolete("ActionBasedContinuousMoveProvider has been deprecated in version 3.0.0. Use ContinuousMoveProvider instead.", false)]
|
|
public class ActionBasedContinuousMoveProvider : ContinuousMoveProviderBase
|
|
{
|
|
[SerializeField]
|
|
[Tooltip("The Input System Action that will be used to read Move data from the left hand controller. Must be a Value Vector2 Control.")]
|
|
InputActionProperty m_LeftHandMoveAction = new InputActionProperty(new InputAction("Left Hand Move", expectedControlType: "Vector2"));
|
|
/// <summary>
|
|
/// The Input System Action that Unity uses to read Move data from the left hand controller. Must be a <see cref="InputActionType.Value"/> <see cref="Vector2Control"/> Control.
|
|
/// </summary>
|
|
public InputActionProperty leftHandMoveAction
|
|
{
|
|
get => m_LeftHandMoveAction;
|
|
set => SetInputActionProperty(ref m_LeftHandMoveAction, value);
|
|
}
|
|
|
|
[SerializeField]
|
|
[Tooltip("The Input System Action that will be used to read Move data from the right hand controller. Must be a Value Vector2 Control.")]
|
|
InputActionProperty m_RightHandMoveAction = new InputActionProperty(new InputAction("Right Hand Move", expectedControlType: "Vector2"));
|
|
/// <summary>
|
|
/// The Input System Action that Unity uses to read Move data from the right hand controller. Must be a <see cref="InputActionType.Value"/> <see cref="Vector2Control"/> Control.
|
|
/// </summary>
|
|
public InputActionProperty rightHandMoveAction
|
|
{
|
|
get => m_RightHandMoveAction;
|
|
set => SetInputActionProperty(ref m_RightHandMoveAction, value);
|
|
}
|
|
|
|
/// <summary>
|
|
/// See <see cref="MonoBehaviour"/>.
|
|
/// </summary>
|
|
protected void OnEnable()
|
|
{
|
|
m_LeftHandMoveAction.EnableDirectAction();
|
|
m_RightHandMoveAction.EnableDirectAction();
|
|
}
|
|
|
|
/// <summary>
|
|
/// See <see cref="MonoBehaviour"/>.
|
|
/// </summary>
|
|
protected void OnDisable()
|
|
{
|
|
m_LeftHandMoveAction.DisableDirectAction();
|
|
m_RightHandMoveAction.DisableDirectAction();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override Vector2 ReadInput()
|
|
{
|
|
var leftHandValue = m_LeftHandMoveAction.action?.ReadValue<Vector2>() ?? Vector2.zero;
|
|
var rightHandValue = m_RightHandMoveAction.action?.ReadValue<Vector2>() ?? Vector2.zero;
|
|
|
|
return leftHandValue + rightHandValue;
|
|
}
|
|
|
|
void SetInputActionProperty(ref InputActionProperty property, InputActionProperty value)
|
|
{
|
|
if (Application.isPlaying)
|
|
property.DisableDirectAction();
|
|
|
|
property = value;
|
|
|
|
if (Application.isPlaying && isActiveAndEnabled)
|
|
property.EnableDirectAction();
|
|
}
|
|
}
|
|
}
|