12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using SC.XR.Unity;
- public class XRRGBCamera : SingletonMono<XRRGBCamera>
- {
- public static XRRGBCamera Instance;
- public Texture CaptureImage;
- public WebCamTexture RGBCamTexture;
- private void Awake()
- {
- Instance = this;
- }
- private void Start()
- {
-
- playCamera();
- }
- public void playCamera()
- {
-
- WebCamDevice[] devices = WebCamTexture.devices;
- if (devices.Length == 0)
- {
- Debug.Log("No webcam devices found.");
- return;
- }
-
- RGBCamTexture = new WebCamTexture(devices[0].name, 1280, 720, 30);
- Debug.Log("开启摄像头" + devices[0].name);
-
- RGBCamTexture.Play();
- CaptureImage = RGBCamTexture;
- if (this.GetComponent<RawImage>()!=null)
- {
- this.GetComponent<RawImage>().texture = CaptureImage;
- this.GetComponent<RawImage>().transform.localEulerAngles = new Vector3(0,0,0);
- }
- Debug.Log("开启摄像头");
- }
- public void Update()
- {
- }
- public void stopCamera()
- {
- RGBCamTexture.Stop();
- }
- }
|