namespace UnityEngine.XR.Hands.Gestures { /// /// The calculated state of certain relative geometric properties of a /// finger from a given hand. Useful for pose detection. All values are /// normalized from 0 to 1. /// /// /// Do not construct this yourself. Only retrieve it from /// or /// . /// public struct XRFingerShape { internal XRFingerShapeTypes m_Types; internal float m_FullCurl; internal float m_BaseCurl; internal float m_TipCurl; internal float m_Pinch; internal float m_Spread; /// /// Each enabled flag signifies that the corresponding data was /// successfully updated. /// /// /// May not necessarily match the types passed to /// or /// , /// as data required for the calculations is not guaranteed to be available. /// public readonly XRFingerShapeTypes types => m_Types; /// /// Attempts to retrieve the full-curl value. /// /// /// If successful, will be set to the calculated full-curl value for the /// requested finger. /// /// /// Returns if successful and /// is set to a usable value. Otherwise, returns . /// /// /// Full-curl represents how curled the entire finger is. A value of /// 1 denotes a fully curled finger. /// public readonly bool TryGetFullCurl(out float fullCurl) { var isFullCurlValid = (m_Types & XRFingerShapeTypes.FullCurl) != 0; fullCurl = isFullCurlValid ? m_FullCurl : 0f; return isFullCurlValid; } /// /// Attempts to retrieve the base-curl value. /// /// /// If successful, will be set to the calculated base-curl value for the /// requested finger. /// /// /// Returns if successful and /// is set to a usable value. Otherwise, returns . /// /// /// Base-curl represents the extent that the proximal joint is bent. /// public readonly bool TryGetBaseCurl(out float baseCurl) { var isBaseCurlValid = (m_Types & XRFingerShapeTypes.BaseCurl) != 0; baseCurl = isBaseCurlValid ? m_BaseCurl : 0f; return isBaseCurlValid; } /// /// Attempts to retrieve the tip-curl value. /// /// /// If successful, will be set to the calculated tip-curl value for the /// requested finger. /// /// /// Returns if successful and /// is set to a usable value. Otherwise, returns . /// /// /// Tip curl represents how bent the top two joints of the finger or thumb are. /// This feature does not take the proximal joint into consideration. /// public readonly bool TryGetTipCurl(out float tipCurl) { var isTipCurlValid = (m_Types & XRFingerShapeTypes.TipCurl) != 0; tipCurl = isTipCurlValid ? m_TipCurl : 0f; return isTipCurlValid; } /// /// Attempts to retrieve the pinch value. /// /// /// If successful, will be set to the calculated pinch value for the /// requested finger. /// /// /// Returns if successful and /// is set to a usable value. Otherwise, returns . /// /// /// Pinch represents the strength of the pinch between the requested /// finger tip and the thumb tip. Will never be valid for the thumb /// (will always have a value of 0 and this method will always /// return ). /// public readonly bool TryGetPinch(out float pinch) { var isPinchValid = (m_Types & XRFingerShapeTypes.Pinch) != 0; pinch = isPinchValid ? m_Pinch : 0f; return isPinchValid; } /// /// Attempts to retrieve the spread value. /// /// /// If successful, will be set to the calculated spread value for the /// requested finger. /// /// /// Returns if successful and /// is set to a usable value. Otherwise, returns . /// /// /// Spread represents the normalized angle between two adjacent fingers, /// measured at the base of those two fingers. Will never be valid for /// the little finger (will always have a value of 0 and this /// method will always return ). /// public readonly bool TryGetSpread(out float spread) { var isSpreadValid = (m_Types & XRFingerShapeTypes.Spread) != 0; spread = isSpreadValid ? m_Spread : 0f; return isSpreadValid; } /// /// Clears the state by setting all the types to None. /// internal void Clear() => m_Types = XRFingerShapeTypes.None; } }