コード例 #1
0
        private OculusQuestController GetOrAddController(Handedness handedness)
        {
            if (trackedControllers.ContainsKey(handedness))
            {
                return(trackedControllers[handedness]);
            }

            var pointers        = RequestPointers(SupportedControllerType.ArticulatedHand, handedness);
            var inputSourceType = InputSourceType.Hand;

            IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;
            var inputSource = inputSystem?.RequestNewGenericInputSource($"Oculus Quest {handedness} Controller", pointers, inputSourceType);

            var controller = new OculusQuestController(TrackingState.Tracked, handedness, inputSource);

            // Code is obsolete later on, but older MRTK versions require it.
#pragma warning disable 618
            controller.SetupConfiguration(typeof(OculusQuestController));
#pragma warning restore 618

            for (int i = 0; i < controller.InputSource?.Pointers?.Length; i++)
            {
                controller.InputSource.Pointers[i].Controller = controller;
            }

            inputSystem?.RaiseSourceDetected(controller.InputSource, controller);

            trackedControllers.Add(handedness, controller);

            return(controller);
        }
コード例 #2
0
        private OculusQuestController GetOrAddController(Handedness handedness)
        {
            if (trackedControllers.ContainsKey(handedness))
            {
                return(trackedControllers[handedness]);
            }

            var pointers        = RequestPointers(SupportedControllerType.ArticulatedHand, handedness);
            var inputSourceType = InputSourceType.Hand;

            IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;
            var inputSource = inputSystem?.RequestNewGenericInputSource($"Oculus Quest {handedness} Controller", pointers, inputSourceType);

            var controller = new OculusQuestController(TrackingState.Tracked, handedness, inputSource);

            for (int i = 0; i < controller.InputSource?.Pointers?.Length; i++)
            {
                controller.InputSource.Pointers[i].Controller = controller;
            }

            inputSystem?.RaiseSourceDetected(controller.InputSource, controller);

            trackedControllers.Add(handedness, controller);

            return(controller);
        }
コード例 #3
0
        private OculusQuestController GetOrAddController(Handedness handedness)
        {
            if (trackedControllers.ContainsKey(handedness))
            {
                return(trackedControllers[handedness]);
            }

            var pointers        = RequestPointers(SupportedControllerType.ArticulatedHand, handedness);
            var inputSourceType = InputSourceType.Hand;

            IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;
            var inputSource = inputSystem?.RequestNewGenericInputSource($"Oculus Quest {handedness} Controller", pointers, inputSourceType);

            if (!inactiveControllerCache.TryGetValue(handedness, out var controller))
            {
                controller = new OculusQuestController(TrackingState.Tracked, handedness, inputSource);
                controller.UpdateAvatarMaterial(MRTKOculusConfig.Instance.CustomHandMaterial);
            }
            inactiveHandCache.Remove(handedness);
            controller.ApplyHandMaterial();

            for (int i = 0; i < controller.InputSource?.Pointers?.Length; i++)
            {
                controller.InputSource.Pointers[i].Controller = controller;
            }

            if (MRTKOculusConfig.Instance.ActiveTeleportPointerMode == MRTKOculusConfig.TeleportPointerMode.Custom && MixedRealityToolkit.IsTeleportSystemEnabled)
            {
                if (!teleportPointers.TryGetValue(handedness, out CustomTeleportPointer pointer))
                {
                    pointer = GameObject.Instantiate(MRTKOculusConfig.Instance.CustomTeleportPrefab).GetComponent <CustomTeleportPointer>();
                    pointer.gameObject.SetActive(false);
                    teleportPointers.Add(handedness, pointer);
                }
                pointer.Controller         = controller;
                controller.TeleportPointer = pointer;
            }

            inputSystem?.RaiseSourceDetected(controller.InputSource, controller);

            trackedControllers.Add(handedness, controller);

            return(controller);
        }
コード例 #4
0
        private void RemoveControllerDevice(OculusQuestController controller)
        {
            if (controller == null)
            {
                return;
            }
            CoreServices.InputSystem?.RaiseSourceLost(controller.InputSource, controller);
            trackedControllers.Remove(controller.ControllerHandedness);

            // Recycle pointers makes this loop obsolete. If you are using an MRTK version older than 2.3, please use the loop and comment out RecyclePointers.

            /*
             * foreach (IMixedRealityPointer pointer in controller.InputSource.Pointers)
             * {
             *  if (pointer == null) continue;
             *  pointer.Controller = null;
             * }
             */
            RecyclePointers(controller.InputSource);
        }
コード例 #5
0
        private void RemoveControllerDevice(OculusQuestController controller)
        {
            if (controller == null)
            {
                return;
            }
            CoreServices.InputSystem?.RaiseSourceLost(controller.InputSource, controller);
            trackedControllers.Remove(controller.ControllerHandedness);

            if (teleportPointers.TryGetValue(controller.ControllerHandedness, out CustomTeleportPointer pointer))
            {
                if (pointer == null)
                {
                    teleportPointers.Remove(controller.ControllerHandedness);
                }
                else
                {
                    pointer.Reset();
                }
                controller.TeleportPointer = null;
            }
            RecyclePointers(controller.InputSource);
        }