12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.XR;
- using Valve.VR;
- namespace SicknessReduction.Visual
- {
- public class VirtualNose : MonoBehaviour
- {
- public GameObject prefabToSpawn;
- public Vector3 padding;
- public bool adjustToIpd = true;
- private Camera cam;
- private GameObject nose;
- private InputDevice leftEye;
- private InputDevice rightEye;
- private void OnEnable()
- {
- cam = Camera.main;
- if (cam == null)
- {
- Debug.LogWarning("No main camera found. Cannot place virtual nose!");
- return;
- }
- Debug.Log($"Main Camera IPD: {cam.stereoSeparation}");
- nose = Instantiate(prefabToSpawn, cam.transform);
- nose.transform.localPosition = Vector3.forward * cam.nearClipPlane + padding;
- }
- private void Start()
- {
- List<InputDevice> devices = new List<InputDevice>();
- InputDevices.GetDevicesWithCharacteristics(
- InputDeviceCharacteristics.Camera | InputDeviceCharacteristics.HeadMounted, devices);
- if (devices.Count == 0)
- {
- Debug.LogWarning("No devices");
- return;
- }
- devices[0].TryGetFeatureValue(CommonUsages.rightEyePosition, out var reye);
- devices[0].TryGetFeatureValue(CommonUsages.leftEyePosition, out var leye);
- Debug.Log($"Eyes: {leye}, {reye}");
- }
- private void OnDisable()
- {
- if (nose == null) return;
- Destroy(nose);
- }
- }
- }
|