Skip to content

Commit 595c4b5

Browse files
authored
Eyetracking QoL and updating test icons (#9704)
* Allow the user to define a box collider on the parent object of the object referencing the eyetracking target script and still have it recognized as a valid lookateyetarget * Update the eyetracking target to implement null checking on the OnLookStart and WhileLookingAtTarget callbacks * Update a broken api call int the updatetestscripticons method * Update the test icons for the new eyetrackingtargettest class * Reverting nested children change, updated test icons * test adjustment * made an explicit null check * fixing CI complaints Co-authored-by: peader <peader.com>
1 parent 951087c commit 595c4b5

File tree

6 files changed

+113
-8
lines changed

6 files changed

+113
-8
lines changed

Assets/MRTK/SDK/Features/Input/Handlers/EyeTrackingTarget.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,11 @@ private void UpdateHitTarget()
260260

261261
if (isHit)
262262
{
263-
LookedAtTarget = hitInfo.collider.gameObject;
264-
LookedAtEyeTarget = LookedAtTarget.GetComponent<EyeTrackingTarget>();
263+
LookedAtEyeTarget = hitInfo.collider.transform.GetComponent<EyeTrackingTarget>();
264+
if(LookedAtEyeTarget != null)
265+
{
266+
LookedAtTarget = LookedAtEyeTarget.gameObject;
267+
}
265268
LookedAtPoint = hitInfo.point;
266269
}
267270
else
@@ -282,12 +285,12 @@ protected void OnEyeFocusStart()
282285
{
283286
lookAtStartTime = DateTime.UtcNow;
284287
IsLookedAt = true;
285-
OnLookAtStart.Invoke();
288+
OnLookAtStart?.Invoke();
286289
}
287290

288291
protected void OnEyeFocusStay()
289292
{
290-
WhileLookingAtTarget.Invoke();
293+
WhileLookingAtTarget?.Invoke();
291294

292295
if ((!IsDwelledOn) && (DateTime.UtcNow - lookAtStartTime).TotalSeconds > dwellTimeInSec)
293296
{
@@ -305,7 +308,7 @@ protected void OnEyeFocusStop()
305308
{
306309
IsDwelledOn = false;
307310
IsLookedAt = false;
308-
OnLookAway.Invoke();
311+
OnLookAway?.Invoke();
309312
}
310313

311314
#endregion

Assets/MRTK/Tests/EditModeTests/Core/Definitions/Utilities/MixedRealityPoseTests.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/MRTK/Tests/PlayModeTests/DwellTests.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
#if !WINDOWS_UWP
5+
// When the .NET scripting backend is enabled and C# projects are built
6+
// The assembly that this file is part of is still built for the player,
7+
// even though the assembly itself is marked as a test assembly (this is not
8+
// expected because test assemblies should not be included in player builds).
9+
// Because the .NET backend is deprecated in 2018 and removed in 2019 and this
10+
// issue will likely persist for 2018, this issue is worked around by wrapping all
11+
// play mode tests in this check.
12+
13+
using Microsoft.MixedReality.Toolkit.Input;
14+
using NUnit.Framework;
15+
using System.Collections;
16+
using UnityEditor;
17+
using UnityEngine;
18+
using UnityEngine.TestTools;
19+
20+
namespace Microsoft.MixedReality.Toolkit.Tests.Input
21+
{
22+
// tests for eyetracking
23+
public class EyeTrackingTargetTest
24+
{
25+
// Assets/MRTK/Examples/Demos/EyeTracking/General/Profiles/EyeTrackingDemoConfigurationProfile.asset
26+
private const string eyeTrackingConfigurationProfileGuid = "6615cacb3eaaa044f99b917186093aeb";
27+
28+
private static readonly string eyeTrackingConfigurationProfilePath = AssetDatabase.GUIDToAssetPath(eyeTrackingConfigurationProfileGuid);
29+
30+
private GameObject target;
31+
32+
// This method is called once before we enter play mode and execute any of the tests
33+
// do any kind of setup here that can't be done in playmode
34+
[SetUp]
35+
public void Setup()
36+
{
37+
PlayModeTestUtilities.Setup();
38+
TestUtilities.PlayspaceToOriginLookingForward();
39+
}
40+
41+
// Destroy the scene - this method is called after each test listed below has completed
42+
[TearDown]
43+
public void TearDown()
44+
{
45+
PlayModeTestUtilities.TearDown();
46+
}
47+
48+
#region Tests
49+
50+
/// <summary>
51+
/// Skeleton for a new MRTK play mode test.
52+
/// </summary>
53+
[UnityTest]
54+
public IEnumerator TestEyeTrackingTarget()
55+
{
56+
// Eye tracking configuration profile should set eye based gaze
57+
var profile = AssetDatabase.LoadAssetAtPath(eyeTrackingConfigurationProfilePath, typeof(MixedRealityToolkitConfigurationProfile)) as MixedRealityToolkitConfigurationProfile;
58+
MixedRealityToolkit.Instance.ResetConfiguration(profile);
59+
60+
// Reset view to origin
61+
MixedRealityPlayspace.PerformTransformation(p =>
62+
{
63+
p.position = Vector3.zero;
64+
p.LookAt(Vector3.forward);
65+
});
66+
67+
string targetName = "eyetrackingTargetObject";
68+
69+
var eyetrackingTargetObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
70+
eyetrackingTargetObject.name = targetName;
71+
var eyeTrackingTargetComponent = eyetrackingTargetObject.AddComponent<EyeTrackingTarget>();
72+
eyetrackingTargetObject.transform.position = Vector3.forward;
73+
74+
// We need to simulate an eye in the direction of the parent object
75+
var inputSimulationService = PlayModeTestUtilities.GetInputSimulationService();
76+
// We don't need any other input just eye gaze
77+
inputSimulationService.UserInputEnabled = false;
78+
inputSimulationService.EyeGazeSimulationMode = EyeGazeSimulationMode.CameraForwardAxis;
79+
80+
yield return null;
81+
82+
var isEyeGazeActive = InputRayUtils.TryGetEyeGazeRay(out var eyegazeRay);
83+
Assert.True(isEyeGazeActive);
84+
yield return null;
85+
Assert.True(EyeTrackingTarget.LookedAtTarget != null);
86+
Assert.True(EyeTrackingTarget.LookedAtEyeTarget.name == targetName);
87+
}
88+
#endregion
89+
}
90+
}
91+
#endif

Assets/MRTK/Tests/PlayModeTests/InputSystem/EyeTrackingTargetTest.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/MRTK/Tests/PlayModeTests/InteractiveElementTests.cs.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)