NRRenderPlaneFocus.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal.Experimental
  10. {
  11. using NRKernal;
  12. using UnityEngine;
  13. public class NRRenderPlaneFocus : MonoBehaviour
  14. {
  15. private Transform m_HeadTransfrom;
  16. private Vector3 m_FocusPosition;
  17. RaycastHit hitResult;
  18. void Start()
  19. {
  20. m_HeadTransfrom = NRSessionManager.Instance.CenterCameraAnchor;
  21. }
  22. void Update()
  23. {
  24. if (Physics.Raycast(new Ray(m_HeadTransfrom.position, m_HeadTransfrom.forward), out hitResult, 100))
  25. {
  26. m_FocusPosition = m_HeadTransfrom.InverseTransformPoint(hitResult.point);
  27. #if USING_XR_SDK && !UNITY_EDITOR
  28. NRSessionManager.Instance.XRDisplaySubsystem?.SetFocusPlane(m_FocusPosition,hitResult.normal,Vector3.zero);
  29. #else
  30. NRSessionManager.Instance.NRRenderer?.SetFocusDistance(m_FocusPosition.magnitude);
  31. #endif
  32. }
  33. }
  34. }
  35. }