Exemple #1
0
        /// <summary>
        /// Remove the selected controller from the Active Store
        /// </summary>
        /// <param name="interactionSourceState">Source State provided by the SDK to remove</param>
        private void RemoveController(InteractionSource interactionSource)
        {
            var controller = GetController(interactionSource, false);

            if (controller != null)
            {
                IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;

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

                foreach (IMixedRealityPointer pointer in controller.InputSource.Pointers)
                {
                    if (pointer != null)
                    {
                        pointer.Controller = null;
                    }
                }

                if (controller.Visualizer != null &&
                    controller.Visualizer.GameObjectProxy != null)
                {
                    controller.Visualizer.GameObjectProxy.SetActive(false);
                }
            }

            activeControllers.Remove(interactionSource.id);
        }
        private void RefreshDevices()
        {
            Profiler.BeginSample("[MRTK] UnityJoystickManager.RefreshDevices");

            IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;

            var joystickNames = UInput.GetJoystickNames();

            if (joystickNames.Length <= 0)
            {
                Profiler.EndSample(); // RefreshDevices - no devices
                return;
            }

            if (lastDeviceList != null && joystickNames.Length == lastDeviceList.Length)
            {
                for (int i = 0; i < lastDeviceList.Length; i++)
                {
                    if (joystickNames[i].Equals(lastDeviceList[i]))
                    {
                        continue;
                    }

                    if (ActiveControllers.ContainsKey(lastDeviceList[i]))
                    {
                        var controller = GetOrAddController(lastDeviceList[i]);

                        if (controller != null)
                        {
                            inputSystem?.RaiseSourceLost(controller.InputSource, controller);
                        }

                        RemoveController(lastDeviceList[i]);
                    }
                }
            }

            for (var i = 0; i < joystickNames.Length; i++)
            {
                if (string.IsNullOrEmpty(joystickNames[i]))
                {
                    continue;
                }

                if (!ActiveControllers.ContainsKey(joystickNames[i]))
                {
                    var controller = GetOrAddController(joystickNames[i]);

                    if (controller != null)
                    {
                        inputSystem?.RaiseSourceDetected(controller.InputSource, controller);
                    }
                }
            }

            lastDeviceList = joystickNames;

            Profiler.EndSample(); // RefreshDevices
        }
        private void RefreshDevices()
        {
            IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;

            var joystickNames = UInput.GetJoystickNames();

            if (joystickNames.Length <= 0)
            {
                return;
            }

            if (lastDeviceList != null && joystickNames.Length == lastDeviceList.Length)
            {
                for (int i = 0; i < lastDeviceList.Length; i++)
                {
                    if (joystickNames[i].Equals(lastDeviceList[i]))
                    {
                        continue;
                    }

                    if (ActiveControllers.ContainsKey(lastDeviceList[i]))
                    {
                        var controller = GetOrAddController(lastDeviceList[i]);

                        if (controller != null)
                        {
                            inputSystem?.RaiseSourceLost(controller.InputSource, controller);
                        }

                        ActiveControllers.Remove(lastDeviceList[i]);
                    }
                    else
                    {
                        Debug.Log("Controller does not contains kye");
                    }
                }
            }

            for (var i = 0; i < joystickNames.Length; i++)
            {
                if (string.IsNullOrEmpty(joystickNames[i]))
                {
                    continue;
                }

                if (!ActiveControllers.ContainsKey(joystickNames[i]))
                {
                    var controller = GetOrAddController(joystickNames[i]);

                    if (controller != null)
                    {
                        inputSystem?.RaiseSourceDetected(controller.InputSource, controller);
                    }
                }
            }

            lastDeviceList = joystickNames;
        }
        /// <inheritdoc />
        public override void Disable()
        {
            IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;

            if (Controller != null)
            {
                inputSystem?.RaiseSourceLost(Controller.InputSource, Controller);
            }
        }
Exemple #5
0
    void UnplugSimulatedMotionController(Handedness controllerHandedness)
    {
        var motionController = SimulatedMotionControllerDictionary[controllerHandedness];

        IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;

        inputSystem?.RaiseSourceLost(motionController.InputSource, motionController);

        SimulatedMotionControllerDictionary.Remove(controllerHandedness);
    }
        private void RemoveTouchController(Touch touch)
        {
            UnityTouchController controller;

            if (!ActiveTouches.TryGetValue(touch.fingerId, out controller))
            {
                return;
            }

            controller.EndTouch();
            IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;

            inputSystem?.RaiseSourceLost(controller.InputSource, controller);
        }
        /// <inheritdoc />
        public override void Disable()
        {
            IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;

            foreach (var genericJoystick in ActiveControllers)
            {
                if (genericJoystick.Value != null)
                {
                    inputSystem?.RaiseSourceLost(genericJoystick.Value.InputSource, genericJoystick.Value);
                }
            }

            ActiveControllers.Clear();
        }
Exemple #8
0
        void MLControllerDisconnected(byte controllerId)
        {
            MLControllerContainer controllerContainer = GetConnectedController(controllerId);

            if (controllerContainer != null)
            {
                IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;
                inputSystem?.RaiseSourceLost(controllerContainer.mrtkController.InputSource, controllerContainer.mrtkController);
                trackedControls.Remove(controllerContainer.mrtkController);
                RecyclePointers(controllerContainer.mrtkController.InputSource);
                controllerContainer.mrtkController.CleanupController();
                ConnectedControllers.Remove(controllerId);
            }
            return;
        }
        public override void Disable()
        {
            base.Disable();

            IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;

            foreach (var hand in trackedHands)
            {
                if (hand.Value != null)
                {
                    inputSystem?.RaiseSourceLost(hand.Value.InputSource, hand.Value);
                }
            }

            trackedHands.Clear();
        }
        /// <inheritdoc />
        public override void Disable()
        {
            IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;

            foreach (var controller in ActiveTouches)
            {
                if (controller.Value == null || inputSystem == null)
                {
                    continue;
                }

                foreach (var inputSource in inputSystem.DetectedInputSources)
                {
                    if (inputSource.SourceId == controller.Value.InputSource.SourceId)
                    {
                        inputSystem.RaiseSourceLost(controller.Value.InputSource, controller.Value);
                    }
                }
            }

            ActiveTouches.Clear();
        }
        /// <inheritdoc />
        public override void Disable()
        {
            if (!IsAvailable)
            {
                return;
            }
            enabled = false;
            IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;

            if (Controller != null)
            {
                inputSystem?.RaiseSourceLost(Controller.InputSource, Controller);

                Cursor.visible   = true;
                Cursor.lockState = CursorLockMode.None;
                foreach (var pt in Controller.InputSource.Pointers)
                {
                    pt.BaseCursor = null;
                    var pointer = pt as MousePointer;
                    GameObject.DestroyImmediate(pointer.gameObject);
                }
            }
        }
Exemple #12
0
        private void HandleOnControllerDisconnected(byte controllerId)
        {
            mlInputControllers.RemoveAll((device) => device.Id == controllerId);

            MagicLeapController controller;

            if (ActiveControllers.TryGetValue(controllerId, out controller))
            {
                IMixedRealityInputSystem inputSystem = Service as IMixedRealityInputSystem;

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

                foreach (IMixedRealityPointer pointer in controller.InputSource.Pointers)
                {
                    if (pointer != null)
                    {
                        pointer.Controller = null;
                    }
                }

                ActiveControllers.Remove(controllerId);
            }
        }