测试一下摄像头功能:WebCamTexture
deviceName | Set this to specify the name of the device to use. |
didUpdateThisFrame | Did the video buffer update this frame? |
isPlaying | Returns if the camera is currently playing. |
requestedFPS | 设置摄像机需要的帧速率 |
requestedHeight | 设置摄像头需要的高度 |
requestedWidth | 设置摄像头需要的宽度 |
videoRotationAngle | 返回一个顺时针方向的角度,它可用于旋转多边形,以便相机内容显示在正确的方位 |
videoVerticallyMirrored | 纹理图像是否垂直翻转 |
代码也几乎是网上找到:
脚本添加到任意对象上。
WebCamTexture wct;
// Use this for initialization
void Start () {
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
{
WebCamDevice[] devices = WebCamTexture.devices;
deviceName = devices[0].name;
wct = new WebCamTexture(deviceName, 400, 300, 12);
wct.Play();
}
}
// Update is called once per frame
// 把摄像机获取到图像放到一个Plane面上
void Update () {
GameObject panel = GameObject.Find("Plane_reality");
if (!panel)
Debug.Log("not found panel");
Material mat = panel.GetComponent<Renderer>().material;
if (mat)
{
mat.mainTexture = wct;
}
}
在plane的设置上,需要把他的位姿调整一下,否则是颠倒的