u3d 打开摄像头 截屏

代码

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
public class VideoTextureRecordManager : MonoBehaviour
{
    public RawImage cameraTexture;
    public WebCamTexture webCameraTexture;

    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(GetWebCamDevice());
    }

    IEnumerator GetWebCamDevice()
    {
        yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
        if (Application.HasUserAuthorization(UserAuthorization.WebCam))
        {
            WebCamDevice[] devices = WebCamTexture.devices;
            if(devices.Length != 0)
            {
                string devicename = devices[0].name;
                webCameraTexture = new WebCamTexture(devicename, Screen.width, Screen.height);
                cameraTexture.texture = webCameraTexture;
                webCameraTexture.Play();
            }
     

你可能感兴趣的:(u3d)