Exemple #1
0
        /// <summary>
        /// Gets or creates a joint in the skeleton hierarchy.
        /// </summary>
        /// <param name="jointType">The target joint.</param>
        /// <returns>The created or found component instance.</returns>
        public KinectSkeletonJoint GetOrCreateJoint(JointType jointType)
        {
            var joint = GetJoint(jointType);

            if (joint != null)
            {
                return(joint);
            }

            var parent = GetParentJoint(jointType);

            joint = KinectSkeletonJoint.Create(jointType);
            joint.transform.position = transform.position + KinectHelper.tPose[(int)jointType];

            // This is required because changing the parent transform fires
            // the OnTransformChildrenChanged directly. Since rebuilding the
            // hierarchy is useless here, it will be skipped.
            SetJointParentWithoutRebuild(joint, parent == null ? transform : parent.transform);

            AddJointToHierarchy(joint);
            FixJointHierarchy(joint);

            return(joint);
        }