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 { /// /// Locomotion provider that allows the user to smoothly move their rig continuously over time /// using a specified input action. /// /// [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")); /// /// The Input System Action that Unity uses to read Move data from the left hand controller. Must be a Control. /// 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")); /// /// The Input System Action that Unity uses to read Move data from the right hand controller. Must be a Control. /// public InputActionProperty rightHandMoveAction { get => m_RightHandMoveAction; set => SetInputActionProperty(ref m_RightHandMoveAction, value); } /// /// See . /// protected void OnEnable() { m_LeftHandMoveAction.EnableDirectAction(); m_RightHandMoveAction.EnableDirectAction(); } /// /// See . /// protected void OnDisable() { m_LeftHandMoveAction.DisableDirectAction(); m_RightHandMoveAction.DisableDirectAction(); } /// protected override Vector2 ReadInput() { var leftHandValue = m_LeftHandMoveAction.action?.ReadValue() ?? Vector2.zero; var rightHandValue = m_RightHandMoveAction.action?.ReadValue() ?? 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(); } } }