using System;
using UnityEngine.XR.Interaction.Toolkit.Interactors;
namespace UnityEngine.XR.Interaction.Toolkit
{
///
/// Represents a serializable state of the XR Interactor for use with recording and playback.
///
///
/// Use of this class should be avoided outside of the context of playback and recording.
/// Instead, use properties in when possible.
///
///
[Serializable]
public partial class XRControllerState
{
///
/// The time value for this controller.
///
public double time;
///
/// The input tracking state of the controller.
///
public InputTrackingState inputTrackingState;
///
/// Whether the controller is actively tracked.
///
public bool isTracked;
///
/// The position of the controller.
///
public Vector3 position;
///
/// The rotation of the controller.
///
public Quaternion rotation;
///
/// The selection interaction state.
///
public InteractionState selectInteractionState;
///
/// The activate interaction state.
///
public InteractionState activateInteractionState;
///
/// The UI press interaction state.
///
public InteractionState uiPressInteractionState;
///
/// The UI scroll value.
///
public Vector2 uiScrollValue;
///
/// Initializes and returns an instance of .
///
/// The time value for this controller.
/// The position for this controller.
/// The rotation for this controller.
/// The inputTrackingState for this controller.
/// Whether the controller is tracked this frame.
protected XRControllerState(double time, Vector3 position, Quaternion rotation, InputTrackingState inputTrackingState, bool isTracked)
{
this.time = time;
this.position = position;
this.rotation = rotation;
this.inputTrackingState = inputTrackingState;
this.isTracked = isTracked;
}
///
/// Initializes and returns an instance of .
///
public XRControllerState() : this(0d, Vector3.zero, Quaternion.identity, InputTrackingState.None, false)
{
}
///
/// Initializes and returns an instance of .
///
/// The object used to create this object.
public XRControllerState(XRControllerState value)
{
this.time = value.time;
this.position = value.position;
this.rotation = value.rotation;
this.inputTrackingState = value.inputTrackingState;
this.isTracked = value.isTracked;
this.selectInteractionState = value.selectInteractionState;
this.activateInteractionState = value.activateInteractionState;
this.uiPressInteractionState = value.uiPressInteractionState;
this.uiScrollValue = value.uiScrollValue;
}
///
/// Initializes and returns an instance of .
///
/// The time value for this controller.
/// The position for this controller.
/// The rotation for this controller.
/// The inputTrackingState for this controller.
/// Whether the controller is tracked this frame.
/// Whether select is active or not.
/// Whether activate is active or not.
/// Whether UI press is active or not.
public XRControllerState(double time, Vector3 position, Quaternion rotation, InputTrackingState inputTrackingState, bool isTracked,
bool selectActive, bool activateActive, bool pressActive)
: this(time, position, rotation, inputTrackingState, isTracked)
{
this.selectInteractionState.SetFrameState(selectActive);
this.activateInteractionState.SetFrameState(activateActive);
this.uiPressInteractionState.SetFrameState(pressActive);
}
///
/// Initializes and returns an instance of .
///
/// The time value for this controller.
/// The position for this controller.
/// The rotation for this controller.
/// The inputTrackingState for this controller.
/// Whether the controller is tracked this frame.
/// Whether select is active or not.
/// Whether activate is active or not.
/// Whether UI press is active or not.
/// The select value.
/// The activate value.
/// The UI press value.
public XRControllerState(double time, Vector3 position, Quaternion rotation, InputTrackingState inputTrackingState, bool isTracked,
bool selectActive, bool activateActive, bool pressActive,
float selectValue, float activateValue, float pressValue)
: this(time, position, rotation, inputTrackingState, isTracked)
{
this.selectInteractionState.SetFrameState(selectActive, selectValue);
this.activateInteractionState.SetFrameState(activateActive, activateValue);
this.uiPressInteractionState.SetFrameState(pressActive, pressValue);
}
///
/// Resets all the interaction states that are based on whether they occurred "this frame".
///
///
public void ResetFrameDependentStates()
{
selectInteractionState.ResetFrameDependent();
activateInteractionState.ResetFrameDependent();
uiPressInteractionState.ResetFrameDependent();
}
///
/// Converts state data to a string.
///
/// A string representation.
public override string ToString() => $"time: {time}, position: {position}, rotation: {rotation}, selectActive: {selectInteractionState.active}, activateActive: {activateInteractionState.active}, pressActive: {uiPressInteractionState.active}, isTracked: {isTracked}, inputTrackingState: {inputTrackingState}";
}
}