NRPreviewer.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.Record
  10. {
  11. using NRKernal;
  12. using UnityEngine;
  13. using UnityEngine.UI;
  14. /// <summary> Preview the camera's record or capture image. </summary>
  15. public class NRPreviewer : MonoBehaviour
  16. {
  17. /// <summary> The root. </summary>
  18. public GameObject Root;
  19. /// <summary> The preview screen. </summary>
  20. public RawImage PreviewScreen;
  21. /// <summary> The state icon. </summary>
  22. public Image StateIcon;
  23. /// <summary> True if is bind to controller, false if not. </summary>
  24. public bool isBindToController = true;
  25. /// <summary> Starts this object. </summary>
  26. private void Start()
  27. {
  28. Root.SetActive(false);
  29. }
  30. /// <summary> Sets a data. </summary>
  31. /// <param name="tex"> The tex.</param>
  32. /// <param name="isplaying"> True to isplaying.</param>
  33. public void SetData(Texture tex, bool isplaying)
  34. {
  35. PreviewScreen.texture = tex;
  36. StateIcon.color = isplaying ? Color.green : Color.red;
  37. }
  38. /// <summary> Updates this object. </summary>
  39. private void Update()
  40. {
  41. if (NRInput.GetButtonDown(ControllerButton.APP))
  42. {
  43. Root.SetActive(!Root.activeInHierarchy);
  44. NRInput.LaserVisualActive = !Root.activeInHierarchy;
  45. NRInput.ReticleVisualActive = !Root.activeInHierarchy;
  46. }
  47. if (isBindToController)
  48. {
  49. this.BindPreviewTOController();
  50. }
  51. }
  52. /// <summary> Bind preview to controller. </summary>
  53. private void BindPreviewTOController()
  54. {
  55. var inputAnchor = NRInput.AnchorsHelper.GetAnchor(ControllerAnchorEnum.RightModelAnchor);
  56. transform.position = inputAnchor.TransformPoint(Vector3.forward * 0.3f);
  57. transform.forward = inputAnchor.forward;
  58. }
  59. /// <summary> Switch perview. </summary>
  60. /// <param name="flag"> True to flag.</param>
  61. public void SwitchPerview(bool flag)
  62. {
  63. Root.SetActive(flag);
  64. }
  65. }
  66. }