using System;
using UnityEngine.XR.Interaction.Toolkit.Interactors;
namespace UnityEngine.XR.Interaction.Toolkit
{
///
/// Serializable struct to hold logical input state for a given interaction, such as for select.
///
///
/// Use of this class should be avoided outside of the context of playback and recording.
/// Instead, use when possible.
///
///
[Serializable]
public partial struct InteractionState
{
[Range(0f, 1f)]
[SerializeField]
float m_Value;
///
/// The value of the interaction in this frame.
///
public float value
{
get => m_Value;
set => m_Value = value;
}
[SerializeField]
bool m_Active;
///
/// Whether it is currently on.
///
public bool active
{
get => m_Active;
set => m_Active = value;
}
bool m_ActivatedThisFrame;
///
/// Whether the interaction state activated this frame.
///
public bool activatedThisFrame
{
get => m_ActivatedThisFrame;
set => m_ActivatedThisFrame = value;
}
bool m_DeactivatedThisFrame;
///
/// Whether the interaction state deactivated this frame.
///
public bool deactivatedThisFrame
{
get => m_DeactivatedThisFrame;
set => m_DeactivatedThisFrame = value;
}
///
/// Sets the interaction state for this frame. This method should only be called once per frame.
///
/// Whether the state is active (in other words, pressed).
public void SetFrameState(bool isActive)
{
SetFrameState(isActive, isActive ? 1f : 0f);
}
///
/// Sets the interaction state for this frame. This method should only be called once per frame.
///
/// Whether the state is active (in other words, pressed).
/// The interaction value.
public void SetFrameState(bool isActive, float newValue)
{
value = newValue;
activatedThisFrame = !active && isActive;
deactivatedThisFrame = active && !isActive;
active = isActive;
}
///
/// Sets the interaction state that are based on whether they occurred "this frame".
///
/// Whether the previous state is active (in other words, pressed).
public void SetFrameDependent(bool wasActive)
{
activatedThisFrame = !wasActive && active;
deactivatedThisFrame = wasActive && !active;
}
///
/// Resets the interaction states that are based on whether they occurred "this frame".
///
///
///
public void ResetFrameDependent()
{
activatedThisFrame = false;
deactivatedThisFrame = false;
}
}
}