Пример #1
0
        /// <summary>
        /// Shuts down the EyeTracking host.
        /// </summary>
        public void Shutdown()
        {
            _isShuttingDown = true;

            if (!IsInitialized)
            {
                return;
            }
            print("Tobii EyeTracking is shutting down.");

            if (_context != null)
            {
                // The context must be shut down before disposing.
                try
                {
                    _context.Shutdown(1000, false);
                }
                catch (InteractionApiException ex)
                {
                    Debug.LogError("Tobii Engine context shutdown failed: " + ex.Message);
                }

                _context.Dispose();
                _context = null;
            }

            if (_environment != null)
            {
                _environment.Dispose();
                _environment = null;
            }
        }
        /// <summary>
        /// Cleans up any resources being used.
        /// </summary>
        /// <param name="isDisposing">true if managed resources should be disposed; otherwise, false.</param>
        protected virtual void Dispose(bool isDisposing)
        {
            if (isDisposing)
            {
                if (_context != null && !_context.IsInvalid)
                {
                    // The context must be shut down before disposing.
                    try
                    {
                        _context.Shutdown();
                    }
                    catch (InteractionApiException ex)
                    {
                        Debug.WriteLine("EyeX context shutdown failed: " + ex.Message);
                    }

                    _context.Dispose();
                    _context = null;
                }

                if (_environment != null)
                {
                    _environment.Dispose();
                    _environment = null;
                }
            }
        }
        /// <summary>
        /// Initializes the EyeX host and enables the connection to the EyeX Engine.
        /// </summary>
        public virtual void Start()
        {
            if (_context != null)
            {
                throw new InvalidOperationException("The EyeX host cannot be re-started.");
            }

            // Initialize the EyeX Engine client library.
            _environment = Environment.Initialize(LogTarget.Trace);

            // Create a context, register event handlers, and enable the connection to the engine.
            _context = new Context(false);
            _context.RegisterQueryHandlerForCurrentProcess(HandleQuery);
            _context.RegisterEventHandler(HandleEvent);
            _context.ConnectionStateChanged += OnConnectionStateChanged;

            _screenBoundsStateAccessor.OnContextCreated(_context);
            _displaySizeStateAccessor.OnContextCreated(_context);
            _eyeTrackingDeviceStatusStateAccessor.OnContextCreated(_context);
            _userPresenceStateAccessor.OnContextCreated(_context);
            _userProfileNameStateAccessor.OnContextCreated(_context);

            _context.EnableConnection();

            // Execute deferred initialization logic.
            while (_deferredInitialization.Count > 0)
            {
                _deferredInitialization.Dequeue().Invoke();
            }
        }
Пример #4
0
    /// <summary>
    /// Initializes the EyeX engine.
    /// </summary>
    public void InitializeEyeX()
    {
        if (IsInitialized)
        {
            return;
        }

        try
        {
            Tobii.EyeX.Client.Interop.EyeX.EnableMonoCallbacks("mono");
            _environment = Environment.Initialize();
        }
        catch (InteractionApiException ex)
        {
            Debug.LogError("EyeX initialization failed: " + ex.Message);
        }
        catch (DllNotFoundException)
        {
#if UNITY_EDITOR
            Debug.LogError("EyeX initialization failed because the client access library 'Tobii.EyeX.Client.dll' could not be loaded. " +
                           "Please make sure that it is present in the Unity project directory. " +
                           "You can find it in the SDK package, in the lib/x86 directory. (Currently only Windows is supported.)");
#else
            Debug.LogError("EyeX initialization failed because the client access library 'Tobii.EyeX.Client.dll' could not be loaded. " +
                           "Please make sure that it is present in the root directory of the game/application.");
#endif
            return;
        }

        try
        {
            _context = new Context(false);
            _context.RegisterQueryHandlerForCurrentProcess(HandleQuery);
            _context.RegisterEventHandler(HandleEvent);
            _context.ConnectionStateChanged += OnConnectionStateChanged;
            _context.EnableConnection();

            print("EyeX is running.");
        }
        catch (InteractionApiException ex)
        {
            Debug.LogError("EyeX context initialization failed: " + ex.Message);
        }
    }
Пример #5
0
        /// <summary>
        /// Cleans up any resources being used.
        /// </summary>
        /// <param name="isDisposing">true if managed resources should be disposed; otherwise, false.</param>
        protected virtual void Dispose(bool isDisposing)
        {
            if (isDisposing)
            {
                if (_context != null && !_context.IsInvalid)
                {
                    // The context must be shut down before disposing.
                    try
                    {
                        _context.Shutdown();
                    }
                    catch (InteractionApiException ex)
                    {
                        Debug.WriteLine("EyeX context shutdown failed: " + ex.Message);
                    }

                    _context.Dispose();
                    _context = null;
                }

                if (_environment != null)
                {
                    _environment.Dispose();
                    _environment = null;
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Initializes the EyeX host and enables the connection to the EyeX Engine.
        /// </summary>
        public virtual void Start()
        {
            if (_context != null)
            {
                throw new InvalidOperationException("The EyeX host cannot be re-started.");
            }

            // Initialize the EyeX Engine client library.
            _environment = Environment.Initialize(LogTarget.Trace);

            // Create a context, register event handlers, and enable the connection to the engine.
            _context = new Context(false);
            _context.RegisterQueryHandlerForCurrentProcess(HandleQuery);
            _context.RegisterEventHandler(HandleEvent);
            _context.ConnectionStateChanged += OnConnectionStateChanged;

            _screenBoundsStateAccessor.OnContextCreated(_context);
            _displaySizeStateAccessor.OnContextCreated(_context);
            _eyeTrackingDeviceStatusStateAccessor.OnContextCreated(_context);
            _userPresenceStateAccessor.OnContextCreated(_context);
            _userProfileNameStateAccessor.OnContextCreated(_context);
            _userProfilesStateAccessor.OnContextCreated(_context);
            _gazeTracking.OnContextCreated(_context);

            _context.EnableConnection();

            // Execute deferred initialization logic.
            while (_deferredInitialization.Count > 0)
            {
                _deferredInitialization.Dequeue().Invoke();
            }
        }