Merge pull request #19 from unity/GazeCheck-Rework
Re-worked gaze check
This commit is contained in:
Коммит
3bfb87534f
|
@ -5,7 +5,6 @@ using NUnit.Framework;
|
|||
using System.Collections;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class CameraCheck : TestBaseSetup
|
||||
{
|
||||
|
@ -20,14 +19,8 @@ public class CameraCheck : TestBaseSetup
|
|||
|
||||
private Texture2D m_MobileTexture;
|
||||
|
||||
List<XRNodeState> m_XrNodeStates;
|
||||
XRNode m_XrNodes;
|
||||
XRNode m_Head;
|
||||
private Vector3 m_XrHeadNodePos;
|
||||
|
||||
void Start()
|
||||
{
|
||||
|
||||
m_StartingScale = XRSettings.eyeTextureResolutionScale;
|
||||
m_StartingZoomAmount = XRDevice.fovZoomFactor;
|
||||
m_StartingRenderScale = XRSettings.renderViewportScale;
|
||||
|
@ -52,60 +45,6 @@ public class CameraCheck : TestBaseSetup
|
|||
base.TearDown();
|
||||
}
|
||||
|
||||
[Ignore("Disabling brittle test")]
|
||||
[UnityTest]
|
||||
public IEnumerator GazeCheck()
|
||||
{
|
||||
yield return new WaitForSeconds(kDeviceSetupWait);
|
||||
|
||||
RaycastHit info = new RaycastHit();
|
||||
InputTracking.GetNodeStates(m_XrNodeStates);
|
||||
|
||||
foreach(XRNodeState node in m_XrNodeStates)
|
||||
{
|
||||
if(node.nodeType == XRNode.Head)
|
||||
{
|
||||
m_Head = node.nodeType;
|
||||
node.TryGetPosition(out m_XrHeadNodePos);
|
||||
}
|
||||
}
|
||||
|
||||
InputTracking.Recenter();
|
||||
|
||||
yield return null;
|
||||
|
||||
if (m_TestSetupHelpers.m_Cube != null)
|
||||
{
|
||||
m_TestSetupHelpers.m_Cube.transform.position = new Vector3(m_XrHeadNodePos.x, m_XrHeadNodePos.y, m_XrHeadNodePos.z + 2f);
|
||||
}
|
||||
else if (m_TestSetupHelpers.m_Cube == null)
|
||||
{
|
||||
m_TestSetupHelpers.TestCubeSetup(TestCubesConfig.TestCube);
|
||||
m_TestSetupHelpers.m_Cube.transform.position = new Vector3(m_XrHeadNodePos.x, m_XrHeadNodePos.y, m_XrHeadNodePos.z + 2f);
|
||||
}
|
||||
|
||||
|
||||
yield return new WaitForSeconds(2f);
|
||||
|
||||
if (Physics.Raycast(m_XrHeadNodePos, m_TestSetupHelpers.m_Camera.GetComponent<Camera>().transform.forward, out info, 10f))
|
||||
{
|
||||
yield return new WaitForSeconds(0.05f);
|
||||
if (info.collider.name == m_TestSetupHelpers.m_Cube.name)
|
||||
{
|
||||
m_RaycastHit = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_TestSetupHelpers.m_Cube != null)
|
||||
{
|
||||
GameObject.Destroy(m_TestSetupHelpers.m_Cube);
|
||||
}
|
||||
|
||||
if (Application.platform != RuntimePlatform.IPhonePlayer)
|
||||
{
|
||||
Assert.IsTrue(m_RaycastHit, "Gaze check failed to hit something!");
|
||||
}
|
||||
}
|
||||
#if UNITY_EDITOR
|
||||
[Ignore("Known bug")]
|
||||
[UnityTest]
|
||||
|
|
|
@ -0,0 +1,128 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions.Must;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.XR;
|
||||
|
||||
public class PhysicsCheck : TestBaseSetup
|
||||
{
|
||||
private bool m_RaycastFired = false;
|
||||
private float kDeviceSetupWait = 1f;
|
||||
|
||||
private Texture2D m_MobileTexture;
|
||||
|
||||
private List<XRNodeState> m_XrNodeList;
|
||||
|
||||
private Vector3 m_XrCenterNodePos;
|
||||
private bool m_RaycastDirection;
|
||||
|
||||
[SetUp]
|
||||
public override void SetUp()
|
||||
{
|
||||
base.SetUp();
|
||||
|
||||
m_XrNodeList = new List<XRNodeState>();
|
||||
|
||||
InputTracking.trackingAcquired += InputTracking_trackingAcquired;
|
||||
InputTracking.trackingLost += InputTracking_trackingLost;
|
||||
InputTracking.nodeAdded += InputTracking_nodeAdded;
|
||||
InputTracking.nodeRemoved += InputTracking_nodeRemoved;
|
||||
|
||||
m_RaycastFired = m_RaycastDirection = false;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public override void TearDown()
|
||||
{
|
||||
InputTracking.trackingAcquired -= InputTracking_trackingAcquired;
|
||||
InputTracking.trackingLost -= InputTracking_trackingLost;
|
||||
InputTracking.nodeAdded -= InputTracking_nodeAdded;
|
||||
InputTracking.nodeRemoved -= InputTracking_nodeRemoved;
|
||||
m_RaycastFired = m_RaycastDirection = false;
|
||||
base.TearDown();
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator GazeCheck()
|
||||
{
|
||||
yield return new WaitForSeconds(kDeviceSetupWait);
|
||||
|
||||
InputTracking.GetNodeStates(m_XrNodeList);
|
||||
yield return new WaitForSeconds(1f);
|
||||
|
||||
if (m_XrNodeList.Count != 0)
|
||||
{
|
||||
foreach (XRNodeState nodeState in m_XrNodeList)
|
||||
{
|
||||
if (nodeState.nodeType == XRNode.CenterEye)
|
||||
{
|
||||
nodeState.TryGetPosition(out m_XrCenterNodePos);
|
||||
}
|
||||
}
|
||||
|
||||
SkipFrame(100);
|
||||
|
||||
Ray ray = new Ray(m_XrCenterNodePos, m_TestSetupHelpers.m_Camera.GetComponent<Camera>().transform.forward);
|
||||
Physics.Raycast(ray, 10f);
|
||||
yield return null;
|
||||
|
||||
if (ray.origin == m_XrCenterNodePos)
|
||||
{
|
||||
m_RaycastFired = true;
|
||||
}
|
||||
|
||||
if (ray.direction != Vector3.zero)
|
||||
{
|
||||
m_RaycastDirection = true;
|
||||
}
|
||||
|
||||
if (m_TestSetupHelpers.m_Cube != null)
|
||||
{
|
||||
GameObject.Destroy(m_TestSetupHelpers.m_Cube);
|
||||
}
|
||||
|
||||
if (Application.platform != RuntimePlatform.IPhonePlayer)
|
||||
{
|
||||
Assert.IsTrue(m_RaycastFired, "Gaze ray failed to leave the cetner eye position");
|
||||
Assert.IsTrue(m_RaycastDirection, "Gaze direction failed to travel!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail("Nodes are not being Tracked");
|
||||
}
|
||||
}
|
||||
|
||||
private void InputTracking_nodeRemoved(XRNodeState obj)
|
||||
{
|
||||
Debug.Log("Node Removed");
|
||||
}
|
||||
|
||||
private void InputTracking_nodeAdded(XRNodeState obj)
|
||||
{
|
||||
Debug.Log("Node Added");
|
||||
}
|
||||
|
||||
private void InputTracking_trackingLost(XRNodeState obj)
|
||||
{
|
||||
Debug.Log("Tracking Lost");
|
||||
}
|
||||
|
||||
private void InputTracking_trackingAcquired(XRNodeState obj)
|
||||
{
|
||||
Debug.Log("Tracking Acquire");
|
||||
}
|
||||
|
||||
IEnumerator SkipFrame(int frames)
|
||||
{
|
||||
for (int f = 0; f < frames; f++)
|
||||
{
|
||||
yield return null;
|
||||
Debug.Log("Skip Frame");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bac0f6a497d4a774db47cfcce20cb30f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -2,6 +2,7 @@
|
|||
using UnityEditor;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
using UnityEngine.SpatialTracking;
|
||||
|
||||
public enum TestStageConfig
|
||||
{
|
||||
|
@ -23,12 +24,16 @@ public enum TestCubesConfig
|
|||
public class TestSetupHelpers : TestBaseSetup
|
||||
{
|
||||
private int m_CubeCount = 0;
|
||||
|
||||
|
||||
private void CameraLightSetup()
|
||||
{
|
||||
m_Camera = new GameObject("Camera");
|
||||
m_Camera.AddComponent<Camera>();
|
||||
m_Camera.AddComponent<TrackedPoseDriver>();
|
||||
|
||||
var trackedPoseDriver = m_Camera.GetComponent<TrackedPoseDriver>();
|
||||
trackedPoseDriver.SetPoseSource(TrackedPoseDriver.DeviceType.GenericXRDevice, TrackedPoseDriver.TrackedPose.Head);
|
||||
|
||||
m_Light = new GameObject("Light");
|
||||
Light light = m_Light.AddComponent<Light>();
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
{
|
||||
"name": "Unity.CrossPlatformXRAutomation",
|
||||
"references": [
|
||||
"GUID:7dba57cf4c7e949bc9a312f3160727ff"
|
||||
],
|
||||
"optionalUnityReferences": [
|
||||
"TestAssemblies"
|
||||
"UnityEngine.SpatialTracking",
|
||||
"UnityEngine.TestRunner",
|
||||
"UnityEditor.TestRunner",
|
||||
"Scripts"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [
|
||||
|
@ -18,8 +18,12 @@
|
|||
],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll"
|
||||
],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": []
|
||||
}
|
|
@ -7,7 +7,6 @@ using System.Collections.Generic;
|
|||
|
||||
internal class XrNodes : TestBaseSetup
|
||||
{
|
||||
private XRNodeState m_XrNodeState;
|
||||
private List<XRNodeState> m_NodeList;
|
||||
|
||||
private bool m_TrackingNodes;
|
||||
|
@ -21,7 +20,6 @@ internal class XrNodes : TestBaseSetup
|
|||
public override void SetUp()
|
||||
{
|
||||
base.SetUp();
|
||||
m_XrNodeState = new XRNodeState();
|
||||
m_NodeList = new List<XRNodeState>();
|
||||
|
||||
InputTracking.trackingAcquired += InputTracking_trackingAcquired;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
"com.unity.test-framework": "1.0.11",
|
||||
"com.unity.textmeshpro": "1.3.0",
|
||||
"com.unity.timeline": "1.0.0",
|
||||
"com.unity.xr.legacyinputhelpers": "2.0.2",
|
||||
"com.unity.modules.ai": "1.0.0",
|
||||
"com.unity.modules.androidjni": "1.0.0",
|
||||
"com.unity.modules.animation": "1.0.0",
|
||||
|
|
Загрузка…
Ссылка в новой задаче