/// <summary> /// Handles interaction events. /// </summary> /// <param name="event_">The <see cref="InteractionEvent"/> instance containing the event data.</param> /// <param name="frameTimestamp">The timestamp of the frame the event was received.</param> /// <param name="gameViewInfo">Information about game view position and pixel scaling.</param> public void HandleEvent(InteractionEvent event_, float frameTimestamp, GameViewInfo gameViewInfo) { var eventBehaviors = event_.Behaviors; HandleEvent(eventBehaviors, frameTimestamp, gameViewInfo); lock (_lock) { _lastDataPoints.Add(Last); } foreach (var eventBehavior in eventBehaviors) { eventBehavior.Dispose(); } }
/// <summary> /// Update is called every frame, if the MonoBehaviour is enabled. /// </summary> void Update() { _frameTimestamp = Time.time; if (_engineVersion == null && IsInitialized && _isConnected) { _engineVersion = GetEngineVersion(); } // update the gameView Position, in case the game window has been moved or resized. var gameViewBounds = _gameViewBoundsProvider.GetGameViewPhysicalBounds(); var gameViewPosition = new Vector2(gameViewBounds.x, gameViewBounds.y); var gameViewPixelsPerDesktopPixel = new Vector2(Screen.width / gameViewBounds.width, Screen.height / gameViewBounds.height); _gameViewInfo = new GameViewInfo(gameViewPosition, gameViewPixelsPerDesktopPixel); _gazeFocus.UpdateGazeFocus(); StartCoroutine(DoEndOfFrameCleanup()); }
protected abstract void HandleEvent(IEnumerable <Behavior> eventBehaviors, float frameTimestamp, GameViewInfo gameViewInfo);
protected override void HandleEvent(IEnumerable <Behavior> eventBehaviors, float frameTimestamp, GameViewInfo gameViewInfo) { // Note that this method is called on a worker thread, so we MAY NOT access any game objects from here. // The data is stored in the Last property and used from the main thread. foreach (var behavior in eventBehaviors) { EyePositionDataEventParams eventParams; if (behavior.TryGetEyePositionDataEventParams(out eventParams)) { var left = new SingleEyePosition(eventParams.HasLeftEyePosition != EyeXBoolean.False, (float)eventParams.LeftEyeX, (float)eventParams.LeftEyeY, (float)eventParams.LeftEyeZ); var leftNormalized = new SingleEyePosition(eventParams.HasLeftEyePosition != EyeXBoolean.False, (float)eventParams.LeftEyeXNormalized, (float)eventParams.LeftEyeYNormalized, (float)eventParams.LeftEyeZNormalized); var right = new SingleEyePosition(eventParams.HasRightEyePosition != EyeXBoolean.False, (float)eventParams.RightEyeX, (float)eventParams.RightEyeY, (float)eventParams.RightEyeZ); var rightNormalized = new SingleEyePosition(eventParams.HasRightEyePosition != EyeXBoolean.False, (float)eventParams.RightEyeXNormalized, (float)eventParams.RightEyeYNormalized, (float)eventParams.RightEyeZNormalized); Last = new EyePositions(left, leftNormalized, right, rightNormalized, eventParams.Timestamp, frameTimestamp); } } }
protected override void HandleEvent(IEnumerable <Behavior> eventBehaviors, float frameTimestamp, GameViewInfo gameViewInfo) { // Note that this method is called on a worker thread, so we MAY NOT access any game objects from here. // The data is stored in the Last property and used from the main thread. foreach (var behavior in eventBehaviors) { FixationDataEventParams eventParams; if (behavior.TryGetFixationDataEventParams(out eventParams)) { var gazePointInUnityScreenSpace = gameViewInfo.DisplaySpaceToUnityScreenSpace((float)eventParams.X, (float)eventParams.Y); var gazePoint = new GazePoint( gazePointInUnityScreenSpace, eventParams.Timestamp, frameTimestamp); Last = new FixationPoint(gazePoint, eventParams.EventType, eventParams.Timestamp, frameTimestamp); } } }