using TMPro;
using UnityEngine.XR.Hands.Gestures;
namespace UnityEngine.XR.Hands.Samples.Gestures.DebugTools
{
///
/// Updates the text label that denotes the currently detected hand gesture
///
[RequireComponent(typeof(TextMeshProUGUI))]
public class XRSelectedHandShapeDebugUI : MonoBehaviour
{
///
/// The string displayed when no gesture is detected
///
const string k_NoGestureDetectedString = "None Detected";
[SerializeField]
[Tooltip("The label that will be used to display the name of the hand shape.")]
TextMeshProUGUI m_HandShapeNameLabel;
///
/// The text label that denotes and displays the currently detected hand gesture
///
public TextMeshProUGUI handShapeNameLabel
{
get => m_HandShapeNameLabel;
set => m_HandShapeNameLabel = value;
}
void Awake()
{
m_HandShapeNameLabel.text = k_NoGestureDetectedString;
}
///
/// Update the text label that denotes the currently detected hand gesture
///
/// The pose or shape whose name will be displayed
public void UpdateSelectedHandshapeTextUI(ScriptableObject handPoseOrShape)
{
var handShape = handPoseOrShape as XRHandShape;
var handPose = handPoseOrShape as XRHandPose;
if (handShape)
m_HandShapeNameLabel.text = handShape.name;
else if (handPose)
m_HandShapeNameLabel.text = handPose.name;
}
///
/// Update the text label that denote that no hand gesture is currently detected
///
public void ResetUI()
{
m_HandShapeNameLabel.text = k_NoGestureDetectedString;
}
}
}