private void ProcessLine(LineSegment line, ref MLInputDevice inputDevice)
        {
            Vector3?endPoint = null;
            Vector3 normal   = Vector3.zero;

            MLInputDeviceEventData pointerEventData = _cachedTrackedPointerEventData;

            if (pointerEventData == null)
            {
                return;
            }

            pointerEventData.Reset();
            inputDevice.CopyTo(ref pointerEventData);
            pointerEventData.pointerCurrentRaycast = PerformRaycast(pointerEventData);
            GameObject currentRaycastObject = pointerEventData.pointerCurrentRaycast.gameObject;

            // enable cursor for any canvas UI or any game object with an Event Trigger (assuming camera has physics raycaster on it)
            if (currentRaycastObject != null &&
                (currentRaycastObject.GetComponent <RectTransform>() != null || currentRaycastObject.GetComponent <EventTrigger>() != null))
            {
                // Relies on TrackedDeviceRaycaster and 3D world position to work with event system
                RaycastResult result = pointerEventData.pointerCurrentRaycast;
                endPoint = result.worldPosition;
                normal   = result.worldNormal;
            }

            inputDevice.CopyFrom(pointerEventData);
            inputDevice.OnFrameFinished();

            line.Set(inputDevice.Position, endPoint, normal);
        }
        /// <summary/>
        protected override void Start()
        {
            base.Start();

            _headpose = Camera.main;
            if (_headpose == null)
            {
                Debug.LogError("Error: MLInputModule, no camera found tagged as MainCamera, disabling script.");
                enabled = false;
                return;
            }

            // Eye Tracking
            if (_pointerInput == PointerInputType.EyeTracking)
            {
                #if PLATFORM_LUMIN
                MLResult result = MLEyes.Start();
                if (!result.IsOk)
                {
                    Debug.LogErrorFormat("Error: MLInputModule failed starting MLEyes, disabling script. Reason: {0}", result);
                    enabled = false;
                    return;
                }
                #endif
            }

            #if PLATFORM_LUMIN
            // Controllers
            if (!MLInput.IsStarted)
            {
                MLInput.Configuration config = new MLInput.Configuration(true);
                MLResult result = MLInput.Start(config);
                if (!result.IsOk)
                {
                    Debug.LogErrorFormat("Error: MLInputModule failed starting MLInput, disabling script. Reason: {0}", result);
                    enabled = false;
                    return;
                }
            }
            #endif

            AddController(0);
            AddController(1);

            #if PLATFORM_LUMIN
            // Track connect / disconnect
            MLInput.OnControllerConnected    += HandleOnControllerConnected;
            MLInput.OnControllerDisconnected += HandleOnControllerDisconnected;

            _pointerInputDevice = new MLInputDevice();
            _pointerInputDevice.Initialize();
            _cachedTrackedPointerEventData = new MLInputDeviceEventData(eventSystem);
            #endif
        }
        private void ProcessTrackedDevice(ref MLInputDevice deviceState)
        {
            var eventData = _cachedTrackedPointerEventData;

            eventData.Reset();
            deviceState.CopyTo(ref eventData);

            eventData.button = PointerEventData.InputButton.Left;
            eventData.pointerCurrentRaycast = PerformRaycast(eventData);

            ProcessButton(deviceState.SelectDelta, ref eventData);
            ProcessMovement(eventData);
            ProcessScroll(eventData);

            deviceState.CopyFrom(eventData);
            deviceState.OnFrameFinished();
        }
        /// <summary/>
        protected override void Start()
        {
            base.Start();

            if (_mainCanvas == null)
            {
                Debug.LogError("Error: MLInputModule, _mainCanvas field is empty, disabling script.");
                enabled = false;
                return;
            }

            _mainCamera = Camera.main;

            if (_mainCamera == null)
            {
                Debug.LogError("Error: MLInputModule, no camera found tagged as MainCamera, disabling script.");
                enabled = false;
                return;
            }

            _mainCanvas.worldCamera = _mainCamera;

            SceneManager.activeSceneChanged += ChangedActiveScene;

            #if PLATFORM_LUMIN
            // Controllers
            if (!MLInput.IsStarted)
            {
                MLInput.Configuration config = new MLInput.Configuration(true);
                MLInput.SetConfig(config);
            }
            #endif

            AddController(0);
            AddController(1);

            #if PLATFORM_LUMIN
            // Track connect / disconnect
            MLInput.OnControllerConnected    += HandleOnControllerConnected;
            MLInput.OnControllerDisconnected += HandleOnControllerDisconnected;

            _pointerInputDevice = new MLInputDevice();
            _pointerInputDevice.Initialize();
            _cachedTrackedPointerEventData = new MLInputDeviceEventData(eventSystem);
            #endif
        }