Shan Jiang
4 年前
当前提交
034b1e4c
共有 10 个文件被更改,包括 148 次插入 和 260 次删除
-
236Assets/Scenes/LightEstimation/HDRLightEstimation.unity
-
37Assets/Scenes/LightEstimation/LightEstimation.unity
-
2Assets/Scenes/LightEstimation/Rotator.cs
-
2Assets/Scenes/LightEstimation/HDRLightEstimationSettings.lighting
-
71Assets/Scenes/LightEstimation/FaceDirectionManager.cs
-
8Assets/Scenes/ImageTracking/Prefabs.meta
-
52Assets/Scenes/LightEstimation/PlatformSelector.cs
-
0/Assets/Scenes/LightEstimation/HDRLightEstimationSettings.lighting.meta
-
0/Assets/Scenes/LightEstimation/FaceDirectionManager.cs.meta
-
0/Assets/Scenes/LightEstimation/HDRLightEstimationSettings.lighting
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.XR.ARFoundation; |
|||
|
|||
namespace UnityEngine.XR.ARFoundation.Samples |
|||
{ |
|||
/// <summary>
|
|||
/// On ARKit, HDR light estimation only works in face tracking mode.
|
|||
/// On ARCore, HDR light estimation only works when NOT in face tracking mode.
|
|||
/// This script enables face tracking on iOS and disables it otherwise.
|
|||
/// </summary>
|
|||
[RequireComponent(typeof(ARSessionOrigin))] |
|||
[RequireComponent(typeof(ARFaceManager))] |
|||
[RequireComponent(typeof(ARCameraManager))] |
|||
public class FaceDirectionManager : MonoBehaviour |
|||
{ |
|||
[SerializeField] |
|||
GameObject m_WorldSpaceObject; |
|||
|
|||
public GameObject worldSpaceObject |
|||
{ |
|||
get => m_WorldSpaceObject; |
|||
set => m_WorldSpaceObject = value; |
|||
} |
|||
|
|||
CameraFacingDirection updatedCameraFacingDirection; |
|||
CameraFacingDirection originalCameraFacingDirection; |
|||
void OnEnable() |
|||
{ |
|||
originalCameraFacingDirection = GetComponentInChildren<ARCameraManager>().currentFacingDirection; |
|||
updatedCameraFacingDirection = originalCameraFacingDirection; |
|||
} |
|||
|
|||
void Update() |
|||
{ |
|||
updatedCameraFacingDirection = GetComponentInChildren<ARCameraManager>().currentFacingDirection; |
|||
if (updatedCameraFacingDirection != CameraFacingDirection.None && updatedCameraFacingDirection != originalCameraFacingDirection) |
|||
{ |
|||
if (updatedCameraFacingDirection == CameraFacingDirection.User) |
|||
{ |
|||
originalCameraFacingDirection = updatedCameraFacingDirection; |
|||
GetComponent<ARFaceManager>().enabled = true; |
|||
worldSpaceObject.SetActive(false); |
|||
} |
|||
else if (updatedCameraFacingDirection == CameraFacingDirection.World) |
|||
{ |
|||
originalCameraFacingDirection = updatedCameraFacingDirection; |
|||
GetComponent<ARFaceManager>().enabled = false; |
|||
worldSpaceObject.SetActive(true); |
|||
Application.onBeforeRender += OnBeforeRender; |
|||
} |
|||
} |
|||
} |
|||
|
|||
void OnDisable() |
|||
{ |
|||
GetComponent<ARFaceManager>().enabled = false; |
|||
Application.onBeforeRender -= OnBeforeRender; |
|||
} |
|||
|
|||
void OnBeforeRender() |
|||
{ |
|||
var camera = GetComponent<ARSessionOrigin>().camera; |
|||
if (camera && worldSpaceObject) |
|||
{ |
|||
worldSpaceObject.transform.position = camera.transform.position + camera.transform.forward; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2e816cbe1be2c41e5ad778b51588c92b |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.XR.ARFoundation; |
|||
|
|||
namespace UnityEngine.XR.ARFoundation.Samples |
|||
{ |
|||
/// <summary>
|
|||
/// On ARKit, HDR light estimation only works in face tracking mode.
|
|||
/// On ARCore, HDR light estimation only works when NOT in face tracking mode.
|
|||
/// This script enables face tracking on iOS and disables it otherwise.
|
|||
/// </summary>
|
|||
[RequireComponent(typeof(ARSessionOrigin))] |
|||
[RequireComponent(typeof(ARFaceManager))] |
|||
public class PlatformSelector : MonoBehaviour |
|||
{ |
|||
[SerializeField] |
|||
GameObject m_WorldSpaceObject; |
|||
|
|||
public GameObject worldSpaceObject |
|||
{ |
|||
get => m_WorldSpaceObject; |
|||
set => m_WorldSpaceObject = value; |
|||
} |
|||
|
|||
void OnEnable() |
|||
{ |
|||
#if UNITY_IOS
|
|||
GetComponent<ARFaceManager>().enabled = true; |
|||
#else
|
|||
GetComponent<ARFaceManager>().enabled = false; |
|||
worldSpaceObject?.SetActive(true); |
|||
Application.onBeforeRender += OnBeforeRender; |
|||
#endif
|
|||
} |
|||
|
|||
void OnDisable() |
|||
{ |
|||
GetComponent<ARFaceManager>().enabled = false; |
|||
Application.onBeforeRender -= OnBeforeRender; |
|||
} |
|||
|
|||
void OnBeforeRender() |
|||
{ |
|||
var camera = GetComponent<ARSessionOrigin>().camera; |
|||
if (camera && worldSpaceObject) |
|||
{ |
|||
worldSpaceObject.transform.position = camera.transform.position + camera.transform.forward; |
|||
} |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue