//[HideInInspector]
        //private IVR_HandMovements handMovements;

        public override void StartController(InstantVR ivr)
        {
            extension = ivr.GetComponent <IVR_Animator>();
            base.StartController(ivr);

            animatorHip     = ivr.hipTarget.GetComponent <IVR_AnimatorHip>();
            lastHipPosition = ivr.hipTarget.position;

            //handMovements = GetComponent<IVR_HandMovements>();

            hip2hand = Quaternion.Inverse(ivr.transform.rotation) * (ivr.hipTarget.position - this.transform.position);
            if (this.transform == ivr.leftHandTarget)
            {
                foot2hand      = Quaternion.Inverse(ivr.transform.rotation) * (ivr.leftHandTarget.position - ivr.rightFootTarget.position);
                footController = ivr.rightFootTarget.GetComponent <IVR_Controller>();
            }
            else
            {
                foot2hand      = Quaternion.Inverse(ivr.transform.rotation) * (ivr.rightHandTarget.position - ivr.leftFootTarget.position);
                footController = ivr.leftFootTarget.GetComponent <IVR_Controller>();
            }

            if (footController.GetType() == typeof(IVR_AnimatorFoot) && !footController.enabled)
            {
                footController = null;
            }
        }
 private int FindControllerIndex(IVR_Controller[] controllers, IVR_Controller controller)
 {
     for (int i = 0; i < controllers.Length; i++)
     {
         if (controllers[i] == controller)
         {
             return(i);
         }
     }
     return(-1);
 }
Beispiel #3
0
        public void OnEnable()
        {
            IVR_Controller ivrController = (IVR_Controller)target;
            IVR_Extension  ivrExtension  = ivrController.extension;

            if (ivrExtension == null)
            {
                //Debug.Log ("Destroyed Extension, removing Controller: " + ivrController);
                DestroyImmediate(ivrController, true);
            }
        }
        protected void MoveUp(IVR_Controller controller)
        {
            IVR_Controller[] controllers = controller.gameObject.GetComponents <IVR_Controller>();
            int controllerIndex          = FindControllerIndex(controllers, controller);

            if (controllerIndex > 0)
            {
                if (controllers[controllerIndex].extension != null && controllers[controllerIndex - 1].extension != null)
                {
                    if (controllers[controllerIndex].extension.priority <= controllers[controllerIndex - 1].extension.priority + 1)
                    {
                        UnityEditorInternal.ComponentUtility.MoveComponentUp(controllers[controllerIndex]);
                    }
                }
            }
        }
        protected void MoveDown(IVR_Controller controller)
        {
            IVR_Controller[] controllers = controller.gameObject.GetComponents <IVR_Controller>();
            int controllerIndex          = FindControllerIndex(controllers, controller);

            if (controllerIndex > -1 && controllerIndex < controllers.Length - 1)
            {
                if (controllers[controllerIndex].extension != null && controllers[controllerIndex + 1].extension != null)
                {
                    if (controllers[controllerIndex].extension.priority >= controllers[controllerIndex + 1].extension.priority - 1)
                    {
                        UnityEditorInternal.ComponentUtility.MoveComponentDown(controllers[controllerIndex]);
                    }
                }
            }
        }
Beispiel #6
0
        private void UpdateControllers()
        {
            if (leftHandMovements != null)
            {
                leftHandMovements.selectedController = (IVR_HandController)UpdateController(leftHandControllers, leftHandMovements.selectedController);
            }
            if (rightHandMovements != null)
            {
                rightHandMovements.selectedController = (IVR_HandController)UpdateController(rightHandControllers, rightHandMovements.selectedController);
            }

            hipController       = UpdateController(hipControllers, hipController);
            leftFootController  = UpdateController(leftFootControllers, leftFootController);
            rightFootController = UpdateController(rightFootControllers, rightFootController);
            // Head needs to be after hands because of traditional controller.
            headController = UpdateController(headControllers, headController);
        }
Beispiel #7
0
        private IVR_Controller UpdateController(IVR_Controller[] controllers, IVR_Controller lastActiveController)
        {
            if (controllers != null)
            {
                int lastIndex = 0, newIndex = 0;

                IVR_Controller activeController = null;
                for (int i = 0; i < controllers.Length; i++)
                {
                    if (controllers[i] != null)
                    {
                        controllers[i].UpdateController();
                        if (activeController == null && controllers[i].isTracking())
                        {
                            activeController = controllers[i];
                            controllers[i].SetSelection(true);
                            newIndex = i;
                        }
                        else
                        {
                            controllers[i].SetSelection(false);
                        }

                        if (controllers[i] == lastActiveController)
                        {
                            lastIndex = i;
                        }
                    }
                }

                if (lastIndex < newIndex && lastActiveController != null)   // we are degreding
                {
                    activeController.TransferCalibration(lastActiveController);
                }

                return(activeController);
            }
            else
            {
                return(null);
            }
        }
 public void TransferCalibration(IVR_Controller lastController)
 {
 }
Beispiel #9
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);
            }
        }
Beispiel #10
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();
        }