Class VarjoEyeTrackingHandler
Drives eye-tracking data acquisition, gaze visualisation, and high-frequency CSV logging for Varjo XR headsets.
public class VarjoEyeTrackingHandler : MonoBehaviour
Inheritance
Remarks
The simulator setup pairs a Varjo headset with a physical steering rig so that head gaze
direction can be correlated with driving events (e.g., does the participant look toward a
pedestrian before yielding?). Two GazeDataSource modes are provided because
the Varjo headset exposes two separate APIs: the standard OpenXR InputSubsystem
path works with any XR headset and returns fixation point data only, while the
Varjo-proprietary GazeAPI additionally exposes per-eye pupil and iris diameter
measurements needed for pupillometry-based cognitive-load analysis.
Gaze logging writes directly to a semicolon-delimited CSV file at up to 200 Hz rather than routing through the analysis pipeline (IDataSendService). This was chosen for performance (zero serialisation overhead per frame) at the cost of not sharing the retry and queuing guarantees of the main data-send infrastructure.
Gaze target placement uses a BufferedRaycast over the last 10 frames so transient head micro-jitter does not cause the on-screen fixation indicator to flicker between objects at boundaries. The semantic collision names accumulated across those 10 frames are written to the CSV log so post-hoc analysis can reconstruct what the participant was fixating in each timestep.
The entire implementation is conditionally compiled for UNITY_EDITOR and
UNITY_STANDALONE_WIN only; WebGL and other platforms cannot use the Varjo SDK or
native file I/O required here.
Fields
calibrationRequestKey
Key to press to request a gaze calibration during runtime.
[Tooltip("Key to press to request a gaze calibration during runtime.")]
public KeyCode calibrationRequestKey
Field Value
fixationPointTransform
Transform representing the fixation point in the scene, used to visualize where the user is looking.
[Header("Visualization Transforms")]
[Tooltip("Transform representing the fixation point in the scene.")]
public Transform fixationPointTransform
Field Value
frequency
Specifies the frequency at which gaze data is output by the Varjo API.
[Header("Gaze data output frequency")]
[Tooltip("Specifies the frequency at which gaze data is output.")]
public VarjoEyeTracking.GazeOutputFrequency frequency
Field Value
VarjoEyeTracking.GazeOutputFrequency
gazeCalibrationMode
Determines the mode to use when requesting gaze calibration from Varjo.
[Header("Gaze calibration settings")]
[Tooltip("Determines the mode to use when requesting gaze calibration from Varjo.")]
public VarjoEyeTracking.GazeCalibrationMode gazeCalibrationMode
Field Value
VarjoEyeTracking.GazeCalibrationMode
gazeDataSource
Selects which gaze data source to use for tracking (InputSubsystem or GazeAPI).
[Header("Gaze data")]
[Tooltip("Selects which gaze data source to use for tracking.")]
public VarjoEyeTrackingHandler.GazeDataSource gazeDataSource
Field Value
gazeOutputFilterType
Sets the filter type applied to the gaze data output from Varjo for smoother or more responsive gaze signals.
[Header("Gaze output filter settings")]
[Tooltip("Sets the filter type applied to the gaze data output from Varjo.")]
public VarjoEyeTracking.GazeOutputFilterType gazeOutputFilterType
Field Value
VarjoEyeTracking.GazeOutputFilterType
leftEyeTransform
Transform representing the left eye�s position and orientation in the scene.
[Tooltip("Transform representing the left eye.")]
public Transform leftEyeTransform
Field Value
printFramerate
Enables printing of the gaze data framerate to the console during logging for debugging performance.
[Tooltip("Enables printing of gaze data framerate while logging.")]
[SerializeField]
public bool printFramerate
Field Value
bool
rightEyeTransform
Transform representing the right eye�s position and orientation in the scene.
[Tooltip("Transform representing the right eye.")]
public Transform rightEyeTransform
Field Value
setOutputFilterTypeKey
Key to press to cycle or set the gaze output filter type during runtime.
[Tooltip("Key to press to set the gaze output filter type during runtime.")]
public KeyCode setOutputFilterTypeKey
Field Value
showFixationPoint
Determines whether the fixation point indicator should be visible in the scene.
[Header("Toggle fixation point indicator visibility")]
[Tooltip("Determines whether the fixation point indicator should be visible.")]
public bool showFixationPoint
Field Value
bool