微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Unity获取RGB camera数据并绘制在UGUI上

Unity获取RGB camera数据并绘制在UGUI上

创建一个Unity获取RGB camera数据并绘制在UGUI上的脚本

创建UGUI

新建一个名字为Callback_CAMERA.cs的一个脚本并挂载在场景中的任何一个游戏物体身上

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Callback_CAMERA : MonoBehavIoUr
{

private WebCamTexture web_camera;

public RawImage CAMERA_RAWIMAGE;

private void Start()
{
    StartCoroutine(GetCameraData());
}

private IEnumerator GetCameraData()
{

    yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);

    if (Application.HasUserAuthorization(UserAuthorization.WebCam))
    {

       WebCamDevice[] devices =  WebCamTexture.devices;

        string name = devices[0].name;

        web_camera = new WebCamTexture(name ,Screen.width,Screen.height,60);

        CAMERA_RAWIMAGE.texture = web_camera;

        web_camera.Play();


    }

}

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐