Ejemplo n.º 1
0
 public void AutoDetectReferences()
 {
     if (!CustomVRIKReferences.AutoDetectReferences(transform, out references))
     {
         if (Application.isPlaying)                //don't do it in the editor mode
         {
             enabled = false;
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Reinitializes the IK and Solver.
        /// </summary>
        public void ReInitialize()
        {
            Debug.Log($"Reinit CustomVRIK");
            solver.initiated   = false;
            componentInitiated = false;
            FindAnimatorRecursive(transform, true);

            //We only call the base solver because on reinit we will want to assume
            //that the avatar has been replaced, and we'll need to find the data component that can be used to retreieve it.
            IAvatarIKReferenceContainer <CustomVRIKReferences> referenceContainer = this.GetComponentInChildren <IAvatarIKReferenceContainer <CustomVRIKReferences> >();

            //If we contain no reference data
            //then we should just autodetect and wish for the best
            //though this could cost performance issues on failure maybe?
            if (referenceContainer == null)
            {
                Debug.LogWarning($"Failed to find IK reference container.");
                AutoDetectReferences();
            }
            else
            {
                //Set the references in the IK controller
                this.references = referenceContainer.references;

                //We should do nothing if the references are empty.
                if (references.isEmpty)
                {
                    return;
                }

                var oldSolver = solver;
                solver = new IKSolverVR
                {
                    spine    = { headTarget = oldSolver.spine.headTarget },
                    leftArm  = { target = oldSolver.leftArm.target },
                    rightArm = { target = oldSolver.rightArm.target }
                };

                //First let's set the trackers to the appropriate local rotation
                //These compute from precomputed EULER angles from the SDK.
                solver.leftArm.target.localEulerAngles   = references.LocalLeftHandRotation;
                solver.rightArm.target.localEulerAngles  = references.LocalRightHandRotation;
                solver.spine.headTarget.localEulerAngles = references.LocalHeadRotation;

                solver.SetToReferences(references);
            }

            base.InitiateSolver();
            componentInitiated = true;
        }