void Reset()
        {
            bodyMovements = (IVR_BodyMovements)target;
            InstantVR ivr = bodyMovements.GetComponent <InstantVR>();

            if (ivr == null)
            {
                Debug.LogWarning("Body Movements script requires Instant VR script on the game object");
                DestroyImmediate(bodyMovements);
                return;
            }

            IVR_BodyMovements[] bodyMovementsScripts = bodyMovements.GetComponents <IVR_BodyMovements>();
            if (bodyMovementsScripts.Length > 1)
            {
                Debug.LogError("You cant have more than one BodyMovements script");
                DestroyImmediate(bodyMovements); // why does it delete the first script, while target should be the new script...
                return;
            }

            Animator animator = bodyMovements.transform.GetComponentInChildren <Animator>();

            if (animator)
            {
                avatarGameObject = animator.gameObject;

                prefabPose = false;
                bodyMovements.StartMovements();
            }
        }
Exemple #2
0
        public void Initialize(InstantVR ivr, BodySide bodySide, IVR_BodyMovements bodyMovements)
        {
            this.ivr = ivr;

            this.bodySide = bodySide;
            animator      = ivr.GetComponentInChildren <Animator>();

            if (bodySide == BodySide.Left)
            {
                upperArm = animator.GetBoneTransform(HumanBodyBones.LeftUpperArm);
                forearm  = animator.GetBoneTransform(HumanBodyBones.LeftLowerArm);
                hand     = animator.GetBoneTransform(HumanBodyBones.LeftHand);

#if INSTANTVR_ADVANCED
                handMovements = ivr.leftHandMovements;
#endif
            }
            else
            {
                upperArm = animator.GetBoneTransform(HumanBodyBones.RightUpperArm);
                forearm  = animator.GetBoneTransform(HumanBodyBones.RightLowerArm);
                hand     = animator.GetBoneTransform(HumanBodyBones.RightHand);

#if INSTANTVR_ADVANCED
                handMovements = ivr.rightHandMovements;
#endif
            }

            if (upperArm != null)
            {
                upperArmLength = Vector3.Distance(upperArm.position, forearm.position);
                forearmLength  = Vector3.Distance(forearm.position, hand.position);
                length         = upperArmLength + forearmLength;
                if (length == 0)
                {
                    Debug.LogError("Avatar arm positions are incorrect. Please restore avatar in T-pose.");
                }

                upperArmLength2 = upperArmLength * upperArmLength;
                forearmLength2  = forearmLength * forearmLength;

                upperArmStartPosition = upperArm.position;
            }
        }
Exemple #3
0
        public bool IsInTPose()
        {
            float d;
            Ray   hip2foot = new Ray(upperLeg.position, foot.position - upperLeg.position);

            // All lined up?
            d = IVR_BodyMovements.DistanceToRay(hip2foot, lowerLeg.position);
            if (d > 0.1f)
            {
                return(false);
            }

            // All vertical?
            if (Mathf.Abs(hip2foot.direction.x) > 0.2f)
            {
                return(false);
            }
            if (Mathf.Abs(hip2foot.direction.z) > 0.2f)
            {
                return(false);
            }

            return(true);
        }
Exemple #4
0
 public ArmMovements(InstantVR ivr, BodySide bodySide, IVR_BodyMovements bodyMovements)
 {
     Initialize(ivr, bodySide, bodyMovements);
 }
Exemple #5
0
        protected virtual void Awake()
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;

            extensions = this.GetComponents <IVR_Extension>();
            foreach (IVR_Extension extension in extensions)
            {
                extension.StartExtension(this);
            }

            headControllers      = headTarget.GetComponents <IVR_Controller>();
            leftHandControllers  = leftHandTarget.GetComponents <IVR_Controller>();
            rightHandControllers = rightHandTarget.GetComponents <IVR_Controller>();
            hipControllers       = hipTarget.GetComponents <IVR_Controller>();
            leftFootControllers  = leftFootTarget.GetComponents <IVR_Controller>();
            rightFootControllers = rightFootTarget.GetComponents <IVR_Controller>();

            headController      = FindActiveController(headControllers);
            leftHandController  = FindActiveController(leftHandControllers);
            rightHandController = FindActiveController(rightHandControllers);
            hipController       = FindActiveController(hipControllers);
            leftFootController  = FindActiveController(leftFootControllers);
            rightFootController = FindActiveController(rightFootControllers);

            headMovements = headTarget.GetComponent <IVR_Movements>();

            leftHandMovements = leftHandTarget.GetComponent <IVR_HandMovementsBase>();
            if (leftHandMovements != null)
            {
                leftHandMovements.selectedController = (IVR_HandController)FindActiveController(leftHandControllers);
            }

            rightHandMovements = rightHandTarget.GetComponent <IVR_HandMovementsBase>();
            if (rightHandMovements != null)
            {
                rightHandMovements.selectedController = (IVR_HandController)FindActiveController(rightHandControllers);
            }


            Animator[] animators = GetComponentsInChildren <Animator>();
            for (int i = 0; i < animators.Length; i++)
            {
                Avatar avatar = animators[i].avatar;
                if (avatar.isValid && avatar.isHuman)
                {
                    characterTransform = animators[i].transform;

                    AddRigidbody(characterTransform.gameObject);
                    bodyCapsule = AddHipCollider(hipTarget.gameObject, proximitySpeed);
                }
            }

            foreach (IVR_Controller c in headControllers)
            {
                c.StartController(this);
            }
            foreach (IVR_Controller c in leftHandControllers)
            {
                c.StartController(this);
            }
            foreach (IVR_Controller c in rightHandControllers)
            {
                c.StartController(this);
            }
            foreach (IVR_Controller c in hipControllers)
            {
                c.StartController(this);
            }
            foreach (IVR_Controller c in leftFootControllers)
            {
                c.StartController(this);
            }
            foreach (IVR_Controller c in rightFootControllers)
            {
                c.StartController(this);
            }

            IVR_BodyMovements bm = GetComponent <IVR_BodyMovements>();

            if (bm != null)
            {
                bm.StartMovements();
            }

            if (headMovements && headMovements.enabled)
            {
                headMovements.StartMovements(this);
            }
            if (leftHandMovements != null && leftHandMovements.enabled)
            {
                leftHandMovements.StartMovements(this);
            }
            if (rightHandMovements != null && rightHandMovements.enabled)
            {
                rightHandMovements.StartMovements(this);
            }
        }
Exemple #6
0
        protected virtual void Awake()
        {
            Screen.sleepTimeout = SleepTimeout.NeverSleep;

            extensions = this.GetComponents <IVR_Extension>();
            foreach (IVR_Extension extension in extensions)
            {
                extension.StartExtension(this);
            }

            headControllers      = headTarget.GetComponents <IVR_Controller>();
            leftHandControllers  = leftHandTarget.GetComponents <IVR_Controller>();
            rightHandControllers = rightHandTarget.GetComponents <IVR_Controller>();
            hipControllers       = hipTarget.GetComponents <IVR_Controller>();
            leftFootControllers  = leftFootTarget.GetComponents <IVR_Controller>();
            rightFootControllers = rightFootTarget.GetComponents <IVR_Controller>();

            headController      = FindActiveController(headControllers);
            leftHandController  = FindActiveController(leftHandControllers);
            rightHandController = FindActiveController(rightHandControllers);
            hipController       = FindActiveController(hipControllers);
            leftFootController  = FindActiveController(leftFootControllers);
            rightFootController = FindActiveController(rightFootControllers);

            headMovements = headTarget.GetComponent <IVR_Movements>();

            leftHandMovements = leftHandTarget.GetComponent <IVR_HandMovementsBase>();
            if (leftHandMovements != null)
            {
                leftHandMovements.selectedController = (IVR_HandController)FindActiveController(leftHandControllers);
            }

            rightHandMovements = rightHandTarget.GetComponent <IVR_HandMovementsBase>();
            if (rightHandMovements != null)
            {
                rightHandMovements.selectedController = (IVR_HandController)FindActiveController(rightHandControllers);
            }

            DetermineAvatar();

            foreach (IVR_Controller c in headControllers)
            {
                c.StartController(this);
            }
            foreach (IVR_Controller c in leftHandControllers)
            {
                c.StartController(this);
            }
            foreach (IVR_Controller c in rightHandControllers)
            {
                c.StartController(this);
            }
            foreach (IVR_Controller c in hipControllers)
            {
                c.StartController(this);
            }
            foreach (IVR_Controller c in leftFootControllers)
            {
                c.StartController(this);
            }
            foreach (IVR_Controller c in rightFootControllers)
            {
                c.StartController(this);
            }

            bodyMovements = GetComponent <IVR_BodyMovements>();
            if (bodyMovements != null)
            {
                bodyMovements.StartMovements();
            }

            if (headMovements && headMovements.enabled)
            {
                headMovements.StartMovements(this);
            }
            if (leftHandMovements != null && leftHandMovements.enabled)
            {
                leftHandMovements.StartMovements(this);
            }
            if (rightHandMovements != null && rightHandMovements.enabled)
            {
                rightHandMovements.StartMovements(this);
            }

            InitGroundcheck();
        }