1234567891011121314151617181920212223242526272829303132333435 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class TestRGB : MonoBehaviour
- {
- public int index;
- int w = 1280;
- int h = 720;
- WebCamTexture RGBCamTexture;
- // Start is called before the first frame update
- void Start()
- {
- WebCamDevice[] devices = WebCamTexture.devices;
- if (devices.Length == 0)
- {
- Debug.Log("No webcam devices found.");
- return;
- }
- // 使用第一个可用的摄像头设备(你可以根据需要选择其他设备)
- RGBCamTexture = new WebCamTexture(devices[index].name, w, h, 30);
- Debug.Log("开启摄像头" + devices[index].name);
- // 开始摄像头捕捉
- RGBCamTexture.Play();
- if (this.GetComponent<RawImage>() != null)
- {
- this.GetComponent<RawImage>().texture = RGBCamTexture;
- this.GetComponent<RawImage>().transform.localEulerAngles = new Vector3(0, 0, 0);
- }
- }
- }
|