XRRGBCamera.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using NRKernal;
  2. using SC.XR.Unity;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class XRRGBCamera : SingletonMono<XRRGBCamera>
  8. {
  9. public Texture CaptureImage;
  10. NRRGBCamTexture RGBCamTexture;
  11. public bool isAuto = true;
  12. private void Start()
  13. {
  14. RGBCamTexture = new NRRGBCamTexture();
  15. if (isAuto)
  16. playCamera(1280, 720);
  17. }
  18. public void playCamera(int w, int h)
  19. {
  20. if (RGBCamTexture != null)
  21. {
  22. RGBCamTexture.Stop();
  23. }
  24. CaptureImage = RGBCamTexture.GetTexture();
  25. if (this.GetComponent<RawImage>() != null)
  26. {
  27. this.GetComponent<RawImage>().texture = CaptureImage;
  28. this.GetComponent<RawImage>().transform.localEulerAngles = new Vector3(-180, 0, 0);
  29. }
  30. if (this.GetComponent<MeshRenderer>() != null)
  31. {
  32. this.GetComponent<MeshRenderer>().material.mainTexture = CaptureImage;
  33. this.GetComponent<MeshRenderer>().transform.localEulerAngles = new Vector3(-180, 0, 0);
  34. }
  35. RGBCamTexture.Play();
  36. }
  37. public void stopCamera()
  38. {
  39. if (RGBCamTexture != null)
  40. {
  41. RGBCamTexture.Stop();
  42. }
  43. }
  44. }