David Mohrhardt
6 年前
当前提交
f82ed202
共有 10 个文件被更改,包括 515 次插入 和 152 次删除
-
2Assets/Prefabs/AR Eye Pose Visualizer.prefab
-
4Assets/Prefabs/AR Fixation Point Visualizer.prefab
-
94Assets/Scripts/ARKitEyePoseVisualizer.cs
-
356Assets/Prefabs/Eye Pose Prefab.prefab
-
7Assets/Prefabs/Eye Pose Prefab.prefab.meta
-
102Assets/Scripts/ARKitFixationPointVisualizer.cs
-
102Assets/Scripts/ARKitEyeGazePositionVisualizer.cs
-
0/Assets/Prefabs/AR Fixation Point Visualizer.prefab.meta
-
0/Assets/Prefabs/AR Fixation Point Visualizer.prefab
-
0/Assets/Scripts/ARKitFixationPointVisualizer.cs.meta
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!1 &152495550747070176 |
|||
GameObject: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
serializedVersion: 6 |
|||
m_Component: |
|||
- component: {fileID: 152495550747070177} |
|||
m_Layer: 0 |
|||
m_Name: Scale |
|||
m_TagString: Untagged |
|||
m_Icon: {fileID: 0} |
|||
m_NavMeshLayer: 0 |
|||
m_StaticEditorFlags: 0 |
|||
m_IsActive: 1 |
|||
--- !u!4 &152495550747070177 |
|||
Transform: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 152495550747070176} |
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} |
|||
m_LocalPosition: {x: 0, y: 0, z: 0} |
|||
m_LocalScale: {x: 0.25, y: 0.25, z: 0.25} |
|||
m_Children: |
|||
- {fileID: 1958265320497096805} |
|||
- {fileID: 1958384019485452097} |
|||
- {fileID: 1959735309776464799} |
|||
m_Father: {fileID: 1959886114218717893} |
|||
m_RootOrder: 0 |
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
|||
--- !u!1 &1956030389682867815 |
|||
GameObject: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
serializedVersion: 6 |
|||
m_Component: |
|||
- component: {fileID: 1959735309776464799} |
|||
- component: {fileID: 1969396949154698435} |
|||
- component: {fileID: 1977798803723705533} |
|||
- component: {fileID: 2002662381773121613} |
|||
m_Layer: 0 |
|||
m_Name: XAxis |
|||
m_TagString: Untagged |
|||
m_Icon: {fileID: 0} |
|||
m_NavMeshLayer: 0 |
|||
m_StaticEditorFlags: 0 |
|||
m_IsActive: 1 |
|||
--- !u!4 &1959735309776464799 |
|||
Transform: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 1956030389682867815} |
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} |
|||
m_LocalPosition: {x: 0.1, y: 0, z: 0} |
|||
m_LocalScale: {x: 0.2, y: 0.02, z: 0.02} |
|||
m_Children: [] |
|||
m_Father: {fileID: 152495550747070177} |
|||
m_RootOrder: 2 |
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
|||
--- !u!33 &1969396949154698435 |
|||
MeshFilter: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 1956030389682867815} |
|||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} |
|||
--- !u!23 &1977798803723705533 |
|||
MeshRenderer: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 1956030389682867815} |
|||
m_Enabled: 1 |
|||
m_CastShadows: 1 |
|||
m_ReceiveShadows: 1 |
|||
m_DynamicOccludee: 1 |
|||
m_MotionVectors: 1 |
|||
m_LightProbeUsage: 1 |
|||
m_ReflectionProbeUsage: 1 |
|||
m_RenderingLayerMask: 4294967295 |
|||
m_RendererPriority: 0 |
|||
m_Materials: |
|||
- {fileID: 2100000, guid: 1d85e66239f5b41eb87246c413157610, type: 2} |
|||
m_StaticBatchInfo: |
|||
firstSubMesh: 0 |
|||
subMeshCount: 0 |
|||
m_StaticBatchRoot: {fileID: 0} |
|||
m_ProbeAnchor: {fileID: 0} |
|||
m_LightProbeVolumeOverride: {fileID: 0} |
|||
m_ScaleInLightmap: 1 |
|||
m_ReceiveGI: 1 |
|||
m_PreserveUVs: 0 |
|||
m_IgnoreNormalsForChartDetection: 0 |
|||
m_ImportantGI: 0 |
|||
m_StitchLightmapSeams: 0 |
|||
m_SelectedEditorRenderState: 3 |
|||
m_MinimumChartSize: 4 |
|||
m_AutoUVMaxDistance: 0.5 |
|||
m_AutoUVMaxAngle: 89 |
|||
m_LightmapParameters: {fileID: 0} |
|||
m_SortingLayerID: 0 |
|||
m_SortingLayer: 0 |
|||
m_SortingOrder: 0 |
|||
--- !u!65 &2002662381773121613 |
|||
BoxCollider: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 1956030389682867815} |
|||
m_Material: {fileID: 0} |
|||
m_IsTrigger: 0 |
|||
m_Enabled: 1 |
|||
serializedVersion: 2 |
|||
m_Size: {x: 1, y: 1, z: 1} |
|||
m_Center: {x: 0, y: 0, z: 0} |
|||
--- !u!1 &1956280942445795445 |
|||
GameObject: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
serializedVersion: 6 |
|||
m_Component: |
|||
- component: {fileID: 1958384019485452097} |
|||
- component: {fileID: 1969602120645992969} |
|||
- component: {fileID: 1979174208927811219} |
|||
- component: {fileID: 2000889402908661493} |
|||
m_Layer: 0 |
|||
m_Name: YAxis |
|||
m_TagString: Untagged |
|||
m_Icon: {fileID: 0} |
|||
m_NavMeshLayer: 0 |
|||
m_StaticEditorFlags: 0 |
|||
m_IsActive: 1 |
|||
--- !u!4 &1958384019485452097 |
|||
Transform: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 1956280942445795445} |
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} |
|||
m_LocalPosition: {x: 0, y: 0.1, z: 0} |
|||
m_LocalScale: {x: 0.02, y: 0.2, z: 0.02} |
|||
m_Children: [] |
|||
m_Father: {fileID: 152495550747070177} |
|||
m_RootOrder: 1 |
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
|||
--- !u!33 &1969602120645992969 |
|||
MeshFilter: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 1956280942445795445} |
|||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} |
|||
--- !u!23 &1979174208927811219 |
|||
MeshRenderer: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 1956280942445795445} |
|||
m_Enabled: 1 |
|||
m_CastShadows: 1 |
|||
m_ReceiveShadows: 1 |
|||
m_DynamicOccludee: 1 |
|||
m_MotionVectors: 1 |
|||
m_LightProbeUsage: 1 |
|||
m_ReflectionProbeUsage: 1 |
|||
m_RenderingLayerMask: 4294967295 |
|||
m_RendererPriority: 0 |
|||
m_Materials: |
|||
- {fileID: 2100000, guid: e62de97909a2840f786ce710f802cf2d, type: 2} |
|||
m_StaticBatchInfo: |
|||
firstSubMesh: 0 |
|||
subMeshCount: 0 |
|||
m_StaticBatchRoot: {fileID: 0} |
|||
m_ProbeAnchor: {fileID: 0} |
|||
m_LightProbeVolumeOverride: {fileID: 0} |
|||
m_ScaleInLightmap: 1 |
|||
m_ReceiveGI: 1 |
|||
m_PreserveUVs: 0 |
|||
m_IgnoreNormalsForChartDetection: 0 |
|||
m_ImportantGI: 0 |
|||
m_StitchLightmapSeams: 0 |
|||
m_SelectedEditorRenderState: 3 |
|||
m_MinimumChartSize: 4 |
|||
m_AutoUVMaxDistance: 0.5 |
|||
m_AutoUVMaxAngle: 89 |
|||
m_LightmapParameters: {fileID: 0} |
|||
m_SortingLayerID: 0 |
|||
m_SortingLayer: 0 |
|||
m_SortingOrder: 0 |
|||
--- !u!65 &2000889402908661493 |
|||
BoxCollider: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 1956280942445795445} |
|||
m_Material: {fileID: 0} |
|||
m_IsTrigger: 0 |
|||
m_Enabled: 1 |
|||
serializedVersion: 2 |
|||
m_Size: {x: 1, y: 1, z: 1} |
|||
m_Center: {x: 0, y: 0, z: 0} |
|||
--- !u!1 &1956452873657601559 |
|||
GameObject: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
serializedVersion: 6 |
|||
m_Component: |
|||
- component: {fileID: 1958265320497096805} |
|||
- component: {fileID: 1971173663241107599} |
|||
- component: {fileID: 1977545447907752563} |
|||
- component: {fileID: 2002791279201354339} |
|||
m_Layer: 0 |
|||
m_Name: ZAxis |
|||
m_TagString: Untagged |
|||
m_Icon: {fileID: 0} |
|||
m_NavMeshLayer: 0 |
|||
m_StaticEditorFlags: 0 |
|||
m_IsActive: 1 |
|||
--- !u!4 &1958265320497096805 |
|||
Transform: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 1956452873657601559} |
|||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} |
|||
m_LocalPosition: {x: 0, y: 0, z: 0.1} |
|||
m_LocalScale: {x: 0.02, y: 0.02, z: 0.2} |
|||
m_Children: [] |
|||
m_Father: {fileID: 152495550747070177} |
|||
m_RootOrder: 0 |
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
|||
--- !u!33 &1971173663241107599 |
|||
MeshFilter: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 1956452873657601559} |
|||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} |
|||
--- !u!23 &1977545447907752563 |
|||
MeshRenderer: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 1956452873657601559} |
|||
m_Enabled: 1 |
|||
m_CastShadows: 1 |
|||
m_ReceiveShadows: 1 |
|||
m_DynamicOccludee: 1 |
|||
m_MotionVectors: 1 |
|||
m_LightProbeUsage: 1 |
|||
m_ReflectionProbeUsage: 1 |
|||
m_RenderingLayerMask: 4294967295 |
|||
m_RendererPriority: 0 |
|||
m_Materials: |
|||
- {fileID: 2100000, guid: d80c1a202911a4a37a3da59992876dfc, type: 2} |
|||
m_StaticBatchInfo: |
|||
firstSubMesh: 0 |
|||
subMeshCount: 0 |
|||
m_StaticBatchRoot: {fileID: 0} |
|||
m_ProbeAnchor: {fileID: 0} |
|||
m_LightProbeVolumeOverride: {fileID: 0} |
|||
m_ScaleInLightmap: 1 |
|||
m_ReceiveGI: 1 |
|||
m_PreserveUVs: 0 |
|||
m_IgnoreNormalsForChartDetection: 0 |
|||
m_ImportantGI: 0 |
|||
m_StitchLightmapSeams: 0 |
|||
m_SelectedEditorRenderState: 3 |
|||
m_MinimumChartSize: 4 |
|||
m_AutoUVMaxDistance: 0.5 |
|||
m_AutoUVMaxAngle: 89 |
|||
m_LightmapParameters: {fileID: 0} |
|||
m_SortingLayerID: 0 |
|||
m_SortingLayer: 0 |
|||
m_SortingOrder: 0 |
|||
--- !u!65 &2002791279201354339 |
|||
BoxCollider: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 1956452873657601559} |
|||
m_Material: {fileID: 0} |
|||
m_IsTrigger: 0 |
|||
m_Enabled: 1 |
|||
serializedVersion: 2 |
|||
m_Size: {x: 1, y: 1, z: 1} |
|||
m_Center: {x: 0, y: 0, z: 0} |
|||
--- !u!1 &1956726250845337899 |
|||
GameObject: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
serializedVersion: 6 |
|||
m_Component: |
|||
- component: {fileID: 1959886114218717893} |
|||
- component: {fileID: 1924741400625479931} |
|||
m_Layer: 0 |
|||
m_Name: Eye Pose Prefab |
|||
m_TagString: Untagged |
|||
m_Icon: {fileID: 0} |
|||
m_NavMeshLayer: 0 |
|||
m_StaticEditorFlags: 0 |
|||
m_IsActive: 1 |
|||
--- !u!4 &1959886114218717893 |
|||
Transform: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 1956726250845337899} |
|||
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} |
|||
m_LocalPosition: {x: 0, y: 0, z: 0} |
|||
m_LocalScale: {x: 1, y: 1, z: 1} |
|||
m_Children: |
|||
- {fileID: 152495550747070177} |
|||
m_Father: {fileID: 0} |
|||
m_RootOrder: 0 |
|||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} |
|||
--- !u!114 &1924741400625479931 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 1956726250845337899} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: 5d87bd45cfc214ce48ce8b882225dd11, type: 3} |
|||
m_Name: |
|||
m_EditorClassIdentifier: |
|||
m_DestroyOnRemoval: 1 |
|
|||
fileFormatVersion: 2 |
|||
guid: 643bb4f9636444efebc65bc5ec614d1b |
|||
PrefabImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.XR.ARFoundation; |
|||
using UnityEngine.XR.ARSubsystems; |
|||
|
|||
/// <summary>
|
|||
/// Visualizes the eye gaze position in face space for an <see cref="ARFace"/>.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Face space is the space where the origin is the transform of an <see cref="ARFace"/>.
|
|||
/// </remarks>
|
|||
[RequireComponent(typeof(ARFace))] |
|||
public class ARKitFixationPointVisualizer : MonoBehaviour |
|||
{ |
|||
[SerializeField] |
|||
GameObject m_FixationPointPrefab; |
|||
|
|||
public GameObject fixationPointPrefab |
|||
{ |
|||
get => m_FixationPointPrefab; |
|||
set => m_FixationPointPrefab = value; |
|||
} |
|||
|
|||
GameObject m_FixationPointGameObject; |
|||
|
|||
ARFace m_Face; |
|||
#if UNITY_IOS && !UNITY_EDITOR
|
|||
XRFaceSubsystem m_FaceSubsystem; |
|||
#endif
|
|||
|
|||
void Awake() |
|||
{ |
|||
m_Face = GetComponent<ARFace>(); |
|||
CreateEyeGameObjects(); |
|||
} |
|||
|
|||
void CreateEyeGameObjects() |
|||
{ |
|||
m_FixationPointGameObject = Instantiate(m_FixationPointPrefab, m_Face.transform); |
|||
m_FixationPointGameObject.SetActive(false); |
|||
} |
|||
|
|||
void SetVisible(bool visible) |
|||
{ |
|||
m_FixationPointGameObject.SetActive(visible); |
|||
} |
|||
|
|||
void UpdateVisibility() |
|||
{ |
|||
var visible = |
|||
enabled && |
|||
(m_Face.trackingState == TrackingState.Tracking) && |
|||
#if UNITY_IOS && !UNITY_EDITOR
|
|||
m_FaceSubsystem.supportedEyeTracking && |
|||
#endif
|
|||
(ARSession.state > ARSessionState.Ready); |
|||
|
|||
SetVisible(visible); |
|||
} |
|||
|
|||
void OnEnable() |
|||
{ |
|||
#if UNITY_IOS && !UNITY_EDITOR
|
|||
var faceManager = FindObjectOfType<ARFaceManager>(); |
|||
if (faceManager != null) |
|||
{ |
|||
m_FaceSubsystem = (XRFaceSubsystem)faceManager.subsystem; |
|||
} |
|||
#endif
|
|||
UpdateVisibility(); |
|||
m_Face.updated += OnUpdated; |
|||
} |
|||
|
|||
void OnUpdated(ARFaceUpdatedEventArgs eventArgs) |
|||
{ |
|||
UpdateVisibility(); |
|||
UpdateFixationPoint(); |
|||
} |
|||
|
|||
void UpdateFixationPoint() |
|||
{ |
|||
#if UNITY_IOS && !UNITY_EDITOR
|
|||
var fixationPoint = new Vector3(); |
|||
|
|||
if (m_FaceSubsystem.supportedEyeTracking) |
|||
{ |
|||
if (m_FaceSubsystem.TryGetFixationPoint(m_Face.trackableId, ref fixationPoint)) |
|||
{ |
|||
// The vector that represents the gaze offset from the face is not normalized and therefore could be behind the camera.
|
|||
// So set the offset to be 1/10th of meter in the direction of the offset
|
|||
m_FixationPointGameObject.transform.localPosition = Vector3.Normalize(fixationPoint) / 10; |
|||
} |
|||
else |
|||
{ |
|||
Debug.Log("Failed to get the face's fixation point."); |
|||
} |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
} |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.XR.ARFoundation; |
|||
using UnityEngine.XR.ARSubsystems; |
|||
|
|||
/// <summary>
|
|||
/// Visualizes the eye gaze position in face space for an <see cref="ARFace"/>.
|
|||
/// </summary>
|
|||
/// <remarks>
|
|||
/// Face space is the space where the origin is the transform of an <see cref="ARFace">.
|
|||
/// </remarks>
|
|||
[RequireComponent(typeof(ARFace))] |
|||
public class ARKitEyeGazePositionVisualizer : MonoBehaviour |
|||
{ |
|||
[SerializeField] |
|||
GameObject m_GazePositionPrefab; |
|||
|
|||
public GameObject gazePositionPrefab |
|||
{ |
|||
get => m_GazePositionPrefab; |
|||
set => m_GazePositionPrefab = value; |
|||
} |
|||
|
|||
GameObject m_GazePositionGameObject; |
|||
|
|||
ARFace m_Face; |
|||
#if UNITY_IOS && !UNITY_EDITOR
|
|||
XRFaceSubsystem m_FaceSubsystem; |
|||
#endif
|
|||
|
|||
void Awake() |
|||
{ |
|||
m_Face = GetComponent<ARFace>(); |
|||
CreateEyeGameObjects(); |
|||
} |
|||
|
|||
void CreateEyeGameObjects() |
|||
{ |
|||
m_GazePositionGameObject = Instantiate(m_GazePositionPrefab, m_Face.transform); |
|||
m_GazePositionGameObject.SetActive(false); |
|||
} |
|||
|
|||
void SetVisible(bool visible) |
|||
{ |
|||
m_GazePositionGameObject.SetActive(visible); |
|||
} |
|||
|
|||
void UpdateVisibility() |
|||
{ |
|||
var visible = |
|||
enabled && |
|||
(m_Face.trackingState == TrackingState.Tracking) && |
|||
#if UNITY_IOS && !UNITY_EDITOR
|
|||
m_FaceSubsystem.supportedEyeGazeTracking && |
|||
#endif
|
|||
(ARSession.state > ARSessionState.Ready); |
|||
|
|||
SetVisible(visible); |
|||
} |
|||
|
|||
void OnEnable() |
|||
{ |
|||
#if UNITY_IOS && !UNITY_EDITOR
|
|||
var faceManager = FindObjectOfType<ARFaceManager>(); |
|||
if (faceManager != null) |
|||
{ |
|||
m_FaceSubsystem = (XRFaceSubsystem)faceManager.subsystem; |
|||
} |
|||
#endif
|
|||
UpdateVisibility(); |
|||
m_Face.updated += OnUpdated; |
|||
} |
|||
|
|||
void OnUpdated(ARFaceUpdatedEventArgs eventArgs) |
|||
{ |
|||
UpdateVisibility(); |
|||
UpdateEyeGazePosition(); |
|||
} |
|||
|
|||
void UpdateEyeGazePosition() |
|||
{ |
|||
#if UNITY_IOS && !UNITY_EDITOR
|
|||
var gazePosition = new Vector3(); |
|||
|
|||
if (m_FaceSubsystem.supportedEyeGazeTracking) |
|||
{ |
|||
if (m_FaceSubsystem.TryGetEyeGazePosition(m_Face.trackableId, ref gazePosition)) |
|||
{ |
|||
// The vector that represents the gaze offset from the face is not normalized and therefore could be behind the camera.
|
|||
// So set the offset to be 1/10th of meter in the direction of the offset
|
|||
m_GazePositionGameObject.transform.localPosition = Vector3.Normalize(gazePosition) / 10; |
|||
} |
|||
else |
|||
{ |
|||
Debug.Log("Failed to get the face's eye poses."); |
|||
} |
|||
} |
|||
#endif
|
|||
} |
|||
|
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue