CameraTeleportTest.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Nxr.Internal;
  2. using UnityEngine;
  3. namespace NXR.Samples
  4. {
  5. /// <summary>
  6. /// 示例:演示如何更新相机位置
  7. /// </summary>
  8. [RequireComponent(typeof(Collider),typeof(MeshRenderer))]
  9. public class CameraTeleportTest : MonoBehaviour
  10. {
  11. Material material;
  12. public Color defaultColor;
  13. NxrHead nxrHead;
  14. // Start is called before the first frame update
  15. void Start()
  16. {
  17. material = GetComponent<Renderer>().material;
  18. defaultColor = material.color;
  19. SetGazedAt(false);
  20. nxrHead = NxrViewer.Instance.GetHead();
  21. nxrHead.SetTrackPosition(true);
  22. }
  23. private bool gazeAt = false;
  24. public void OnGazeEnter()
  25. {
  26. SetGazedAt(true);
  27. }
  28. public void OnGazeExit()
  29. {
  30. SetGazedAt(false);
  31. }
  32. public void OnGazeTrigger()
  33. {
  34. if(gameObject.name.Equals("CubeReset"))
  35. {
  36. nxrHead.BasePosition = Vector3.zero;
  37. return;
  38. }
  39. nxrHead.BasePosition = transform.position;
  40. }
  41. public void SetGazedAt(bool gazedAt)
  42. {
  43. gazeAt = gazedAt;
  44. material.color = gazedAt ? Color.green : defaultColor;
  45. }
  46. }
  47. }