胡佳骏 1 year ago
parent
commit
c54eaf05e8
1 changed files with 15 additions and 4 deletions
  1. 15 4
      Samples~/SDK/XRRGBCamera.cs

+ 15 - 4
Samples~/SDK/XRRGBCamera.cs

@@ -22,6 +22,10 @@ public class XRRGBCamera : SingletonMono<XRRGBCamera>
 
     public void playCamera()
     {
+        if (RGBCamTexture != null && RGBCamTexture.isPlaying)
+        {
+            RGBCamTexture.Stop();
+        }
         // 将WebCamTexture绑定到RawImage组件以显示摄像头捕捉到的图像
 
         WebCamDevice[] devices = WebCamTexture.devices;
@@ -38,10 +42,15 @@ public class XRRGBCamera : SingletonMono<XRRGBCamera>
         // 开始摄像头捕捉
         RGBCamTexture.Play();
         CaptureImage = RGBCamTexture;
-        if (this.GetComponent<RawImage>()!=null)
+        if (this.GetComponent<RawImage>() != null)
         {
             this.GetComponent<RawImage>().texture = CaptureImage;
-            this.GetComponent<RawImage>().transform.localEulerAngles = new Vector3(0,0,0);
+            this.GetComponent<RawImage>().transform.localEulerAngles = new Vector3(0, 0, 0);
+        }
+        if (this.GetComponent<MeshRenderer>() != null)
+        {
+            this.GetComponent<MeshRenderer>().material.mainTexture = CaptureImage;
+            this.GetComponent<MeshRenderer>().transform.localEulerAngles = new Vector3(0, 0, 0);
         }
         Debug.Log("开启摄像头");
     }
@@ -52,7 +61,9 @@ public class XRRGBCamera : SingletonMono<XRRGBCamera>
 
     public void stopCamera()
     {
-
-        RGBCamTexture.Stop();
+        if (RGBCamTexture != null && RGBCamTexture.isPlaying)
+        {
+            RGBCamTexture.Stop();
+        }
     }
 }