浏览代码

Updated the fixation point sample to support 3d and 2d representations

/3.1
David Mohrhardt 5 年前
当前提交
101a5d1a
共有 19 个文件被更改,包括 631 次插入234 次删除
  1. 15
      Assets/Prefabs/AR Fixation Point Visualizer.prefab
  2. 4
      Assets/Prefabs/FixationReticle.prefab
  3. 166
      Assets/Scenes/FaceTracking/FixationPoint.unity
  4. 126
      Assets/Prefabs/FixationRayPrefab.prefab
  5. 7
      Assets/Prefabs/FixationRayPrefab.prefab.meta
  6. 93
      Assets/Scripts/FixationPoint2DVisualizer.cs
  7. 13
      Assets/Scripts/FixationPoint2DVisualizer.cs.meta
  8. 87
      Assets/Scripts/FixationPoint3DVisualizer.cs
  9. 13
      Assets/Scripts/FixationPoint3DVisualizer.cs.meta
  10. 20
      Assets/Textures/Reticle.png
  11. 91
      Assets/Textures/Reticle.png.meta
  12. 11
      Assets/Scripts/FixationPointVisualizer.cs.meta
  13. 123
      Assets/Scripts/FixationPointVisualizer.cs
  14. 53
      Assets/Shaders/DoubleSidedSurfaceShader.shader
  15. 9
      Assets/Shaders/DoubleSidedSurfaceShader.shader.meta
  16. 23
      Assets/MoveReticle.cs
  17. 11
      Assets/MoveReticle.cs.meta
  18. 0
      /Assets/Prefabs/FixationReticle.prefab.meta
  19. 0
      /Assets/Prefabs/FixationReticle.prefab

15
Assets/Prefabs/AR Fixation Point Visualizer.prefab


- component: {fileID: 8461084496272763974}
- component: {fileID: 4599500522131540127}
- component: {fileID: 2802146367459927232}
- component: {fileID: 5426074507876991005}
m_Layer: 0
m_Name: AR Fixation Point Visualizer
m_TagString: Untagged

m_Script: {fileID: 11500000, guid: 84e9e36f641444746b0c94dcd4bb4518, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FixationPointPrefab: {fileID: 1956726250845337899, guid: 643bb4f9636444efebc65bc5ec614d1b,
m_FixationPointPrefab: {fileID: 1529176408204727125, guid: 8339cb70cc6014347bd14cfea9e60601,
--- !u!114 &5426074507876991005
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 5590809483239930861}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c15242b4b6e064d8ead61c1e4c1b8be7, type: 3}
m_Name:
m_EditorClassIdentifier:
m_GUIFixationReticlePrefab: {fileID: 5180915313586242672, guid: a14db57d4a388438285ebba933990962,
type: 3}

4
Assets/Prefabs/FixationReticle.prefab


- component: {fileID: 5378373474544339981}
- component: {fileID: 7437429907952804438}
m_Layer: 5
m_Name: ReticleImage
m_Name: FixationReticle
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0

m_Calls: []
m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
m_Texture: {fileID: 2800000, guid: bc52c50fa106c4e559c93bde8158ca73, type: 3}
m_Texture: {fileID: 2800000, guid: 80ffce31fe5404f1c91aa768d2cb33e8, type: 3}
m_UVRect:
serializedVersion: 2
x: 0

166
Assets/Scenes/FaceTracking/FixationPoint.unity


m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1266726270
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1266726273}
- component: {fileID: 1266726272}
- component: {fileID: 1266726271}
m_Layer: 0
m_Name: EventSystem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1266726271
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1266726270}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
m_CancelButton: Cancel
m_InputActionsPerSecond: 10
m_RepeatDelay: 0.5
m_ForceModuleActive: 0
--- !u!114 &1266726272
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1266726270}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 76c392e42b5098c458856cdf6ecaaaa1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FirstSelected: {fileID: 0}
m_sendNavigationEvents: 1
m_DragThreshold: 10
--- !u!4 &1266726273
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1266726270}
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: []
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1526980365
GameObject:
m_ObjectHideFlags: 0

m_BounceIntensity: 1
m_ColorTemperature: 6570
m_UseColorTemperature: 0
m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0}
m_BoundingSphereOverride: {x: 1.5046328e-36, y: 1.009742e-28, z: 0, w: 0}
m_UseBoundingSphereOverride: 0
m_ShadowRadius: 0
m_ShadowAngle: 0

m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &1820267523
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1820267527}
- component: {fileID: 1820267526}
- component: {fileID: 1820267525}
- component: {fileID: 1820267524}
m_Layer: 5
m_Name: Canvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1820267524
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1820267523}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!114 &1820267525
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1820267523}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
--- !u!223 &1820267526
Canvas:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1820267523}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 0
m_Camera: {fileID: 0}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!224 &1820267527
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1820267523}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 3
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}

126
Assets/Prefabs/FixationRayPrefab.prefab


%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &795713508893815543
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4175560679010963632}
- component: {fileID: 6833705460578319375}
- component: {fileID: 4622826133050988356}
- component: {fileID: 7010878674475661216}
m_Layer: 0
m_Name: LookAtRay
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &4175560679010963632
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 795713508893815543}
m_LocalRotation: {x: 0.7071068, y: 0, z: 0, w: 0.7071068}
m_LocalPosition: {x: 0, y: 0, z: 100}
m_LocalScale: {x: 0.01, y: 100, z: 0.01}
m_Children: []
m_Father: {fileID: 3282145534469213579}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 90, y: 0, z: 0}
--- !u!33 &6833705460578319375
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 795713508893815543}
m_Mesh: {fileID: 10206, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &4622826133050988356
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 795713508893815543}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RenderingLayerMask: 1
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: 1
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!136 &7010878674475661216
CapsuleCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 795713508893815543}
m_Material: {fileID: 0}
m_IsTrigger: 0
m_Enabled: 1
m_Radius: 0.5000001
m_Height: 2
m_Direction: 1
m_Center: {x: 0.000000059604645, y: 0, z: -0.00000008940697}
--- !u!1 &1529176408204727125
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3282145534469213579}
m_Layer: 0
m_Name: FixationRayPrefab
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3282145534469213579
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1529176408204727125}
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: 4175560679010963632}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

7
Assets/Prefabs/FixationRayPrefab.prefab.meta


fileFormatVersion: 2
guid: 8339cb70cc6014347bd14cfea9e60601
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

93
Assets/Scripts/FixationPoint2DVisualizer.cs


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 FixationPoint2DVisualizer : MonoBehaviour
{
[SerializeField]
GameObject m_GUIFixationReticlePrefab;
public GameObject fixationReticlePrefab
{
get => m_GUIFixationReticlePrefab;
set => m_GUIFixationReticlePrefab = value;
}
GameObject m_FixationReticleGameObject;
Canvas m_Canvas;
ARFace m_Face;
XRFaceSubsystem m_FaceSubsystem;
void Awake()
{
m_Face = GetComponent<ARFace>();
}
void GetOrCreateEyeGameObjects()
{
var canvas = FindObjectOfType<Canvas>();
if (m_Face.fixationPointTransform != null && canvas != null && m_FixationReticleGameObject == null)
{
m_FixationReticleGameObject = Instantiate(m_GUIFixationReticlePrefab, canvas.transform);
}
}
void SetVisible(bool visible)
{
if (m_FixationReticleGameObject != null)
m_FixationReticleGameObject.SetActive(visible);
}
void UpdateVisibility()
{
var visible =
enabled &&
(m_Face.trackingState == TrackingState.Tracking) &&
m_FaceSubsystem.SubsystemDescriptor.supportsEyeTracking &&
(ARSession.state > ARSessionState.Ready);
SetVisible(visible);
}
void OnEnable()
{
var faceManager = FindObjectOfType<ARFaceManager>();
if (faceManager != null)
{
m_FaceSubsystem = (XRFaceSubsystem)faceManager.subsystem;
}
UpdateVisibility();
m_Face.updated += OnUpdated;
}
void OnUpdated(ARFaceUpdatedEventArgs eventArgs)
{
GetOrCreateEyeGameObjects();
UpdateVisibility();
UpdateScreenReticle();
}
void UpdateScreenReticle()
{
var mainCamera = Camera.main;
var fixationInViewSpace = mainCamera.WorldToViewportPoint(m_Face.fixationPointTransform.position);
// The camera is mirrored so x and y must be changed to match where the fixation point is in relation to the face.
var mirrorFixationInView = new Vector3(1 - fixationInViewSpace.x, 1 - fixationInViewSpace.y, fixationInViewSpace.z);
if (m_FixationReticleGameObject != null)
{
m_FixationReticleGameObject.GetComponent<RectTransform>().anchoredPosition3D = mainCamera.ViewportToScreenPoint(mirrorFixationInView);
}
}
}

13
Assets/Scripts/FixationPoint2DVisualizer.cs.meta


fileFormatVersion: 2
guid: c15242b4b6e064d8ead61c1e4c1b8be7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- m_GUIFixationReticlePrefab: {fileID: 5180915313586242672, guid: a14db57d4a388438285ebba933990962,
type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

87
Assets/Scripts/FixationPoint3DVisualizer.cs


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 FixationPoint3DVisualizer : MonoBehaviour
{
[SerializeField]
GameObject m_FixationPointPrefab;
public GameObject fixationPointPrefab
{
get => m_FixationPointPrefab;
set => m_FixationPointPrefab = value;
}
GameObject m_FixationPointGameObject;
ARFace m_Face;
XRFaceSubsystem m_FaceSubsystem;
void Awake()
{
m_Face = GetComponent<ARFace>();
}
void GetOrCreateEyeGameObjects()
{
if (m_FixationPointGameObject == null && m_Face.fixationPointTransform != null)
{
m_FixationPointGameObject = Instantiate(m_FixationPointPrefab, m_Face.transform);
m_FixationPointGameObject.SetActive(false);
}
}
void SetVisible(bool visible)
{
if (m_FixationPointGameObject != null)
m_FixationPointGameObject.SetActive(visible);
}
void UpdateVisibility()
{
var visible =
enabled &&
(m_Face.trackingState == TrackingState.Tracking) &&
m_FaceSubsystem.SubsystemDescriptor.supportsEyeTracking &&
(ARSession.state > ARSessionState.Ready);
SetVisible(visible);
}
void OnEnable()
{
var faceManager = FindObjectOfType<ARFaceManager>();
if (faceManager != null)
{
m_FaceSubsystem = (XRFaceSubsystem)faceManager.subsystem;
}
UpdateVisibility();
m_Face.updated += OnUpdated;
}
void OnUpdated(ARFaceUpdatedEventArgs eventArgs)
{
GetOrCreateEyeGameObjects();
UpdateVisibility();
UpdateFixationPoint();
}
void UpdateFixationPoint()
{
if (m_FixationPointGameObject != null)
{
m_FixationPointGameObject.transform.LookAt(m_Face.fixationPointTransform.position);
}
}
}

13
Assets/Scripts/FixationPoint3DVisualizer.cs.meta


fileFormatVersion: 2
guid: 84e9e36f641444746b0c94dcd4bb4518
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- m_FixationPointPrefab: {fileID: 1529176408204727125, guid: 8339cb70cc6014347bd14cfea9e60601,
type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

20
Assets/Textures/Reticle.png

之前 之后
宽度: 1024  |  高度: 1024  |  大小: 12 KiB

91
Assets/Textures/Reticle.png.meta


fileFormatVersion: 2
guid: 80ffce31fe5404f1c91aa768d2cb33e8
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 10
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: -1
wrapV: -1
wrapW: -1
nPOTScale: 1
lightmap: 0
compressionQuality: 50
spriteMode: 0
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 0
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

11
Assets/Scripts/FixationPointVisualizer.cs.meta


fileFormatVersion: 2
guid: 84e9e36f641444746b0c94dcd4bb4518
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

123
Assets/Scripts/FixationPointVisualizer.cs


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 FixationPointVisualizer : MonoBehaviour
{
[SerializeField]
GameObject m_FixationPointPrefab;
[SerializeField]
GameObject m_GUIFixationReticlePrefab;
public GameObject fixationPointPrefab
{
get => m_FixationPointPrefab;
set => m_FixationPointPrefab = value;
}
public GameObject fixationReticlePrefab
{
get => m_GUIFixationReticlePrefab;
set => m_GUIFixationReticlePrefab = value;
}
GameObject m_FixationPointGameObject;
GameObject m_FixationReticleGameObject;
Canvas m_Canvas;
ARFace m_Face;
XRFaceSubsystem m_FaceSubsystem;
void Awake()
{
m_Face = GetComponent<ARFace>();
}
void GetOrCreateEyeGameObjects()
{
if (m_FixationPointGameObject == null && m_Face.fixationPointTransform != null)
{
m_FixationPointGameObject = Instantiate(m_FixationPointPrefab, m_Face.fixationPointTransform);
m_FixationPointGameObject.SetActive(false);
if (FindObjectOfType<Canvas>() != null && m_FixationReticleGameObject == null)
{
var canvas = FindObjectOfType<Canvas>();
Debug.Log("Found a canvas");
m_FixationReticleGameObject = Instantiate(m_GUIFixationReticlePrefab, canvas.transform);
}
}
}
void SetVisible(bool visible)
{
if (m_FixationPointGameObject != null)
m_FixationPointGameObject.SetActive(visible);
if (m_FixationReticleGameObject != null)
m_FixationReticleGameObject.SetActive(visible);
}
void UpdateVisibility()
{
var visible =
enabled &&
(m_Face.trackingState == TrackingState.Tracking) &&
m_FaceSubsystem.SubsystemDescriptor.supportsEyeTracking &&
(ARSession.state > ARSessionState.Ready);
SetVisible(visible);
}
void OnEnable()
{
var faceManager = FindObjectOfType<ARFaceManager>();
if (faceManager != null)
{
m_FaceSubsystem = (XRFaceSubsystem)faceManager.subsystem;
}
UpdateVisibility();
m_Face.updated += OnUpdated;
}
void OnUpdated(ARFaceUpdatedEventArgs eventArgs)
{
GetOrCreateEyeGameObjects();
UpdateVisibility();
UpdateFixationPoint();
UpdateScreenReticle();
}
void UpdateFixationPoint()
{
if (m_FixationPointGameObject != null)
{
// This is needed to update the rotation to better match the where of the fixation point
// Debug.Log("");
}
}
void UpdateScreenReticle()
{
var mainCamera = Camera.main;
var fixationInViewSpace = mainCamera.WorldToViewportPoint(m_Face.fixationPointTransform.position);
var mirrorFixationInView = new Vector3(1 - fixationInViewSpace.x, 1 - fixationInViewSpace.y, fixationInViewSpace.z);
if (m_FixationReticleGameObject != null)
{
m_FixationReticleGameObject.GetComponent<RectTransform>().anchoredPosition3D = mainCamera.ViewportToScreenPoint(mirrorFixationInView);
}
}
}

53
Assets/Shaders/DoubleSidedSurfaceShader.shader


Shader "Custom/DoubleSidedSurfaceShader"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}

9
Assets/Shaders/DoubleSidedSurfaceShader.shader.meta


fileFormatVersion: 2
guid: 3a5099ac491614be58256fbf10e331d5
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

23
Assets/MoveReticle.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveReticle : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
var rectTransform = GetComponent<RectTransform>();
if (rectTransform != null)
{
Vector2 ancvecc = rectTransform.anchoredPosition;
rectTransform.anchoredPosition = new Vector2(ancvecc.x + 1, ancvecc.y + 1);
}
}
}

11
Assets/MoveReticle.cs.meta


fileFormatVersion: 2
guid: 8ac04636e1b7b4cb2ba1ed320dad266d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

/Assets/Prefabs/ReticleImage.prefab.meta → /Assets/Prefabs/FixationReticle.prefab.meta

/Assets/Prefabs/ReticleImage.prefab → /Assets/Prefabs/FixationReticle.prefab

正在加载...
取消
保存