unity 调用外部相机拍照
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class TakePhotoCamera : MonoBehaviour
{
public static TakePhotoCamera instance;
public byte[] imageTytes;
//摄像头图像类,继承自texture
public WebCamTexture tex;
/// <summary>
/// 图片保存路径
/// </summary>
public string picPath = "";
private void Awake()
{
instance = this;
}
// Start is called before the first frame update
void Start()
{
StartCoroutine(OpenCamera());
}
IEnumerator OpenCamera()
{
//等待用户允许访问
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
//如果用户允许访问,开始获取图像
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
{
//先获取设备
WebCamDevice[] device = WebCamTexture.devices;
string deviceName &#