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 rotate their rig continuously over time
/// using a specified input action.
///
///
///
[AddComponentMenu("XR/Locomotion/Legacy/Continuous Turn Provider (Action-based)", 11)]
[HelpURL(XRHelpURLConstants.k_ActionBasedContinuousTurnProvider)]
[Obsolete("ActionBasedContinuousTurnProvider has been deprecated in version 3.0.0. Use ContinuousTurnProvider instead.")]
public class ActionBasedContinuousTurnProvider : ContinuousTurnProviderBase
{
[SerializeField]
[Tooltip("The Input System Action that will be used to read Turn data from the left hand controller. Must be a Value Vector2 Control.")]
InputActionProperty m_LeftHandTurnAction = new InputActionProperty(new InputAction("Left Hand Turn", expectedControlType: "Vector2"));
///
/// The Input System Action that Unity uses to read Turn data from the left hand controller. Must be a Control.
///
public InputActionProperty leftHandTurnAction
{
get => m_LeftHandTurnAction;
set => SetInputActionProperty(ref m_LeftHandTurnAction, value);
}
[SerializeField]
[Tooltip("The Input System Action that will be used to read Turn data from the right hand controller. Must be a Value Vector2 Control.")]
InputActionProperty m_RightHandTurnAction = new InputActionProperty(new InputAction("Right Hand Turn", expectedControlType: "Vector2"));
///
/// The Input System Action that Unity uses to read Turn data from the right hand controller. Must be a Control.
///
public InputActionProperty rightHandTurnAction
{
get => m_RightHandTurnAction;
set => SetInputActionProperty(ref m_RightHandTurnAction, value);
}
///
/// See .
///
protected void OnEnable()
{
m_LeftHandTurnAction.EnableDirectAction();
m_RightHandTurnAction.EnableDirectAction();
}
///
/// See .
///
protected void OnDisable()
{
m_LeftHandTurnAction.DisableDirectAction();
m_RightHandTurnAction.DisableDirectAction();
}
///
protected override Vector2 ReadInput()
{
var leftHandValue = m_LeftHandTurnAction.action?.ReadValue() ?? Vector2.zero;
var rightHandValue = m_RightHandTurnAction.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();
}
}
}