/// <summary>
        /// Starts the MLInput, initializes the first controller, and registers the connection handlers
        /// </summary>
        void Start()
        {
            if (_devicesAllowed == 0)
            {
                Debug.LogErrorFormat("Error: ControllerConnectionHandler._devicesAllowed is invalid, disabling script.");
                enabled = false;
                return;
            }

            bool requestCFUID = DevicesAllowed.HasFlag(DeviceTypesAllowed.ControllerLeft) ||
                                DevicesAllowed.HasFlag(DeviceTypesAllowed.ControllerRight);

            if (!MLInput.IsStarted)
            {
                MLInputConfiguration config = new MLInputConfiguration(MLInputConfiguration.DEFAULT_TRIGGER_DOWN_THRESHOLD,
                                                                       MLInputConfiguration.DEFAULT_TRIGGER_UP_THRESHOLD,
                                                                       requestCFUID);
                MLResult result = MLInput.Start(config);
                if (!result.IsOk)
                {
                    Debug.LogErrorFormat("Error: ControllerConnectionHandler failed starting MLInput, disabling script. Reason: {0}", result);
                    enabled = false;
                    return;
                }
            }

            MLInput.OnControllerConnected    += HandleOnControllerConnected;
            MLInput.OnControllerDisconnected += HandleOnControllerDisconnected;

            GetAllowedInput();
        }
        /// <summary>
        /// Starts the MLInput, initializes the first controller, and registers the connection handlers
        /// </summary>
        void Start()
        {
            if (_devicesAllowed == 0)
            {
                Debug.LogErrorFormat("Error: ControllerConnectionHandler._devicesAllowed is invalid, disabling script.");
                enabled = false;
                return;
            }
            bool requestCFUID = DevicesAllowed.HasFlag(DeviceTypesAllowed.ControllerLeft) ||
                                DevicesAllowed.HasFlag(DeviceTypesAllowed.ControllerRight);

            #if PLATFORM_LUMIN
            if (!MLInput.IsStarted)
            {
                MLInput.Configuration config = new MLInput.Configuration(requestCFUID,
                                                                         MLInput.Configuration.DefaultTriggerDownThreshold,
                                                                         MLInput.Configuration.DefaultTriggerUpThreshold);
                MLResult result = MLInput.Start(config);
                if (!result.IsOk)
                {
                    Debug.LogErrorFormat("Error: ControllerConnectionHandler failed starting MLInput, disabling script. Reason: {0}", result);
                    enabled = false;
                    return;
                }
            }

            MLInput.OnControllerConnected    += HandleOnControllerConnected;
            MLInput.OnControllerDisconnected += HandleOnControllerDisconnected;
            #endif

            GetAllowedInput();
        }
 /// <summary>
 /// Unregisters the connection handlers and stops the MLInput
 /// </summary>
 private void OnDestroy()
 {
     if (MLInput.IsStarted)
     {
         UnregisterConnectionHandlers();
         MLInput.Stop();
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Unregisters the connection handlers and stops the MLInput
        /// </summary>
        void OnDestroy()
        {
            if (MLInput.IsStarted)
            {
                MLInput.OnControllerDisconnected -= HandleOnControllerDisconnected;
                MLInput.OnControllerConnected    -= HandleOnControllerConnected;

                MLInput.Stop();
            }
        }
        /// <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
        }
Esempio n. 6
0
 /// <summary>
 /// Fills allowed connected devices list with all the connected controllers matching
 /// types set in _devicesAllowed.
 /// </summary>
 private void GetAllowedInput()
 {
     for (int i = 0; i < 2; ++i)
     {
         MLInputController controller = MLInput.GetController(i);
         if (IsDeviceAllowed(controller) && !_allowedConnectedDevices.Exists((device) => device.Id == controller.Id))
         {
             _allowedConnectedDevices.Add(controller);
         }
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Unregisters the connection handlers and stops the MLInput
        /// </summary>
        void OnDestroy()
        {
            #if PLATFORM_LUMIN
            if (MLInput.IsStarted)
            {
                MLInput.OnControllerDisconnected -= HandleOnControllerDisconnected;
                MLInput.OnControllerConnected    -= HandleOnControllerConnected;

                MLInput.Stop();
            }
            #endif
        }
 /// <summary>
 /// Gets the first input device that's connected and allowed
 /// </summary>
 /// <returns>The first connected allowed device if any, null otherwise</returns>
 private MLInputController GetAllowedInput()
 {
     for (int i = 0; i < 2; ++i)
     {
         MLInputController controller = MLInput.GetController(i);
         if (IsDeviceAllowed(controller))
         {
             return(controller);
         }
     }
     return(null);
 }
Esempio n. 9
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)
        {
            MLInputController 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);
            }
        }
Esempio n. 11
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)
        {
            MLInputController 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);
            }
        }
        /// <summary>
        /// Handles the event when a controller connects. If the current controller
        /// is not valid, this will check if the new controller is allowed and uses
        /// it if so. Otherwise, no change will happen.
        /// </summary>
        /// <param name="controllerId">The id of the controller.</param>
        private void HandleOnControllerConnected(byte controllerId)
        {
            if (!IsControllerValid())
            {
                MLInputController newController = MLInput.GetController(controllerId);
                if (IsDeviceAllowed(newController))
                {
                    ConnectedController = newController;
                }

                if (OnControllerConnected != null)
                {
                    OnControllerConnected(ConnectedController);
                }
            }
        }
        /// <summary/>
        protected override void OnDestroy()
        {
            base.OnDestroy();

            if (MLInput.IsStarted)
            {
                MLInput.Stop();
            }

            MLInput.OnControllerConnected    -= HandleOnControllerConnected;
            MLInput.OnControllerDisconnected -= HandleOnControllerDisconnected;

            if (MLEyes.IsStarted)
            {
                MLEyes.Stop();
            }
        }
        /// <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
        }
        /// <summary>
        /// Starts the MLInput, initializes the first controller, and registers the connection handlers
        /// </summary>
        private void Awake()
        {
            MLInputConfiguration config = new MLInputConfiguration(MLInputConfiguration.DEFAULT_TRIGGER_DOWN_THRESHOLD,
                                                                   MLInputConfiguration.DEFAULT_TRIGGER_UP_THRESHOLD,
                                                                   true);
            MLResult result = MLInput.Start(config);

            if (!result.IsOk)
            {
                Debug.LogError("Error ControllerConnectionHandler starting MLInput, disabling script.");
                enabled = false;
                return;
            }

            ConnectedController = GetAllowedInput();
            RegisterConnectionHandlers();
        }
Esempio n. 16
0
        /// <summary/>
        protected override void OnDestroy()
        {
            base.OnDestroy();

            #if PLATFORM_LUMIN
            if (MLInput.IsStarted)
            {
                MLInput.Stop();
            }

            MLInput.OnControllerConnected    -= HandleOnControllerConnected;
            MLInput.OnControllerDisconnected -= HandleOnControllerDisconnected;
            SceneManager.activeSceneChanged  -= ChangedActiveScene;

            if (MLEyes.IsStarted)
            {
                MLEyes.Stop();
            }
            #endif
        }
Esempio n. 17
0
        /// <summary>
        /// Starts the MLInput, initializes the first controller, and registers the connection handlers
        /// </summary>
        void Awake()
        {
            if (!MLInput.IsStarted)
            {
                MLInputConfiguration config = new MLInputConfiguration(MLInputConfiguration.DEFAULT_TRIGGER_DOWN_THRESHOLD,
                                                                       MLInputConfiguration.DEFAULT_TRIGGER_UP_THRESHOLD,
                                                                       true);
                MLResult result = MLInput.Start(config);
                if (!result.IsOk)
                {
                    Debug.LogErrorFormat("Error: ControllerConnectionHandler failed starting MLInput, disabling script. Reason: {0}", result);
                    enabled = false;
                    return;
                }
            }

            MLInput.OnControllerConnected    += HandleOnControllerConnected;
            MLInput.OnControllerDisconnected += HandleOnControllerDisconnected;

            GetAllowedInput();
        }
Esempio n. 18
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
        }
Esempio n. 19
0
 public static MLResult Start(MLInput.Configuration config)
 {
     MLInput.SetConfig(config);
     return(MLResult.Create(MLResult.Code.Ok));
 }