Exemple #1
0
        /// <summary>
        /// Update the controller touchpad data.
        /// </summary>
        /// <param name="controller">The controller device.</param>
        /// <param name="scrollFactor">scrolling amount factor.</param>
        public void UpdateTouch(MLInput.Controller controller, float scrollFactor = 1.0f)
        {
            if (controller == null || !controller.Connected)
            {
                return;
            }

            Vector2 newTouchPosition = Vector2.zero;

            if (controller.Touch1Active)
            {
                // Note: X is flipped
                newTouchPosition = new Vector2(-controller.Touch1PosAndForce.x, controller.Touch1PosAndForce.y);
            }

            if (this.TouchActive)
            {
                if (controller.Touch1Active)
                {
                    // touch continues
                    this.ScrollDelta = (newTouchPosition - this.touchPosition) * scrollFactor;
                }
                else
                {
                    // touch ended
                    this.ScrollDelta = Vector2.zero;
                }
            }

            this.TouchActive   = controller.Touch1Active;
            this.touchPosition = newTouchPosition;
        }
        /// <summary>
        /// Process the input for headpose, eye tracking, controls and standard Unity Editor input (Keyboard, Mouse, Joystick).
        /// </summary>
        public override void Process()
        {
            switch (_pointerInput)
            {
            case PointerInputType.Headpose:
            {
                    #if PLATFORM_LUMIN
                // Convert from Local position, to world position.
                _pointerInputDevice.Position    = transform.TransformPoint(_headpose.transform.position);
                _pointerInputDevice.Orientation = _headpose.transform.rotation;
                    #endif

                break;
            }

            case PointerInputType.EyeTracking:
            {
                    #if PLATFORM_LUMIN
                // Convert from Local position, to world position.
                _pointerInputDevice.Position = transform.TransformPoint(_headpose.transform.position);
                if (MLEyes.IsStarted)
                {
                    _pointerInputDevice.Orientation = Quaternion.LookRotation(MLEyes.FixationPoint - _headpose.transform.position);
                }
                    #endif

                break;
            }

            case PointerInputType.Controller:
            {
                if (_controllers.Count > 0)
                {
                    MLInput.Controller controller = _controllers[0];

                        #if PLATFORM_LUMIN
                    // Convert from Local position, to world position.
                    _pointerInputDevice.Position    = transform.TransformPoint(controller.Position);
                    _pointerInputDevice.Orientation = controller.Orientation;
                        #endif
                }
                break;
            }
            }

            #if PLATFORM_LUMIN
            ProcessLine(_pointerLineSegment, ref _pointerInputDevice);

            if (_controllers.Count > 0)
            {
                MLInput.Controller controller = _controllers[0];
                _pointerInputDevice.Select = IsClicked(controller);
                _pointerInputDevice.UpdateTouch(controller, _scrollSpeed);
            }

            ProcessTrackedDevice(ref _pointerInputDevice);
            #endif
        }
Exemple #3
0
        /// <summary>
        /// Checks if a controller exists, is connected, and is allowed.
        /// </summary>
        /// <param name="controller">The controller to be checked for</param>
        /// <returns>True if the controller exists, is connected, and is allowed</returns>
        private bool IsDeviceAllowed(MLInput.Controller controller)
        {
            #if PLATFORM_LUMIN
            if (controller == null || !controller.Connected)
            {
                return(false);
            }

            return(((_devicesAllowed & DeviceTypesAllowed.MobileApp) != 0 && controller.Type == MLInput.Controller.ControlType.MobileApp) ||
                   ((_devicesAllowed & DeviceTypesAllowed.ControllerLeft) != 0 && controller.Type == MLInput.Controller.ControlType.Control && controller.Hand == MLInput.Hand.Left) ||
                   ((_devicesAllowed & DeviceTypesAllowed.ControllerRight) != 0 && controller.Type == MLInput.Controller.ControlType.Control && controller.Hand == MLInput.Hand.Right));
            #else
            return(false);
            #endif
        }
Exemple #4
0
        /// <summary>
        /// Fills allowed connected devices list with all the connected controllers matching
        /// types set in _devicesAllowed.
        /// </summary>
        private void GetAllowedInput()
        {
            _allowedConnectedDevices.Clear();

            #if PLATFORM_LUMIN
            for (int i = 0; i < 2; ++i)
            {
                MLInput.Controller controller = MLInput.GetController(i);
                if (IsDeviceAllowed(controller) && !_allowedConnectedDevices.Exists((device) => device.Id == controller.Id))
                {
                    _allowedConnectedDevices.Add(controller);
                }
            }
            #endif
        }
        /// <summary>
        /// Adds the connected controller if not yet added.
        /// </summary>
        /// <param name="controllerId">The id of the controller.</param>
        private void AddController(byte controllerId)
        {
            #if PLATFORM_LUMIN
            MLInput.Controller newController = MLInput.GetController(controllerId);
            if (_controllers.Exists((device) => device.Id == controllerId))
            {
                Debug.LogWarning(string.Format("Connected controller with id {0} already connected.", controllerId));
                return;
            }

            if (newController.Connected)
            {
                _controllers.Add(newController);
            }
            #endif
        }
        private bool IsClicked(MLInput.Controller controller)
        {
            #if PLATFORM_LUMIN
            if (controller != null && controller.Connected)
            {
                if (_buttonClick == ButtonClickType.Bumper)
                {
                    return(controller.IsBumperDown);
                }

                if (_buttonClick == ButtonClickType.Trigger)
                {
                    return(controller.TriggerValue >= _triggerDownThreshold);
                }
            }
            #endif

            return(false);
        }
Exemple #7
0
        /// <summary>
        /// Handles the event when a controller connects. If the connected controller
        /// is valid, we add it to the _allowedConnectedDevices list.
        /// </summary>
        /// <param name="controllerId">The id of the controller.</param>
        private void HandleOnControllerConnected(byte controllerId)
        {
            #if PLATFORM_LUMIN
            MLInput.Controller newController = MLInput.GetController(controllerId);
            if (IsDeviceAllowed(newController))
            {
                if (_allowedConnectedDevices.Exists((device) => device.Id == controllerId))
                {
                    Debug.LogWarning(string.Format("Connected controller with id {0} already connected.", controllerId));
                    return;
                }

                _allowedConnectedDevices.Add(newController);

                // Notify Listeners
                if (OnControllerConnected != null)
                {
                    OnControllerConnected.Invoke(controllerId);
                }
            }
            #endif
        }