zoukankan      html  css  js  c++  java
  • Unity3D调用摄像头显示当前拍摄画面

    1. using UnityEngine;  
    2. using System.Collections;  
    3.   
    4. public class CameraTest : MonoBehaviour  
    5. {  
    6.     public WebCamTexture cameraTexture;  
    7.     public string cameraName="";  
    8.     private bool isPlay = false;  
    9.     // Use this for initialization  
    10.     void Start()  
    11.     {  
    12.         StartCoroutine(Test());  
    13.     }  
    14.   
    15.     // Update is called once per frame  
    16.     void Update()  
    17.     {  
    18.   
    19.     }  
    20.   
    21.     IEnumerator Test()  
    22.     {  
    23.         yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);  
    24.         if (Application.HasUserAuthorization(UserAuthorization.WebCam))  
    25.         {  
    26.             WebCamDevice[] devices = WebCamTexture.devices;  
    27.             cameraName = devices[0].name;  
    28.             cameraTexture = new WebCamTexture(cameraName, 400, 300, 15);  
    29.             cameraTexture.Play();  
    30.             isPlay = true;  
    31.         }  
    32.     }  
    33.   
    34.     void OnGUI()  
    35.     {  
    36.         if (isPlay)  
    37.         {  
    38.             GUI.DrawTexture(new Rect(0, 0, 400, 300), cameraTexture, ScaleMode.ScaleToFit);  
    39.         }  
    40.     }  

  • 相关阅读:
    UIImageView
    正则表达式
    控制器生命周期和 UIView
    Storyboard
    1218.2——property关键字
    1218.1——OC中的常见关键字及一些基本方法
    1217.2——定义一个类+方法声明调用
    1217.1——OC准备
    1216.2——文件操作
    1216.1——双链表
  • 原文地址:https://www.cnblogs.com/yfceshi/p/6856723.html
Copyright © 2011-2022 走看看