using System; using System.Text; using UnityEngine.XR.ARSubsystems; using Unity.Collections; using Object = UnityEngine.Object; namespace UnityEngine.XR.ARFoundation { /// /// Trackable human body containing the base pose for the body and the body skeleton. /// [DisallowMultipleComponent] [DefaultExecutionOrder(ARUpdateOrder.k_HumanBody)] [HelpURL(typeof(ARHumanBody))] public class ARHumanBody : ARTrackable, IDisposable { /// /// The scale factor that relates the implementation's default body height to the estimated height. /// /// /// The scale factor that relates the implementation's default body height to the estimated height. /// public float estimatedHeightScaleFactor => sessionRelativeData.estimatedHeightScaleFactor; /// /// The array of joints making up the human body skeleton. /// /// /// The array of joints making up the human body skeleton. /// public NativeArray joints => m_Joints; NativeArray m_Joints; /// /// Update the skeleton for the human body from the subsystem. /// /// The human body subsystem from which to query the skeleton. internal void UpdateSkeleton(XRHumanBodySubsystem bodySubsystem) { bodySubsystem.GetSkeleton(trackableId, Allocator.Persistent, ref m_Joints); } /// /// Generates a string representation of this . Floating point numbers /// use 3 digits of precision after the decimal point. /// /// A string representation of this . public override string ToString() => ToString("0.000"); /// /// Generates a string representation of this . /// /// The floating point format specifier used for floating point properties. /// A string representation of this . public string ToString(string floatingPointFormat) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0} [trackableId:{1} pose:{2} numJoints:{3} state:{4}]", name, trackableId.ToString(), pose.ToString(floatingPointFormat), joints.Length, trackingState.ToString()); foreach (var joint in m_Joints) { sb.AppendFormat("\n {0}", joint.ToString(floatingPointFormat)); } return sb.ToString(); } /// /// Disposes the array, if it was created. /// public void Dispose() { if (m_Joints.IsCreated) { m_Joints.Dispose(); } } void OnDestroy() => Dispose(); } }