Пример #1
0
        private void TrySetHandActive(VRAvatarLimbType limbType)
        {
            var isLimbConnected = OVRUtils.IsLimbConnected(limbType);
            var limb            = mAvatar.GetLimb(limbType);

            limb.SetActive(isLimbConnected);
        }
Пример #2
0
        private void AttachControllerVisual(VRAvatarController avatarController)
        {
            var limb = avatarController.GetComponentInParent <IVRAvatarLimb>();

            var prefab = VRAvatarHelper.EnsureLoadPrefab <VRControllerVisual>(ControllerVisualPrefabName);

            prefab.gameObject.SetActive(false);

            // Create controller instance
            var instance = Instantiate(prefab);

            instance.name = prefab.name;
            instance.transform.SetParentAndIdentity(avatarController.transform);

            // Make sure the OVRGearVrController component exists...
            var trackedRemote = instance.gameObject.GetComponent <OVRControllerHelper>();

            if (trackedRemote == null)
            {
                trackedRemote = instance.gameObject.AddComponent <OVRControllerHelper>();
            }

            avatarController.ControllerVisual = instance;
            mRemotes.Add(trackedRemote);

            // Assign the correct controller based on the limb type the controller is attached to
            OVRInput.Controller controllerType = GetControllerTypeForLimb(limb);
            trackedRemote.m_controller = controllerType;
            trackedRemote.m_modelGearVrController.SetActive(true);

            // Activate the controller
            // TODO Do we need to set active here?
            var active = OVRUtils.IsLimbConnected(limb.LimbType);

            instance.gameObject.SetActive(active);

            Debug.Log($"Attached Controller: {limb.LimbType} and SetActive: {active} Controller Type set to: {controllerType}");
        }
Пример #3
0
        private void UpdateConnectedControllers()
        {
            var allControllers   = new List <IVRInputDevice>();
            var disconnectedList = new List <IVRInputDevice>();
            var connectedList    = new List <IVRInputDevice>();

            var ctrlMask = OVRInput.GetConnectedControllers();

            // NOTE: Controller tests here are in order of priority. Active hand controllers take priority over headset

            #region Controller
            var leftHandConnected  = OVRUtils.IsLimbConnected(VRAvatarLimbType.LeftHand);
            var rightHandConnected = OVRUtils.IsLimbConnected(VRAvatarLimbType.RightHand);

            Debug.Log($"Left Hand Connected: {leftHandConnected}");
            Debug.Log($"Right Hand Connected: {rightHandConnected}");

            // The order the controllers are added currently determines the PrimaryInput however,
            // It does not seem to determine the primary pointer.
            if (rightHandConnected)
            {
                mPrimaryController = mPrimaryController ?? new GearVRController(VRInputDeviceHand.Right);

                if (!mInputDevices.Contains(mPrimaryController))
                {
                    connectedList.Add(mPrimaryController);
                }

                allControllers.Add(mPrimaryController);
            }
            else
            {
                disconnectedList.Add(mPrimaryController);
            }

            if (leftHandConnected)
            {
                mSecondaryController = mSecondaryController ?? new GearVRController(VRInputDeviceHand.Left);

                if (!mInputDevices.Contains(mSecondaryController))
                {
                    connectedList.Add(mSecondaryController);
                }

                allControllers.Add(mSecondaryController);
            }
            else
            {
                disconnectedList.Add(mSecondaryController);
            }
            #endregion

            #region Headset (Swipe-pad)

            if (Headset is GearVRHeadset)
            {
                var gearVRHeadset = Headset as GearVRHeadset;

                if ((ctrlMask & OVRInput.Controller.Touchpad) != 0)
                {
                    if (!mHeadsetInputConnected)
                    {
                        connectedList.Add(gearVRHeadset);
                        mHeadsetInputConnected = true;
                    }

                    allControllers.Add(gearVRHeadset);
                }
                else if (Headset != null)
                {
                    disconnectedList.Add(gearVRHeadset);
                    mHeadsetInputConnected = false;
                }
            }
            #endregion

            // Update internal state
            mInputDevices            = allControllers.ToArray();
            mConnectedControllerMask = ctrlMask;

            foreach (var device in disconnectedList)
            {
                InputDeviceDisconnected?.Invoke(this, device);
            }

            foreach (var device in connectedList)
            {
                InputDeviceConnected?.Invoke(this, device);
            }

            // Force an update of input devices
            UpdateInputDevices();
        }